@@ -2247,7 +2247,13 @@ impl<'a> Resolver<'a> {
22472247
22482248 if items. len ( ) == 0 {
22492249 // Resolve prefix of an import with empty braces (issue #28388).
2250- self . smart_resolve_path ( id, None , & path, PathSource :: ImportPrefix ) ;
2250+ self . smart_resolve_path_with_crate_lint (
2251+ id,
2252+ None ,
2253+ & path,
2254+ PathSource :: ImportPrefix ,
2255+ CrateLint :: SimplePath ( id) , // TODO seems wrong
2256+ ) ;
22512257 } else {
22522258 for & ( ref tree, nested_id) in items {
22532259 self . resolve_use_tree ( nested_id, tree, & path) ;
@@ -2354,7 +2360,8 @@ impl<'a> Resolver<'a> {
23542360 None ,
23552361 & path,
23562362 trait_ref. path . span ,
2357- PathSource :: Trait ( AliasPossibility :: No )
2363+ PathSource :: Trait ( AliasPossibility :: No ) ,
2364+ CrateLint :: SimplePath ( trait_ref. ref_id ) ,
23582365 ) . base_def ( ) ;
23592366 if def != Def :: Err {
23602367 new_id = Some ( def. def_id ( ) ) ;
@@ -2787,18 +2794,38 @@ impl<'a> Resolver<'a> {
27872794 path : & Path ,
27882795 source : PathSource )
27892796 -> PathResolution {
2797+ self . smart_resolve_path_with_crate_lint ( id, qself, path, source, CrateLint :: SimplePath ( id) )
2798+ }
2799+
2800+ /// A variant of `smart_resolve_path` where you also specify extra
2801+ /// information about where the path came from; this extra info is
2802+ /// sometimes needed for the lint that recommends rewriting
2803+ /// absoluate paths to `crate`, so that it knows how to frame the
2804+ /// suggestion. If you are just resolving a path like `foo::bar`
2805+ /// that appears...somewhere, though, then you just want
2806+ /// `CrateLint::SimplePath`, which is what `smart_resolve_path`
2807+ /// already provides.
2808+ fn smart_resolve_path_with_crate_lint (
2809+ & mut self ,
2810+ id : NodeId ,
2811+ qself : Option < & QSelf > ,
2812+ path : & Path ,
2813+ source : PathSource ,
2814+ crate_lint : CrateLint
2815+ ) -> PathResolution {
27902816 let segments = & path. segments . iter ( )
27912817 . map ( |seg| seg. ident )
27922818 . collect :: < Vec < _ > > ( ) ;
2793- self . smart_resolve_path_fragment ( id, qself, segments, path. span , source)
2819+ self . smart_resolve_path_fragment ( id, qself, segments, path. span , source, crate_lint )
27942820 }
27952821
27962822 fn smart_resolve_path_fragment ( & mut self ,
27972823 id : NodeId ,
27982824 qself : Option < & QSelf > ,
27992825 path : & [ Ident ] ,
28002826 span : Span ,
2801- source : PathSource )
2827+ source : PathSource ,
2828+ crate_lint : CrateLint )
28022829 -> PathResolution {
28032830 let ident_span = path. last ( ) . map_or ( span, |ident| ident. span ) ;
28042831 let ns = source. namespace ( ) ;
@@ -2999,9 +3026,16 @@ impl<'a> Resolver<'a> {
29993026 err_path_resolution ( )
30003027 } ;
30013028
3002- let resolution = match self . resolve_qpath_anywhere ( id, qself, path, ns, span,
3003- source. defer_to_typeck ( ) ,
3004- source. global_by_default ( ) ) {
3029+ let resolution = match self . resolve_qpath_anywhere (
3030+ id,
3031+ qself,
3032+ path,
3033+ ns,
3034+ span,
3035+ source. defer_to_typeck ( ) ,
3036+ source. global_by_default ( ) ,
3037+ crate_lint,
3038+ ) {
30053039 Some ( resolution) if resolution. unresolved_segments ( ) == 0 => {
30063040 if is_expected ( resolution. base_def ( ) ) || resolution. base_def ( ) == Def :: Err {
30073041 resolution
@@ -3102,14 +3136,15 @@ impl<'a> Resolver<'a> {
31023136 primary_ns : Namespace ,
31033137 span : Span ,
31043138 defer_to_typeck : bool ,
3105- global_by_default : bool )
3139+ global_by_default : bool ,
3140+ crate_lint : CrateLint )
31063141 -> Option < PathResolution > {
31073142 let mut fin_res = None ;
31083143 // FIXME: can't resolve paths in macro namespace yet, macros are
31093144 // processed by the little special hack below.
31103145 for ( i, ns) in [ primary_ns, TypeNS , ValueNS , /*MacroNS*/ ] . iter ( ) . cloned ( ) . enumerate ( ) {
31113146 if i == 0 || ns != primary_ns {
3112- match self . resolve_qpath ( id, qself, path, ns, span, global_by_default) {
3147+ match self . resolve_qpath ( id, qself, path, ns, span, global_by_default, crate_lint ) {
31133148 // If defer_to_typeck, then resolution > no resolution,
31143149 // otherwise full resolution > partial resolution > no resolution.
31153150 Some ( res) if res. unresolved_segments ( ) == 0 || defer_to_typeck =>
@@ -3137,7 +3172,8 @@ impl<'a> Resolver<'a> {
31373172 path : & [ Ident ] ,
31383173 ns : Namespace ,
31393174 span : Span ,
3140- global_by_default : bool )
3175+ global_by_default : bool ,
3176+ crate_lint : CrateLint )
31413177 -> Option < PathResolution > {
31423178 debug ! (
31433179 "resolve_qpath(id={:?}, qself={:?}, path={:?}, \
@@ -3159,8 +3195,14 @@ impl<'a> Resolver<'a> {
31593195 }
31603196 // Make sure `A::B` in `<T as A>::B::C` is a trait item.
31613197 let ns = if qself. position + 1 == path. len ( ) { ns } else { TypeNS } ;
3162- let res = self . smart_resolve_path_fragment ( id, None , & path[ ..qself. position + 1 ] ,
3163- span, PathSource :: TraitItem ( ns) ) ;
3198+ let res = self . smart_resolve_path_fragment (
3199+ id,
3200+ None ,
3201+ & path[ ..qself. position + 1 ] ,
3202+ span,
3203+ PathSource :: TraitItem ( ns) ,
3204+ crate_lint, // TODO wrong
3205+ ) ;
31643206 return Some ( PathResolution :: with_unresolved_segments (
31653207 res. base_def ( ) , res. unresolved_segments ( ) + path. len ( ) - qself. position - 1
31663208 ) ) ;
@@ -4113,8 +4155,14 @@ impl<'a> Resolver<'a> {
41134155 let segments = path. make_root ( ) . iter ( ) . chain ( path. segments . iter ( ) )
41144156 . map ( |seg| seg. ident )
41154157 . collect :: < Vec < _ > > ( ) ;
4116- let def = self . smart_resolve_path_fragment ( id, None , & segments, path. span ,
4117- PathSource :: Visibility ) . base_def ( ) ;
4158+ let def = self . smart_resolve_path_fragment (
4159+ id,
4160+ None ,
4161+ & segments,
4162+ path. span ,
4163+ PathSource :: Visibility ,
4164+ CrateLint :: SimplePath ( id) ,
4165+ ) . base_def ( ) ;
41184166 if def == Def :: Err {
41194167 ty:: Visibility :: Public
41204168 } else {
@@ -4474,7 +4522,7 @@ pub enum MakeGlobMap {
44744522 No ,
44754523}
44764524
4477- #[ derive( Debug ) ]
4525+ #[ derive( Copy , Clone , Debug ) ]
44784526enum CrateLint {
44794527 /// Do not issue the lint
44804528 No ,
0 commit comments