@@ -75,6 +75,15 @@ enum TargetLint {
7575
7676 /// Temporary renaming, used for easing migration pain; see #16545
7777 Renamed ( String , LintId ) ,
78+
79+ /// Lint with this name existed previously, but has been removed/deprecated.
80+ /// The string argument is the reason for removal.
81+ Removed ( String ) ,
82+ }
83+
84+ enum FindLintError {
85+ NotFound ,
86+ Removed
7887}
7988
8089impl LintStore {
@@ -166,30 +175,42 @@ impl LintStore {
166175 self . by_name . insert ( old_name. to_string ( ) , Renamed ( new_name. to_string ( ) , target) ) ;
167176 }
168177
178+ pub fn register_removed ( & mut self , name : & str , reason : & str ) {
179+ self . by_name . insert ( name. into ( ) , Removed ( reason. into ( ) ) ) ;
180+ }
181+
169182 #[ allow( unused_variables) ]
170183 fn find_lint ( & self , lint_name : & str , sess : & Session , span : Option < Span > )
171- -> Option < LintId >
184+ -> Result < LintId , FindLintError >
172185 {
173186 match self . by_name . get ( lint_name) {
174- Some ( & Id ( lint_id) ) => Some ( lint_id) ,
187+ Some ( & Id ( lint_id) ) => Ok ( lint_id) ,
175188 Some ( & Renamed ( ref new_name, lint_id) ) => {
176189 let warning = format ! ( "lint {} has been renamed to {}" ,
177190 lint_name, new_name) ;
178191 match span {
179192 Some ( span) => sess. span_warn ( span, & warning[ ..] ) ,
180193 None => sess. warn ( & warning[ ..] ) ,
181194 } ;
182- Some ( lint_id)
183- }
184- None => None
195+ Ok ( lint_id)
196+ } ,
197+ Some ( & Removed ( ref reason) ) => {
198+ let warning = format ! ( "lint {} has been removed: {}" , lint_name, reason) ;
199+ match span {
200+ Some ( span) => sess. span_warn ( span, & warning[ ..] ) ,
201+ None => sess. warn ( & warning[ ..] )
202+ }
203+ Err ( FindLintError :: Removed )
204+ } ,
205+ None => Err ( FindLintError :: NotFound )
185206 }
186207 }
187208
188209 pub fn process_command_line ( & mut self , sess : & Session ) {
189210 for & ( ref lint_name, level) in & sess. opts . lint_opts {
190211 match self . find_lint ( & lint_name[ ..] , sess, None ) {
191- Some ( lint_id) => self . set_level ( lint_id, ( level, CommandLine ) ) ,
192- None => {
212+ Ok ( lint_id) => self . set_level ( lint_id, ( level, CommandLine ) ) ,
213+ Err ( _ ) => {
193214 match self . lint_groups . iter ( ) . map ( |( & x, pair) | ( x, pair. 0 . clone ( ) ) )
194215 . collect :: < FnvHashMap < & ' static str ,
195216 Vec < LintId > > > ( )
@@ -398,8 +419,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
398419 }
399420 Ok ( ( lint_name, level, span) ) => {
400421 match self . lints . find_lint ( & lint_name, & self . tcx . sess , Some ( span) ) {
401- Some ( lint_id) => vec ! [ ( lint_id, level, span) ] ,
402- None => {
422+ Ok ( lint_id) => vec ! [ ( lint_id, level, span) ] ,
423+ Err ( FindLintError :: NotFound ) => {
403424 match self . lints . lint_groups . get ( & lint_name[ ..] ) {
404425 Some ( & ( ref v, _) ) => v. iter ( )
405426 . map ( |lint_id : & LintId |
@@ -412,7 +433,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
412433 continue ;
413434 }
414435 }
415- }
436+ } ,
437+ Err ( FindLintError :: Removed ) => { continue ; }
416438 }
417439 }
418440 } ;
0 commit comments