@@ -3233,6 +3233,10 @@ impl<'a> Resolver<'a> {
3233
3233
let mut module = None ;
3234
3234
let mut allow_super = true ;
3235
3235
3236
+ let mut fully_local = true ;
3237
+ // are we doing the first resolution? I.e. ignoring :: and crate
3238
+ // and stuff, have we resolved anything yet?
3239
+ let mut first_resolution = true ;
3236
3240
for ( i, & ident) in path. iter ( ) . enumerate ( ) {
3237
3241
debug ! ( "resolve_path ident {} {:?}" , i, ident) ;
3238
3242
let is_last = i == path. len ( ) - 1 ;
@@ -3242,8 +3246,10 @@ impl<'a> Resolver<'a> {
3242
3246
if i == 0 && ns == TypeNS && name == keywords:: SelfValue . name ( ) {
3243
3247
let mut ctxt = ident. span . ctxt ( ) . modern ( ) ;
3244
3248
module = Some ( self . resolve_self ( & mut ctxt, self . current_module ) ) ;
3249
+ first_resolution = false ;
3245
3250
continue
3246
3251
} else if allow_super && ns == TypeNS && name == keywords:: Super . name ( ) {
3252
+ first_resolution = false ;
3247
3253
let mut ctxt = ident. span . ctxt ( ) . modern ( ) ;
3248
3254
let self_module = match i {
3249
3255
0 => self . resolve_self ( & mut ctxt, self . current_module ) ,
@@ -3270,6 +3276,7 @@ impl<'a> Resolver<'a> {
3270
3276
continue
3271
3277
} else if i == 0 && name == keywords:: DollarCrate . name ( ) {
3272
3278
// `$crate::a::b`
3279
+ fully_local = false ;
3273
3280
module = Some ( self . resolve_crate_root ( ident. span . ctxt ( ) , true ) ) ;
3274
3281
continue
3275
3282
} else if i == 1 && !token:: is_path_segment_keyword ( ident) {
@@ -3285,6 +3292,8 @@ impl<'a> Resolver<'a> {
3285
3292
self . get_module ( DefId { krate : crate_id, index : CRATE_DEF_INDEX } ) ;
3286
3293
self . populate_module_if_necessary ( crate_root) ;
3287
3294
module = Some ( crate_root) ;
3295
+ fully_local = false ;
3296
+ first_resolution = false ;
3288
3297
continue
3289
3298
}
3290
3299
}
@@ -3337,6 +3346,27 @@ impl<'a> Resolver<'a> {
3337
3346
let def = binding. def ( ) ;
3338
3347
let maybe_assoc = opt_ns != Some ( MacroNS ) && PathSource :: Type . is_expected ( def) ;
3339
3348
if let Some ( next_module) = binding. module ( ) {
3349
+ if ns == TypeNS && fully_local && module. is_some ( ) && !first_resolution {
3350
+ if let Some ( id) = node_id {
3351
+ if self . extern_prelude . contains ( & ident. name ) {
3352
+ let crate_id =
3353
+ self . crate_loader
3354
+ . process_path_extern ( ident. name , ident. span ) ;
3355
+ let binding_id = binding. def ( ) . def_id ( ) ;
3356
+ if binding_id. krate == crate_id &&
3357
+ binding_id. index == CRATE_DEF_INDEX {
3358
+ self . session . buffer_lint (
3359
+ lint:: builtin:: USE_CRATE_IN_MODULE ,
3360
+ id, ident. span ,
3361
+ "The crate can be used directly \
3362
+ here.") ;
3363
+ }
3364
+ }
3365
+ }
3366
+
3367
+ }
3368
+ fully_local = fully_local && next_module. is_local ( ) ;
3369
+ first_resolution = false ;
3340
3370
module = Some ( next_module) ;
3341
3371
} else if def == Def :: Err {
3342
3372
return PathResult :: NonModule ( err_path_resolution ( ) ) ;
0 commit comments