@@ -158,7 +158,7 @@ enum ResolutionError<'a> {
158
158
/// error E0435: attempt to use a non-constant value in a constant
159
159
AttemptToUseNonConstantValueInConstant ,
160
160
/// error E0530: X bindings cannot shadow Ys
161
- BindingShadowsSomethingUnacceptable ( & ' a str , & ' a str , Name ) ,
161
+ BindingShadowsSomethingUnacceptable ( & ' a str , Name , & ' a NameBinding < ' a > ) ,
162
162
/// error E0531: unresolved pattern path kind `name`
163
163
PatPathUnresolved ( & ' a str , & ' a Path ) ,
164
164
/// 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>,
422
422
E0435 ,
423
423
"attempt to use a non-constant value in a constant" )
424
424
}
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 ( ) ;
426
427
let mut err = struct_span_err ! ( resolver. session,
427
428
span,
428
429
E0530 ,
429
430
"{}s cannot shadow {}s" , what_binding, shadows_what) ;
430
431
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) ;
436
435
err
437
436
}
438
437
ResolutionError :: PatPathUnresolved ( expected_what, path) => {
@@ -712,12 +711,16 @@ impl<'a> LexicalScopeBinding<'a> {
712
711
}
713
712
}
714
713
715
- fn module ( self ) -> Option < Module < ' a > > {
714
+ fn item ( self ) -> Option < & ' a NameBinding < ' a > > {
716
715
match self {
717
- LexicalScopeBinding :: Item ( binding) => binding . module ( ) ,
716
+ LexicalScopeBinding :: Item ( binding) => Some ( binding ) ,
718
717
_ => None ,
719
718
}
720
719
}
720
+
721
+ fn module ( self ) -> Option < Module < ' a > > {
722
+ self . item ( ) . and_then ( NameBinding :: module)
723
+ }
721
724
}
722
725
723
726
/// The link from a module up to its nearest parent node.
@@ -2316,16 +2319,17 @@ impl<'a> Resolver<'a> {
2316
2319
PatKind :: Ident ( bmode, ref ident, ref opt_pat) => {
2317
2320
// First try to resolve the identifier as some existing
2318
2321
// 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 | {
2322
2325
let always_binding = !pat_src. is_refutable ( ) || opt_pat. is_some ( ) ||
2323
2326
bmode != BindingMode :: ByValue ( Mutability :: Immutable ) ;
2324
- match resolution . base_def {
2327
+ match def {
2325
2328
Def :: Struct ( ..) | Def :: Variant ( ..) |
2326
2329
Def :: Const ( ..) | Def :: AssociatedConst ( ..) if !always_binding => {
2327
2330
// A constant, unit variant, etc pattern.
2328
- Some ( resolution)
2331
+ self . record_use ( ident. node . name , ValueNS , binding. unwrap ( ) ) ;
2332
+ Some ( PathResolution :: new ( def) )
2329
2333
}
2330
2334
Def :: Struct ( ..) | Def :: Variant ( ..) |
2331
2335
Def :: Const ( ..) | Def :: AssociatedConst ( ..) | Def :: Static ( ..) => {
@@ -2334,7 +2338,7 @@ impl<'a> Resolver<'a> {
2334
2338
self ,
2335
2339
ident. span ,
2336
2340
ResolutionError :: BindingShadowsSomethingUnacceptable (
2337
- pat_src. descr ( ) , resolution . kind_name ( ) , ident. node . name )
2341
+ pat_src. descr ( ) , ident. node . name , binding . unwrap ( ) )
2338
2342
) ;
2339
2343
None
2340
2344
}
0 commit comments