@@ -145,7 +145,7 @@ enum ResolutionError<'a> {
145
145
/// error E0416: identifier is bound more than once in the same pattern
146
146
IdentifierBoundMoreThanOnceInSamePattern ( & ' a str ) ,
147
147
/// error E0417: static variables cannot be referenced in a pattern
148
- StaticVariableReference ( DefId , Option < Name > ) ,
148
+ StaticVariableReference ( & ' a NameBinding < ' a > ) ,
149
149
/// error E0418: is not an enum variant, struct or const
150
150
NotAnEnumVariantStructOrConst ( & ' a str ) ,
151
151
/// error E0419: unresolved enum variant, struct or const
@@ -197,16 +197,16 @@ enum UnresolvedNameContext<'a> {
197
197
Other ,
198
198
}
199
199
200
- fn resolve_error < ' b , ' a : ' b , ' tcx : ' a > ( resolver : & ' b Resolver < ' a , ' tcx > ,
201
- span : syntax:: codemap:: Span ,
202
- resolution_error : ResolutionError < ' b > ) {
200
+ fn resolve_error < ' b , ' a : ' b , ' tcx : ' a , ' c > ( resolver : & ' b Resolver < ' a , ' tcx > ,
201
+ span : syntax:: codemap:: Span ,
202
+ resolution_error : ResolutionError < ' c > ) {
203
203
resolve_struct_error ( resolver, span, resolution_error) . emit ( ) ;
204
204
}
205
205
206
- fn resolve_struct_error < ' b , ' a : ' b , ' tcx : ' a > ( resolver : & ' b Resolver < ' a , ' tcx > ,
207
- span : syntax:: codemap:: Span ,
208
- resolution_error : ResolutionError < ' b > )
209
- -> DiagnosticBuilder < ' a > {
206
+ fn resolve_struct_error < ' b , ' a : ' b , ' tcx : ' a , ' c > ( resolver : & ' b Resolver < ' a , ' tcx > ,
207
+ span : syntax:: codemap:: Span ,
208
+ resolution_error : ResolutionError < ' b > )
209
+ -> DiagnosticBuilder < ' c > {
210
210
if !resolver. emit_errors {
211
211
return resolver. session . diagnostic ( ) . struct_dummy ( ) ;
212
212
}
@@ -350,22 +350,15 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
350
350
"identifier `{}` is bound more than once in the same pattern" ,
351
351
identifier)
352
352
}
353
- ResolutionError :: StaticVariableReference ( did , name ) => {
353
+ ResolutionError :: StaticVariableReference ( binding ) => {
354
354
let mut err = struct_span_err ! ( resolver. session,
355
355
span,
356
356
E0417 ,
357
357
"static variables cannot be referenced in a \
358
358
pattern, use a `const` instead") ;
359
- if let Some ( sp) = resolver. ast_map . span_if_local ( did) {
360
- err. span_note ( sp, "static variable defined here" ) ;
361
- }
362
- if let Some ( name) = name {
363
- if let Some ( binding) = resolver. current_module
364
- . resolve_name_in_lexical_scope ( name, ValueNS ) {
365
- if binding. is_import ( ) {
366
- err. span_note ( binding. span , "static variable imported here" ) ;
367
- }
368
- }
359
+ if binding. span != codemap:: DUMMY_SP {
360
+ let participle = if binding. is_import ( ) { "imported" } else { "defined" } ;
361
+ err. span_note ( binding. span , & format ! ( "static variable {} here" , participle) ) ;
369
362
}
370
363
err
371
364
}
@@ -766,10 +759,6 @@ impl<'a> LexicalScopeBinding<'a> {
766
759
}
767
760
}
768
761
769
- fn def ( self ) -> Def {
770
- self . local_def ( ) . def
771
- }
772
-
773
762
fn module ( self ) -> Option < Module < ' a > > {
774
763
match self {
775
764
LexicalScopeBinding :: Item ( binding) => binding. module ( ) ,
@@ -2328,11 +2317,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2328
2317
Def :: Variant ( ..) | Def :: Const ( ..) => {
2329
2318
self . record_def ( pattern. id , path_res) ;
2330
2319
}
2331
- Def :: Static ( did, _) => {
2332
- resolve_error ( & self ,
2333
- path. span ,
2334
- ResolutionError :: StaticVariableReference (
2335
- did, None ) ) ;
2320
+ Def :: Static ( ..) => {
2321
+ let segments = & path. segments ;
2322
+ let binding = if path. global {
2323
+ self . resolve_crate_relative_path ( path. span , segments, ValueNS )
2324
+ } else {
2325
+ self . resolve_module_relative_path ( path. span , segments, ValueNS )
2326
+ } . unwrap ( ) ;
2327
+
2328
+ let error = ResolutionError :: StaticVariableReference ( binding) ;
2329
+ resolve_error ( self , path. span , error) ;
2336
2330
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2337
2331
}
2338
2332
_ => {
@@ -2464,17 +2458,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2464
2458
2465
2459
fn resolve_bare_identifier_pattern ( & mut self , ident : hir:: Ident , span : Span )
2466
2460
-> BareIdentifierPatternResolution {
2467
- match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true )
2468
- . map ( LexicalScopeBinding :: def) {
2469
- Some ( def @ Def :: Variant ( ..) ) | Some ( def @ Def :: Struct ( ..) ) => {
2470
- FoundStructOrEnumVariant ( def)
2471
- }
2472
- Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
2473
- FoundConst ( def, ident. unhygienic_name )
2474
- }
2475
- Some ( Def :: Static ( did, _) ) => {
2476
- resolve_error ( self , span, ResolutionError :: StaticVariableReference (
2477
- did, Some ( ident. unhygienic_name ) ) ) ;
2461
+ let binding = match self . resolve_ident_in_lexical_scope ( ident, ValueNS , true ) {
2462
+ Some ( LexicalScopeBinding :: Item ( binding) ) => binding,
2463
+ _ => return BareIdentifierPatternUnresolved ,
2464
+ } ;
2465
+ let def = binding. def ( ) . unwrap ( ) ;
2466
+
2467
+ match def {
2468
+ Def :: Variant ( ..) | Def :: Struct ( ..) => FoundStructOrEnumVariant ( def) ,
2469
+ Def :: Const ( ..) | Def :: AssociatedConst ( ..) => FoundConst ( def, ident. unhygienic_name ) ,
2470
+ Def :: Static ( ..) => {
2471
+ let error = ResolutionError :: StaticVariableReference ( binding) ;
2472
+ resolve_error ( self , span, error) ;
2478
2473
BareIdentifierPatternUnresolved
2479
2474
}
2480
2475
_ => BareIdentifierPatternUnresolved ,
0 commit comments