@@ -158,7 +158,7 @@ enum ResolutionError<'a> {
158
158
/// error E0416: identifier is bound more than once in the same pattern
159
159
IdentifierBoundMoreThanOnceInSamePattern ( & ' a str ) ,
160
160
/// error E0417: static variables cannot be referenced in a pattern
161
- StaticVariableReference ,
161
+ StaticVariableReference ( DefId , Option < Name > ) ,
162
162
/// error E0418: is not an enum variant, struct or const
163
163
NotAnEnumVariantStructOrConst ( & ' a str ) ,
164
164
/// error E0419: unresolved enum variant, struct or const
@@ -367,12 +367,24 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
367
367
"identifier `{}` is bound more than once in the same pattern" ,
368
368
identifier)
369
369
}
370
- ResolutionError :: StaticVariableReference => {
371
- struct_span_err ! ( resolver. session,
372
- span,
373
- E0417 ,
374
- "static variables cannot be referenced in a pattern, use a \
375
- `const` instead")
370
+ ResolutionError :: StaticVariableReference ( did, name) => {
371
+ let mut err = struct_span_err ! ( resolver. session,
372
+ span,
373
+ E0417 ,
374
+ "static variables cannot be referenced in a \
375
+ pattern, use a `const` instead") ;
376
+ if let Some ( sp) = resolver. ast_map . span_if_local ( did) {
377
+ err. span_note ( sp, "static variable defined here" ) ;
378
+ }
379
+ if let Some ( name) = name {
380
+ if let Some ( binding) = resolver. current_module
381
+ . resolve_name_in_lexical_scope ( name, ValueNS ) {
382
+ if binding. is_import ( ) {
383
+ err. span_note ( binding. span , "static variable imported here" ) ;
384
+ }
385
+ }
386
+ }
387
+ err
376
388
}
377
389
ResolutionError :: NotAnEnumVariantStructOrConst ( name) => {
378
390
struct_span_err ! ( resolver. session,
@@ -2374,10 +2386,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2374
2386
Def :: Variant ( ..) | Def :: Const ( ..) => {
2375
2387
self . record_def ( pattern. id , path_res) ;
2376
2388
}
2377
- Def :: Static ( .. ) => {
2389
+ Def :: Static ( did , _ ) => {
2378
2390
resolve_error ( & self ,
2379
2391
path. span ,
2380
- ResolutionError :: StaticVariableReference ) ;
2392
+ ResolutionError :: StaticVariableReference (
2393
+ did, None ) ) ;
2381
2394
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2382
2395
}
2383
2396
_ => {
@@ -2517,8 +2530,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2517
2530
Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
2518
2531
FoundConst ( def, ident. unhygienic_name )
2519
2532
}
2520
- Some ( Def :: Static ( ..) ) => {
2521
- resolve_error ( self , span, ResolutionError :: StaticVariableReference ) ;
2533
+ Some ( Def :: Static ( did, _) ) => {
2534
+ resolve_error ( self , span, ResolutionError :: StaticVariableReference (
2535
+ did, Some ( ident. unhygienic_name ) ) ) ;
2522
2536
BareIdentifierPatternUnresolved
2523
2537
}
2524
2538
_ => BareIdentifierPatternUnresolved ,
0 commit comments