@@ -147,7 +147,7 @@ enum ResolutionError<'a> {
147147 /// error E0416: identifier is bound more than once in the same pattern
148148 IdentifierBoundMoreThanOnceInSamePattern ( & ' a str ) ,
149149 /// error E0417: static variables cannot be referenced in a pattern
150- StaticVariableReference ,
150+ StaticVariableReference ( DefId , Option < Name > ) ,
151151 /// error E0418: is not an enum variant, struct or const
152152 NotAnEnumVariantStructOrConst ( & ' a str ) ,
153153 /// 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>,
352352 "identifier `{}` is bound more than once in the same pattern" ,
353353 identifier)
354354 }
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
361373 }
362374 ResolutionError :: NotAnEnumVariantStructOrConst ( name) => {
363375 struct_span_err ! ( resolver. session,
@@ -2313,10 +2325,11 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
23132325 Def :: Variant ( ..) | Def :: Const ( ..) => {
23142326 self . record_def ( pattern. id , path_res) ;
23152327 }
2316- Def :: Static ( .. ) => {
2328+ Def :: Static ( did , _ ) => {
23172329 resolve_error ( & self ,
23182330 path. span ,
2319- ResolutionError :: StaticVariableReference ) ;
2331+ ResolutionError :: StaticVariableReference (
2332+ did, None ) ) ;
23202333 self . record_def ( pattern. id , err_path_resolution ( ) ) ;
23212334 }
23222335 _ => {
@@ -2456,8 +2469,9 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24562469 Some ( def @ Def :: Const ( ..) ) | Some ( def @ Def :: AssociatedConst ( ..) ) => {
24572470 FoundConst ( def, ident. unhygienic_name )
24582471 }
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 ) ) ) ;
24612475 BareIdentifierPatternUnresolved
24622476 }
24632477 _ => BareIdentifierPatternUnresolved ,
0 commit comments