@@ -2247,7 +2247,13 @@ impl<'a> Resolver<'a> {
2247
2247
2248
2248
if items. len ( ) == 0 {
2249
2249
// 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
+ ) ;
2251
2257
} else {
2252
2258
for & ( ref tree, nested_id) in items {
2253
2259
self . resolve_use_tree ( nested_id, tree, & path) ;
@@ -2354,7 +2360,8 @@ impl<'a> Resolver<'a> {
2354
2360
None ,
2355
2361
& path,
2356
2362
trait_ref. path . span ,
2357
- PathSource :: Trait ( AliasPossibility :: No )
2363
+ PathSource :: Trait ( AliasPossibility :: No ) ,
2364
+ CrateLint :: SimplePath ( trait_ref. ref_id ) ,
2358
2365
) . base_def ( ) ;
2359
2366
if def != Def :: Err {
2360
2367
new_id = Some ( def. def_id ( ) ) ;
@@ -2787,18 +2794,38 @@ impl<'a> Resolver<'a> {
2787
2794
path : & Path ,
2788
2795
source : PathSource )
2789
2796
-> 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 {
2790
2816
let segments = & path. segments . iter ( )
2791
2817
. map ( |seg| seg. ident )
2792
2818
. 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 )
2794
2820
}
2795
2821
2796
2822
fn smart_resolve_path_fragment ( & mut self ,
2797
2823
id : NodeId ,
2798
2824
qself : Option < & QSelf > ,
2799
2825
path : & [ Ident ] ,
2800
2826
span : Span ,
2801
- source : PathSource )
2827
+ source : PathSource ,
2828
+ crate_lint : CrateLint )
2802
2829
-> PathResolution {
2803
2830
let ident_span = path. last ( ) . map_or ( span, |ident| ident. span ) ;
2804
2831
let ns = source. namespace ( ) ;
@@ -2999,9 +3026,16 @@ impl<'a> Resolver<'a> {
2999
3026
err_path_resolution ( )
3000
3027
} ;
3001
3028
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
+ ) {
3005
3039
Some ( resolution) if resolution. unresolved_segments ( ) == 0 => {
3006
3040
if is_expected ( resolution. base_def ( ) ) || resolution. base_def ( ) == Def :: Err {
3007
3041
resolution
@@ -3102,14 +3136,15 @@ impl<'a> Resolver<'a> {
3102
3136
primary_ns : Namespace ,
3103
3137
span : Span ,
3104
3138
defer_to_typeck : bool ,
3105
- global_by_default : bool )
3139
+ global_by_default : bool ,
3140
+ crate_lint : CrateLint )
3106
3141
-> Option < PathResolution > {
3107
3142
let mut fin_res = None ;
3108
3143
// FIXME: can't resolve paths in macro namespace yet, macros are
3109
3144
// processed by the little special hack below.
3110
3145
for ( i, ns) in [ primary_ns, TypeNS , ValueNS , /*MacroNS*/ ] . iter ( ) . cloned ( ) . enumerate ( ) {
3111
3146
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 ) {
3113
3148
// If defer_to_typeck, then resolution > no resolution,
3114
3149
// otherwise full resolution > partial resolution > no resolution.
3115
3150
Some ( res) if res. unresolved_segments ( ) == 0 || defer_to_typeck =>
@@ -3137,7 +3172,8 @@ impl<'a> Resolver<'a> {
3137
3172
path : & [ Ident ] ,
3138
3173
ns : Namespace ,
3139
3174
span : Span ,
3140
- global_by_default : bool )
3175
+ global_by_default : bool ,
3176
+ crate_lint : CrateLint )
3141
3177
-> Option < PathResolution > {
3142
3178
debug ! (
3143
3179
"resolve_qpath(id={:?}, qself={:?}, path={:?}, \
@@ -3159,8 +3195,14 @@ impl<'a> Resolver<'a> {
3159
3195
}
3160
3196
// Make sure `A::B` in `<T as A>::B::C` is a trait item.
3161
3197
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
+ ) ;
3164
3206
return Some ( PathResolution :: with_unresolved_segments (
3165
3207
res. base_def ( ) , res. unresolved_segments ( ) + path. len ( ) - qself. position - 1
3166
3208
) ) ;
@@ -4113,8 +4155,14 @@ impl<'a> Resolver<'a> {
4113
4155
let segments = path. make_root ( ) . iter ( ) . chain ( path. segments . iter ( ) )
4114
4156
. map ( |seg| seg. ident )
4115
4157
. 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 ( ) ;
4118
4166
if def == Def :: Err {
4119
4167
ty:: Visibility :: Public
4120
4168
} else {
@@ -4474,7 +4522,7 @@ pub enum MakeGlobMap {
4474
4522
No ,
4475
4523
}
4476
4524
4477
- #[ derive( Debug ) ]
4525
+ #[ derive( Copy , Clone , Debug ) ]
4478
4526
enum CrateLint {
4479
4527
/// Do not issue the lint
4480
4528
No ,
0 commit comments