@@ -75,6 +75,15 @@ enum TargetLint {
75
75
76
76
/// Temporary renaming, used for easing migration pain; see #16545
77
77
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
78
87
}
79
88
80
89
impl LintStore {
@@ -166,30 +175,42 @@ impl LintStore {
166
175
self . by_name . insert ( old_name. to_string ( ) , Renamed ( new_name. to_string ( ) , target) ) ;
167
176
}
168
177
178
+ pub fn register_removed ( & mut self , name : & str , reason : & str ) {
179
+ self . by_name . insert ( name. into ( ) , Removed ( reason. into ( ) ) ) ;
180
+ }
181
+
169
182
#[ allow( unused_variables) ]
170
183
fn find_lint ( & self , lint_name : & str , sess : & Session , span : Option < Span > )
171
- -> Option < LintId >
184
+ -> Result < LintId , FindLintError >
172
185
{
173
186
match self . by_name . get ( lint_name) {
174
- Some ( & Id ( lint_id) ) => Some ( lint_id) ,
187
+ Some ( & Id ( lint_id) ) => Ok ( lint_id) ,
175
188
Some ( & Renamed ( ref new_name, lint_id) ) => {
176
189
let warning = format ! ( "lint {} has been renamed to {}" ,
177
190
lint_name, new_name) ;
178
191
match span {
179
192
Some ( span) => sess. span_warn ( span, & warning[ ..] ) ,
180
193
None => sess. warn ( & warning[ ..] ) ,
181
194
} ;
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 )
185
206
}
186
207
}
187
208
188
209
pub fn process_command_line ( & mut self , sess : & Session ) {
189
210
for & ( ref lint_name, level) in & sess. opts . lint_opts {
190
211
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 ( _ ) => {
193
214
match self . lint_groups . iter ( ) . map ( |( & x, pair) | ( x, pair. 0 . clone ( ) ) )
194
215
. collect :: < FnvHashMap < & ' static str ,
195
216
Vec < LintId > > > ( )
@@ -398,8 +419,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
398
419
}
399
420
Ok ( ( lint_name, level, span) ) => {
400
421
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 ) => {
403
424
match self . lints . lint_groups . get ( & lint_name[ ..] ) {
404
425
Some ( & ( ref v, _) ) => v. iter ( )
405
426
. map ( |lint_id : & LintId |
@@ -412,7 +433,8 @@ impl<'a, 'tcx> Context<'a, 'tcx> {
412
433
continue ;
413
434
}
414
435
}
415
- }
436
+ } ,
437
+ Err ( FindLintError :: Removed ) => { continue ; }
416
438
}
417
439
}
418
440
} ;
0 commit comments