1212 html_favicon_url = "https://doc.rust-lang.org/favicon.ico" ,
1313 html_root_url = "https://doc.rust-lang.org/nightly/" ) ]
1414
15+ #![ feature( crate_visibility_modifier) ]
1516#![ feature( rustc_diagnostic_macros) ]
1617#![ feature( slice_sort_by_cached_key) ]
1718
@@ -1634,11 +1635,17 @@ impl<'a> Resolver<'a> {
16341635 . map ( |seg| Ident :: new ( seg. name , span) )
16351636 . collect ( ) ;
16361637 // FIXME (Manishearth): Intra doc links won't get warned of epoch changes
1637- match self . resolve_path ( & path, Some ( namespace) , true , span, None ) {
1638+ match self . resolve_path ( & path, Some ( namespace) , true , span, CrateLint :: No ) {
16381639 PathResult :: Module ( module) => * def = module. def ( ) . unwrap ( ) ,
16391640 PathResult :: NonModule ( path_res) if path_res. unresolved_segments ( ) == 0 =>
16401641 * def = path_res. base_def ( ) ,
1641- PathResult :: NonModule ( ..) => match self . resolve_path ( & path, None , true , span, None ) {
1642+ PathResult :: NonModule ( ..) => match self . resolve_path (
1643+ & path,
1644+ None ,
1645+ true ,
1646+ span,
1647+ CrateLint :: No ,
1648+ ) {
16421649 PathResult :: Failed ( span, msg, _) => {
16431650 error_callback ( self , span, ResolutionError :: FailedToResolve ( & msg) ) ;
16441651 }
@@ -2352,8 +2359,13 @@ impl<'a> Resolver<'a> {
23522359 if def != Def :: Err {
23532360 new_id = Some ( def. def_id ( ) ) ;
23542361 let span = trait_ref. path . span ;
2355- if let PathResult :: Module ( module) = self . resolve_path ( & path, None , false , span,
2356- Some ( trait_ref. ref_id ) ) {
2362+ if let PathResult :: Module ( module) = self . resolve_path (
2363+ & path,
2364+ None ,
2365+ false ,
2366+ span,
2367+ CrateLint :: SimplePath ( trait_ref. ref_id ) ,
2368+ ) {
23572369 new_val = Some ( ( module, trait_ref. clone ( ) ) ) ;
23582370 }
23592371 }
@@ -2813,7 +2825,7 @@ impl<'a> Resolver<'a> {
28132825 } else {
28142826 let mod_path = & path[ ..path. len ( ) - 1 ] ;
28152827 let mod_prefix = match this. resolve_path ( mod_path, Some ( TypeNS ) ,
2816- false , span, None ) {
2828+ false , span, CrateLint :: No ) {
28172829 PathResult :: Module ( module) => module. def ( ) ,
28182830 _ => None ,
28192831 } . map_or ( format ! ( "" ) , |def| format ! ( "{} " , def. kind_name( ) ) ) ;
@@ -3143,7 +3155,13 @@ impl<'a> Resolver<'a> {
31433155 ) ) ;
31443156 }
31453157
3146- let result = match self . resolve_path ( & path, Some ( ns) , true , span, Some ( id) ) {
3158+ let result = match self . resolve_path (
3159+ & path,
3160+ Some ( ns) ,
3161+ true ,
3162+ span,
3163+ CrateLint :: SimplePath ( id) ,
3164+ ) {
31473165 PathResult :: NonModule ( path_res) => path_res,
31483166 PathResult :: Module ( module) if !module. is_normal ( ) => {
31493167 PathResolution :: new ( module. def ( ) . unwrap ( ) )
@@ -3180,7 +3198,13 @@ impl<'a> Resolver<'a> {
31803198 path[ 0 ] . name != keywords:: CrateRoot . name ( ) &&
31813199 path[ 0 ] . name != keywords:: DollarCrate . name ( ) {
31823200 let unqualified_result = {
3183- match self . resolve_path ( & [ * path. last ( ) . unwrap ( ) ] , Some ( ns) , false , span, None ) {
3201+ match self . resolve_path (
3202+ & [ * path. last ( ) . unwrap ( ) ] ,
3203+ Some ( ns) ,
3204+ false ,
3205+ span,
3206+ CrateLint :: No ,
3207+ ) {
31843208 PathResult :: NonModule ( path_res) => path_res. base_def ( ) ,
31853209 PathResult :: Module ( module) => module. def ( ) . unwrap ( ) ,
31863210 _ => return Some ( result) ,
@@ -3195,14 +3219,14 @@ impl<'a> Resolver<'a> {
31953219 Some ( result)
31963220 }
31973221
3198- fn resolve_path ( & mut self ,
3199- path : & [ Ident ] ,
3200- opt_ns : Option < Namespace > , // `None` indicates a module path
3201- record_used : bool ,
3202- path_span : Span ,
3203- node_id : Option < NodeId > ) // None indicates that we don't care about linting
3204- // `::module` paths
3205- -> PathResult < ' a > {
3222+ fn resolve_path (
3223+ & mut self ,
3224+ path : & [ Ident ] ,
3225+ opt_ns : Option < Namespace > , // `None` indicates a module path
3226+ record_used : bool ,
3227+ path_span : Span ,
3228+ crate_lint : CrateLint ,
3229+ ) -> PathResult < ' a > {
32063230 let mut module = None ;
32073231 let mut allow_super = true ;
32083232 let mut second_binding = None ;
@@ -3321,7 +3345,7 @@ impl<'a> Resolver<'a> {
33213345 return PathResult :: NonModule ( err_path_resolution ( ) ) ;
33223346 } else if opt_ns. is_some ( ) && ( is_last || maybe_assoc) {
33233347 self . lint_if_path_starts_with_module (
3324- node_id ,
3348+ crate_lint ,
33253349 path,
33263350 path_span,
33273351 second_binding,
@@ -3366,19 +3390,22 @@ impl<'a> Resolver<'a> {
33663390 }
33673391 }
33683392
3369- self . lint_if_path_starts_with_module ( node_id , path, path_span, second_binding) ;
3393+ self . lint_if_path_starts_with_module ( crate_lint , path, path_span, second_binding) ;
33703394
33713395 PathResult :: Module ( module. unwrap_or ( self . graph_root ) )
33723396 }
33733397
3374- fn lint_if_path_starts_with_module ( & self ,
3375- id : Option < NodeId > ,
3376- path : & [ Ident ] ,
3377- path_span : Span ,
3378- second_binding : Option < & NameBinding > ) {
3379- let id = match id {
3380- Some ( id) => id,
3381- None => return ,
3398+ fn lint_if_path_starts_with_module (
3399+ & self ,
3400+ crate_lint : CrateLint ,
3401+ path : & [ Ident ] ,
3402+ path_span : Span ,
3403+ second_binding : Option < & NameBinding > ,
3404+ ) {
3405+ let ( diag_id, diag_span) = match crate_lint {
3406+ CrateLint :: No => return ,
3407+ CrateLint :: SimplePath ( id) => ( id, path_span) ,
3408+ CrateLint :: UsePath { root_id, root_span } => ( root_id, root_span) ,
33823409 } ;
33833410
33843411 let first_name = match path. get ( 0 ) {
@@ -3414,7 +3441,7 @@ impl<'a> Resolver<'a> {
34143441 }
34153442 }
34163443
3417- self . lint_path_starts_with_module ( id , path_span ) ;
3444+ self . lint_path_starts_with_module ( diag_id , diag_span ) ;
34183445 }
34193446
34203447 fn lint_path_starts_with_module ( & self , id : NodeId , span : Span ) {
@@ -3650,7 +3677,7 @@ impl<'a> Resolver<'a> {
36503677 // Search in module.
36513678 let mod_path = & path[ ..path. len ( ) - 1 ] ;
36523679 if let PathResult :: Module ( module) = self . resolve_path ( mod_path, Some ( TypeNS ) ,
3653- false , span, None ) {
3680+ false , span, CrateLint :: No ) {
36543681 add_module_candidates ( module, & mut names) ;
36553682 }
36563683 }
@@ -4427,4 +4454,19 @@ pub enum MakeGlobMap {
44274454 No ,
44284455}
44294456
4457+ enum CrateLint {
4458+ /// Do not issue the lint
4459+ No ,
4460+
4461+ /// This lint applies to some random path like `impl ::foo::Bar`
4462+ /// or whatever. In this case, we can take the span of that path.
4463+ SimplePath ( NodeId ) ,
4464+
4465+ /// This lint comes from a `use` statement. In this case, what we
4466+ /// care about really is the *root* `use` statement; e.g., if we
4467+ /// have nested things like `use a::{b, c}`, we care about the
4468+ /// `use a` part.
4469+ UsePath { root_id : NodeId , root_span : Span } ,
4470+ }
4471+
44304472__build_diagnostic_array ! { librustc_resolve, DIAGNOSTICS }
0 commit comments