@@ -89,7 +89,7 @@ impl<'s> LintLevelsBuilder<'s> {
8989 self . sets . lint_cap = sess. opts . lint_cap . unwrap_or ( Level :: Forbid ) ;
9090
9191 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 ) ;
9393 let orig_level = level;
9494
9595 // If the cap is less than this specified level, e.g., if we've got
@@ -111,7 +111,7 @@ impl<'s> LintLevelsBuilder<'s> {
111111 }
112112
113113 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 ) ;
115115 let lints = store
116116 . find_lints ( lint_name)
117117 . unwrap_or_else ( |_| bug ! ( "A valid lint failed to produce a lint ids" ) ) ;
@@ -322,33 +322,14 @@ impl<'s> LintLevelsBuilder<'s> {
322322 continue ;
323323 }
324324 } ;
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 )
347327 } else {
348328 None
349329 } ;
330+ let tool_name = tool_ident. map ( |ident| ident. name ) ;
350331 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 ) ;
352333 match & lint_result {
353334 CheckLintNameResult :: Ok ( ids) => {
354335 let src = LintLevelSource :: Node (
@@ -365,7 +346,8 @@ impl<'s> LintLevelsBuilder<'s> {
365346 CheckLintNameResult :: Tool ( result) => {
366347 match * result {
367348 Ok ( ids) => {
368- let complete_name = & format ! ( "{}::{}" , tool_name. unwrap( ) , name) ;
349+ let complete_name =
350+ & format ! ( "{}::{}" , tool_ident. unwrap( ) . name, name) ;
369351 let src = LintLevelSource :: Node (
370352 Symbol :: intern ( complete_name) ,
371353 sp,
@@ -420,6 +402,26 @@ impl<'s> LintLevelsBuilder<'s> {
420402 }
421403 }
422404
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+
423425 _ if !self . warn_about_weird_lints => { }
424426
425427 CheckLintNameResult :: Warning ( msg, renamed) => {
@@ -451,8 +453,8 @@ impl<'s> LintLevelsBuilder<'s> {
451453 let ( level, src) =
452454 self . sets . get_lint_level ( lint, self . cur , Some ( & specs) , self . sess ) ;
453455 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)
456458 } else {
457459 name. to_string ( )
458460 } ;
@@ -475,7 +477,9 @@ impl<'s> LintLevelsBuilder<'s> {
475477 if let CheckLintNameResult :: Warning ( _, Some ( new_name) ) = lint_result {
476478 // Ignore any errors or warnings that happen because the new name is inaccurate
477479 // 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+ {
479483 let src = LintLevelSource :: Node ( Symbol :: intern ( & new_name) , sp, reason) ;
480484 for & id in ids {
481485 self . check_gated_lint ( id, attr. span ) ;
@@ -578,7 +582,7 @@ impl<'s> LintLevelsBuilder<'s> {
578582 }
579583}
580584
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 {
582586 if [ sym:: clippy, sym:: rustc, sym:: rustdoc] . contains ( & m_item) {
583587 return true ;
584588 }
0 commit comments