@@ -75,7 +75,7 @@ use syntax_pos::{Span, DUMMY_SP, MultiSpan};
7575use errors:: { Applicability , DiagnosticBuilder , DiagnosticId } ;
7676
7777use std:: cell:: { Cell , RefCell } ;
78- use std:: { cmp, fmt, iter, ptr} ;
78+ use std:: { cmp, fmt, iter, mem , ptr} ;
7979use std:: collections:: BTreeSet ;
8080use std:: mem:: replace;
8181use rustc_data_structures:: ptr_key:: PtrKey ;
@@ -2394,11 +2394,27 @@ impl<'a, 'crateloader: 'a> Resolver<'a, 'crateloader> {
23942394 ast:: UseTreeKind :: Simple ( ..) if segments. len ( ) == 1 => & [ TypeNS , ValueNS ] [ ..] ,
23952395 _ => & [ TypeNS ] ,
23962396 } ;
2397+ let report_error = |this : & Self , ns| {
2398+ let what = if ns == TypeNS { "type parameters" } else { "local variables" } ;
2399+ this. session . span_err ( ident. span , & format ! ( "imports cannot refer to {}" , what) ) ;
2400+ } ;
2401+
23972402 for & ns in nss {
2398- if let Some ( LexicalScopeBinding :: Def ( ..) ) =
2399- self . resolve_ident_in_lexical_scope ( ident, ns, None , use_tree. prefix . span ) {
2400- let what = if ns == TypeNS { "type parameters" } else { "local variables" } ;
2401- self . session . span_err ( ident. span , & format ! ( "imports cannot refer to {}" , what) ) ;
2403+ match self . resolve_ident_in_lexical_scope ( ident, ns, None , use_tree. prefix . span ) {
2404+ Some ( LexicalScopeBinding :: Def ( ..) ) => {
2405+ report_error ( self , ns) ;
2406+ }
2407+ Some ( LexicalScopeBinding :: Item ( binding) ) => {
2408+ let orig_blacklisted_binding =
2409+ mem:: replace ( & mut self . blacklisted_binding , Some ( binding) ) ;
2410+ if let Some ( LexicalScopeBinding :: Def ( ..) ) =
2411+ self . resolve_ident_in_lexical_scope ( ident, ns, None ,
2412+ use_tree. prefix . span ) {
2413+ report_error ( self , ns) ;
2414+ }
2415+ self . blacklisted_binding = orig_blacklisted_binding;
2416+ }
2417+ None => { }
24022418 }
24032419 }
24042420 } else if let ast:: UseTreeKind :: Nested ( use_trees) = & use_tree. kind {
0 commit comments