@@ -147,7 +147,7 @@ enum ResolutionError<'a> {
147
147
/// error E0416: identifier is bound more than once in the same pattern
148
148
IdentifierBoundMoreThanOnceInSamePattern ( & ' a str ) ,
149
149
/// error E0417: static variables cannot be referenced in a pattern
150
- StaticVariableReference ,
150
+ StaticVariableReference ( DefId , Option < Name > ) ,
151
151
/// error E0418: is not an enum variant, struct or const
152
152
NotAnEnumVariantStructOrConst ( & ' a str ) ,
153
153
/// error E0419: unresolved enum variant, struct or const
@@ -352,12 +352,24 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
352
352
"identifier `{}` is bound more than once in the same pattern" ,
353
353
identifier)
354
354
}
355
- ResolutionError :: StaticVariableReference => {
356
- struct_span_err ! ( resolver. session,
357
- span,
358
- E0417 ,
359
- "static variables cannot be referenced in a pattern, use a \
360
- `const` instead")
355
+ ResolutionError :: StaticVariableReference ( did, name) => {
356
+ let mut err = struct_span_err ! ( resolver. session,
357
+ span,
358
+ E0417 ,
359
+ "static variables cannot be referenced in a \
360
+ pattern, use a `const` instead") ;
361
+ if let Some ( sp) = resolver. ast_map . span_if_local ( did) {
362
+ err. span_note ( sp, "static variable defined here" ) ;
363
+ }
364
+ if let Some ( name) = name {
365
+ if let Some ( binding) = resolver. current_module
366
+ . resolve_name_in_lexical_scope ( name, ValueNS ) {
367
+ if binding. is_import ( ) {
368
+ err. span_note ( binding. span , "static variable imported here" ) ;
369
+ }
370
+ }
371
+ }
372
+ err
361
373
}
362
374
ResolutionError :: NotAnEnumVariantStructOrConst ( name) => {
363
375
struct_span_err ! ( resolver. session,
@@ -2313,10 +2325,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2313
2325
Def :: Variant ( ..) | Def :: Const ( ..) => {
2314
2326
self . record_def ( pattern. id , path_res) ;
2315
2327
}
2316
- Def :: Static ( .. ) => {
2328
+ Def :: Static ( did , _ ) => {
2317
2329
resolve_error ( & self ,
2318
2330
path. span ,
2319
- ResolutionError :: StaticVariableReference ) ;
2331
+ ResolutionError :: StaticVariableReference (
2332
+ did, None ) ) ;
2320
2333
self . record_def ( pattern. id , err_path_resolution ( ) ) ;
2321
2334
}
2322
2335
_ => {
@@ -2456,8 +2469,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
2456
2469
Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
2457
2470
FoundConst ( def, ident. unhygienic_name )
2458
2471
}
2459
- Some ( Def :: Static ( ..) ) => {
2460
- resolve_error ( self , span, ResolutionError :: StaticVariableReference ) ;
2472
+ Some ( Def :: Static ( did, _) ) => {
2473
+ resolve_error ( self , span, ResolutionError :: StaticVariableReference (
2474
+ did, Some ( ident. unhygienic_name ) ) ) ;
2461
2475
BareIdentifierPatternUnresolved
2462
2476
}
2463
2477
_ => BareIdentifierPatternUnresolved ,
0 commit comments