@@ -158,7 +158,7 @@ enum ResolutionError<'a> {
158158 /// error E0435: attempt to use a non-constant value in a constant
159159 AttemptToUseNonConstantValueInConstant ,
160160 /// error E0530: X bindings cannot shadow Ys
161- BindingShadowsSomethingUnacceptable ( & ' a str , & ' a str , Name ) ,
161+ BindingShadowsSomethingUnacceptable ( & ' a str , Name , & ' a NameBinding < ' a > ) ,
162162 /// error E0531: unresolved pattern path kind `name`
163163 PatPathUnresolved ( & ' a str , & ' a Path ) ,
164164 /// error E0532: expected pattern path kind, found another pattern path kind
@@ -422,17 +422,16 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
422422 E0435 ,
423423 "attempt to use a non-constant value in a constant" )
424424 }
425- ResolutionError :: BindingShadowsSomethingUnacceptable ( what_binding, shadows_what, name) => {
425+ ResolutionError :: BindingShadowsSomethingUnacceptable ( what_binding, name, binding) => {
426+ let shadows_what = PathResolution :: new ( binding. def ( ) . unwrap ( ) ) . kind_name ( ) ;
426427 let mut err = struct_span_err ! ( resolver. session,
427428 span,
428429 E0530 ,
429430 "{}s cannot shadow {}s" , what_binding, shadows_what) ;
430431 err. span_label ( span, & format ! ( "cannot be named the same as a {}" , shadows_what) ) ;
431- if let Success ( binding) = resolver. current_module . resolve_name ( name, ValueNS , true ) {
432- let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
433- err. span_label ( binding. span , & format ! ( "a {} `{}` is {} here" ,
434- shadows_what, name, participle) ) ;
435- }
432+ let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
433+ let msg = & format ! ( "a {} `{}` is {} here" , shadows_what, name, participle) ;
434+ err. span_label ( binding. span , msg) ;
436435 err
437436 }
438437 ResolutionError :: PatPathUnresolved ( expected_what, path) => {
@@ -712,12 +711,16 @@ impl<'a> LexicalScopeBinding<'a> {
712711 }
713712 }
714713
715- fn module ( self ) -> Option < Module < ' a > > {
714+ fn item ( self ) -> Option < & ' a NameBinding < ' a > > {
716715 match self {
717- LexicalScopeBinding :: Item ( binding) => binding . module ( ) ,
716+ LexicalScopeBinding :: Item ( binding) => Some ( binding ) ,
718717 _ => None ,
719718 }
720719 }
720+
721+ fn module ( self ) -> Option < Module < ' a > > {
722+ self . item ( ) . and_then ( NameBinding :: module)
723+ }
721724}
722725
723726/// The link from a module up to its nearest parent node.
@@ -2316,16 +2319,17 @@ impl<'a> Resolver<'a> {
23162319 PatKind :: Ident ( bmode, ref ident, ref opt_pat) => {
23172320 // First try to resolve the identifier as some existing
23182321 // entity, then fall back to a fresh binding.
2319- let resolution = self . resolve_identifier ( ident. node , ValueNS , true )
2320- . map ( |local_def| PathResolution :: new ( local_def . def ) )
2321- . and_then ( |resolution | {
2322+ let binding = self . resolve_ident_in_lexical_scope ( ident. node , ValueNS , false )
2323+ . and_then ( LexicalScopeBinding :: item ) ;
2324+ let resolution = binding . and_then ( NameBinding :: def ) . and_then ( |def | {
23222325 let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
23232326 bmode != BindingMode :: ByValue ( Mutability :: Immutable ) ;
2324- match resolution . base_def {
2327+ match def {
23252328 Def :: Struct ( ..) | Def :: Variant ( ..) |
23262329 Def :: Const ( ..) | Def :: AssociatedConst ( ..) if !always_binding => {
23272330 // A constant, unit variant, etc pattern.
2328- Some ( resolution)
2331+ self . record_use ( ident. node . name , ValueNS , binding. unwrap ( ) ) ;
2332+ Some ( PathResolution :: new ( def) )
23292333 }
23302334 Def :: Struct ( ..) | Def :: Variant ( ..) |
23312335 Def :: Const ( ..) | Def :: AssociatedConst ( ..) | Def :: Static ( ..) => {
@@ -2334,7 +2338,7 @@ impl<'a> Resolver<'a> {
23342338 self ,
23352339 ident. span ,
23362340 ResolutionError :: BindingShadowsSomethingUnacceptable (
2337- pat_src. descr ( ) , resolution . kind_name ( ) , ident. node . name )
2341+ pat_src. descr ( ) , ident. node . name , binding . unwrap ( ) )
23382342 ) ;
23392343 None
23402344 }
0 commit comments