@@ -42,7 +42,7 @@ use util::nodemap::FxHashMap;
42
42
use std:: default:: Default as StdDefault ;
43
43
use syntax:: ast;
44
44
use syntax:: edition;
45
- use syntax_pos:: { MultiSpan , Span } ;
45
+ use syntax_pos:: { MultiSpan , Span , symbol :: LocalInternedString } ;
46
46
use errors:: DiagnosticBuilder ;
47
47
use hir;
48
48
use hir:: def_id:: LOCAL_CRATE ;
@@ -133,6 +133,12 @@ pub enum CheckLintNameResult<'a> {
133
133
/// The lint is either renamed or removed. This is the warning
134
134
/// message, and an optional new name (`None` if removed).
135
135
Warning ( String , Option < String > ) ,
136
+ /// The lint is from a tool. If the Option is None, then either
137
+ /// the lint does not exist in the tool or the code was not
138
+ /// compiled with the tool and therefore the lint was never
139
+ /// added to the `LintStore`. Otherwise the `LintId` will be
140
+ /// returned as if it where a rustc lint.
141
+ Tool ( Option < & ' a [ LintId ] > ) ,
136
142
}
137
143
138
144
impl LintStore {
@@ -288,14 +294,15 @@ impl LintStore {
288
294
sess : & Session ,
289
295
lint_name : & str ,
290
296
level : Level ) {
291
- let db = match self . check_lint_name ( lint_name) {
297
+ let db = match self . check_lint_name ( lint_name, None ) {
292
298
CheckLintNameResult :: Ok ( _) => None ,
293
299
CheckLintNameResult :: Warning ( ref msg, _) => {
294
300
Some ( sess. struct_warn ( msg) )
295
301
} ,
296
302
CheckLintNameResult :: NoLint => {
297
303
Some ( struct_err ! ( sess, E0602 , "unknown lint: `{}`" , lint_name) )
298
304
}
305
+ CheckLintNameResult :: Tool ( _) => unreachable ! ( ) ,
299
306
} ;
300
307
301
308
if let Some ( mut db) = db {
@@ -319,26 +326,41 @@ impl LintStore {
319
326
/// it emits non-fatal warnings and there are *two* lint passes that
320
327
/// inspect attributes, this is only run from the late pass to avoid
321
328
/// printing duplicate warnings.
322
- pub fn check_lint_name ( & self , lint_name : & str ) -> CheckLintNameResult {
323
- match self . by_name . get ( lint_name) {
324
- Some ( & Renamed ( ref new_name, _) ) => {
325
- CheckLintNameResult :: Warning (
326
- format ! ( "lint `{}` has been renamed to `{}`" , lint_name, new_name) ,
327
- Some ( new_name. to_owned ( ) )
328
- )
329
- } ,
330
- Some ( & Removed ( ref reason) ) => {
331
- CheckLintNameResult :: Warning (
332
- format ! ( "lint `{}` has been removed: `{}`" , lint_name, reason) ,
333
- None
334
- )
335
- } ,
336
- None => {
337
- match self . lint_groups . get ( lint_name) {
338
- None => CheckLintNameResult :: NoLint ,
339
- Some ( ids) => CheckLintNameResult :: Ok ( & ids. 0 ) ,
340
- }
329
+ pub fn check_lint_name (
330
+ & self ,
331
+ lint_name : & str ,
332
+ tool_name : Option < LocalInternedString > ,
333
+ ) -> CheckLintNameResult {
334
+ let complete_name = if let Some ( tool_name) = tool_name {
335
+ format ! ( "{}::{}" , tool_name, lint_name)
336
+ } else {
337
+ lint_name. to_string ( )
338
+ } ;
339
+ if let Some ( _) = tool_name {
340
+ match self . by_name . get ( & complete_name) {
341
+ None => match self . lint_groups . get ( & * complete_name) {
342
+ None => return CheckLintNameResult :: Tool ( None ) ,
343
+ Some ( ids) => return CheckLintNameResult :: Tool ( Some ( & ids. 0 ) ) ,
344
+ } ,
345
+ Some ( & Id ( ref id) ) => return CheckLintNameResult :: Tool ( Some ( slice:: from_ref ( id) ) ) ,
346
+ // If the lint was registered as removed or renamed by the lint tool, we don't need
347
+ // to treat tool_lints and rustc lints different and can use the code below.
348
+ _ => { }
341
349
}
350
+ }
351
+ match self . by_name . get ( & complete_name) {
352
+ Some ( & Renamed ( ref new_name, _) ) => CheckLintNameResult :: Warning (
353
+ format ! ( "lint `{}` has been renamed to `{}`" , lint_name, new_name) ,
354
+ Some ( new_name. to_owned ( ) ) ,
355
+ ) ,
356
+ Some ( & Removed ( ref reason) ) => CheckLintNameResult :: Warning (
357
+ format ! ( "lint `{}` has been removed: `{}`" , lint_name, reason) ,
358
+ None ,
359
+ ) ,
360
+ None => match self . lint_groups . get ( & * complete_name) {
361
+ None => CheckLintNameResult :: NoLint ,
362
+ Some ( ids) => CheckLintNameResult :: Ok ( & ids. 0 ) ,
363
+ } ,
342
364
Some ( & Id ( ref id) ) => CheckLintNameResult :: Ok ( slice:: from_ref ( id) ) ,
343
365
}
344
366
}
0 commit comments