@@ -67,7 +67,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
6767use errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
6868
6969use std:: cell:: { Cell , RefCell } ;
70- use std:: { cmp, fmt, iter, ptr} ;
70+ use std:: { cmp, fmt, iter, mem , ptr} ;
7171use std:: collections:: BTreeSet ;
7272use std:: mem:: replace;
7373use rustc_data_structures:: ptr_key:: PtrKey ;
@@ -2375,11 +2375,27 @@ impl<'a> Resolver<'a> {
23752375 ast:: UseTreeKind :: Simple ( ..) if segments. len ( ) == 1 => & [ TypeNS , ValueNS ] [ ..] ,
23762376 _ => & [ TypeNS ] ,
23772377 } ;
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+
23782383 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 => { }
23832399 }
23842400 }
23852401 } else if let ast:: UseTreeKind :: Nested ( use_trees) = & use_tree. kind {
0 commit comments