@@ -89,7 +89,7 @@ impl<'s> LintLevelsBuilder<'s> {
89
89
self . sets . lint_cap = sess. opts . lint_cap . unwrap_or ( Level :: Forbid ) ;
90
90
91
91
for & ( ref lint_name, level) in & sess. opts . lint_opts {
92
- store. check_lint_name_cmdline ( sess, & lint_name, level) ;
92
+ store. check_lint_name_cmdline ( sess, & lint_name, level, self . crate_attrs ) ;
93
93
let orig_level = level;
94
94
95
95
// If the cap is less than this specified level, e.g., if we've got
@@ -111,7 +111,7 @@ impl<'s> LintLevelsBuilder<'s> {
111
111
}
112
112
113
113
for lint_name in & sess. opts . force_warns {
114
- store. check_lint_name_cmdline ( sess, lint_name, Level :: ForceWarn ) ;
114
+ store. check_lint_name_cmdline ( sess, lint_name, Level :: ForceWarn , self . crate_attrs ) ;
115
115
let lints = store
116
116
. find_lints ( lint_name)
117
117
. unwrap_or_else ( |_| bug ! ( "A valid lint failed to produce a lint ids" ) ) ;
@@ -322,33 +322,14 @@ impl<'s> LintLevelsBuilder<'s> {
322
322
continue ;
323
323
}
324
324
} ;
325
- let tool_name = if meta_item. path . segments . len ( ) > 1 {
326
- let tool_ident = meta_item. path . segments [ 0 ] . ident ;
327
- if !is_known_lint_tool ( tool_ident. name , sess, & self . crate_attrs ) {
328
- let mut err = struct_span_err ! (
329
- sess,
330
- tool_ident. span,
331
- E0710 ,
332
- "unknown tool name `{}` found in scoped lint: `{}`" ,
333
- tool_ident. name,
334
- pprust:: path_to_string( & meta_item. path) ,
335
- ) ;
336
- if sess. is_nightly_build ( ) {
337
- err. help ( & format ! (
338
- "add `#![register_tool({})]` to the crate root" ,
339
- tool_ident. name
340
- ) ) ;
341
- }
342
- err. emit ( ) ;
343
- continue ;
344
- }
345
-
346
- Some ( meta_item. path . segments . remove ( 0 ) . ident . name )
325
+ let tool_ident = if meta_item. path . segments . len ( ) > 1 {
326
+ Some ( meta_item. path . segments . remove ( 0 ) . ident )
347
327
} else {
348
328
None
349
329
} ;
330
+ let tool_name = tool_ident. map ( |ident| ident. name ) ;
350
331
let name = pprust:: path_to_string ( & meta_item. path ) ;
351
- let lint_result = store. check_lint_name ( & name, tool_name) ;
332
+ let lint_result = store. check_lint_name ( sess , & name, tool_name, self . crate_attrs ) ;
352
333
match & lint_result {
353
334
CheckLintNameResult :: Ok ( ids) => {
354
335
let src = LintLevelSource :: Node (
@@ -365,7 +346,8 @@ impl<'s> LintLevelsBuilder<'s> {
365
346
CheckLintNameResult :: Tool ( result) => {
366
347
match * result {
367
348
Ok ( ids) => {
368
- let complete_name = & format ! ( "{}::{}" , tool_name. unwrap( ) , name) ;
349
+ let complete_name =
350
+ & format ! ( "{}::{}" , tool_ident. unwrap( ) . name, name) ;
369
351
let src = LintLevelSource :: Node (
370
352
Symbol :: intern ( complete_name) ,
371
353
sp,
@@ -420,6 +402,26 @@ impl<'s> LintLevelsBuilder<'s> {
420
402
}
421
403
}
422
404
405
+ & CheckLintNameResult :: NoTool => {
406
+ let mut err = struct_span_err ! (
407
+ sess,
408
+ tool_ident. map_or( DUMMY_SP , |ident| ident. span) ,
409
+ E0710 ,
410
+ "unknown tool name `{}` found in scoped lint: `{}::{}`" ,
411
+ tool_name. unwrap( ) ,
412
+ tool_name. unwrap( ) ,
413
+ pprust:: path_to_string( & meta_item. path) ,
414
+ ) ;
415
+ if sess. is_nightly_build ( ) {
416
+ err. help ( & format ! (
417
+ "add `#![register_tool({})]` to the crate root" ,
418
+ tool_name. unwrap( )
419
+ ) ) ;
420
+ }
421
+ err. emit ( ) ;
422
+ continue ;
423
+ }
424
+
423
425
_ if !self . warn_about_weird_lints => { }
424
426
425
427
CheckLintNameResult :: Warning ( msg, renamed) => {
@@ -451,8 +453,8 @@ impl<'s> LintLevelsBuilder<'s> {
451
453
let ( level, src) =
452
454
self . sets . get_lint_level ( lint, self . cur , Some ( & specs) , self . sess ) ;
453
455
struct_lint_level ( self . sess , lint, level, src, Some ( sp. into ( ) ) , |lint| {
454
- let name = if let Some ( tool_name ) = tool_name {
455
- format ! ( "{}::{}" , tool_name , name)
456
+ let name = if let Some ( tool_ident ) = tool_ident {
457
+ format ! ( "{}::{}" , tool_ident . name , name)
456
458
} else {
457
459
name. to_string ( )
458
460
} ;
@@ -475,7 +477,9 @@ impl<'s> LintLevelsBuilder<'s> {
475
477
if let CheckLintNameResult :: Warning ( _, Some ( new_name) ) = lint_result {
476
478
// Ignore any errors or warnings that happen because the new name is inaccurate
477
479
// NOTE: `new_name` already includes the tool name, so we don't have to add it again.
478
- if let CheckLintNameResult :: Ok ( ids) = store. check_lint_name ( & new_name, None ) {
480
+ if let CheckLintNameResult :: Ok ( ids) =
481
+ store. check_lint_name ( sess, & new_name, None , self . crate_attrs )
482
+ {
479
483
let src = LintLevelSource :: Node ( Symbol :: intern ( & new_name) , sp, reason) ;
480
484
for & id in ids {
481
485
self . check_gated_lint ( id, attr. span ) ;
@@ -578,7 +582,7 @@ impl<'s> LintLevelsBuilder<'s> {
578
582
}
579
583
}
580
584
581
- fn is_known_lint_tool ( m_item : Symbol , sess : & Session , attrs : & [ ast:: Attribute ] ) -> bool {
585
+ pub fn is_known_lint_tool ( m_item : Symbol , sess : & Session , attrs : & [ ast:: Attribute ] ) -> bool {
582
586
if [ sym:: clippy, sym:: rustc, sym:: rustdoc] . contains ( & m_item) {
583
587
return true ;
584
588
}
0 commit comments