@@ -67,7 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
67
67
use errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
68
68
69
69
use std:: cell:: { Cell , RefCell } ;
70
- use std:: { cmp, fmt, iter, ptr} ;
70
+ use std:: { cmp, fmt, iter, mem , ptr} ;
71
71
use std:: collections:: BTreeSet ;
72
72
use std:: mem:: replace;
73
73
use rustc_data_structures:: ptr_key:: PtrKey ;
@@ -2375,11 +2375,27 @@ impl<'a> Resolver<'a> {
2375
2375
ast:: UseTreeKind :: Simple ( ..) if segments. len ( ) == 1 => & [ TypeNS , ValueNS ] [ ..] ,
2376
2376
_ => & [ TypeNS ] ,
2377
2377
} ;
2378
+ let report_error = |this : & Self , ns| {
2379
+ let what = if ns == TypeNS { "type parameters" } else { "local variables" } ;
2380
+ this. session . span_err ( ident. span , & format ! ( "imports cannot refer to {}" , what) ) ;
2381
+ } ;
2382
+
2378
2383
for & ns in nss {
2379
- if let Some ( LexicalScopeBinding :: Def ( ..) ) =
2380
- self . resolve_ident_in_lexical_scope ( ident, ns, None , use_tree. prefix . span ) {
2381
- let what = if ns == TypeNS { "type parameters" } else { "local variables" } ;
2382
- self . session . span_err ( ident. span , & format ! ( "imports cannot refer to {}" , what) ) ;
2384
+ match self . resolve_ident_in_lexical_scope ( ident, ns, None , use_tree. prefix . span ) {
2385
+ Some ( LexicalScopeBinding :: Def ( ..) ) => {
2386
+ report_error ( self , ns) ;
2387
+ }
2388
+ Some ( LexicalScopeBinding :: Item ( binding) ) => {
2389
+ let orig_blacklisted_binding =
2390
+ mem:: replace ( & mut self . blacklisted_binding , Some ( binding) ) ;
2391
+ if let Some ( LexicalScopeBinding :: Def ( ..) ) =
2392
+ self . resolve_ident_in_lexical_scope ( ident, ns, None ,
2393
+ use_tree. prefix . span ) {
2394
+ report_error ( self , ns) ;
2395
+ }
2396
+ self . blacklisted_binding = orig_blacklisted_binding;
2397
+ }
2398
+ None => { }
2383
2399
}
2384
2400
}
2385
2401
} else if let ast:: UseTreeKind :: Nested ( use_trees) = & use_tree. kind {
0 commit comments