@@ -145,7 +145,7 @@ enum ResolutionError<'a> {
145145 /// error E0416: identifier is bound more than once in the same pattern
146146 IdentifierBoundMoreThanOnceInSamePattern ( & ' a str ) ,
147147 /// error E0417: static variables cannot be referenced in a pattern
148- StaticVariableReference ( DefId , Option < Name > ) ,
148+ StaticVariableReference ( & ' a NameBinding < ' a > ) ,
149149 /// error E0418: is not an enum variant, struct or const
150150 NotAnEnumVariantStructOrConst ( & ' a str ) ,
151151 /// error E0419: unresolved enum variant, struct or const
@@ -197,16 +197,16 @@ enum UnresolvedNameContext<'a> {
197197 Other ,
198198}
199199
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 > ) {
203203 resolve_struct_error ( resolver, span, resolution_error) . emit ( ) ;
204204}
205205
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 > {
210210 if !resolver. emit_errors {
211211 return resolver. session . diagnostic ( ) . struct_dummy ( ) ;
212212 }
@@ -350,22 +350,15 @@ fn resolve_struct_error<'b, 'a: 'b, 'tcx: 'a>(resolver: &'b Resolver<'a, 'tcx>,
350350 "identifier `{}` is bound more than once in the same pattern" ,
351351 identifier)
352352 }
353- ResolutionError :: StaticVariableReference ( did , name ) => {
353+ ResolutionError :: StaticVariableReference ( binding ) => {
354354 let mut err = struct_span_err ! ( resolver. session,
355355 span,
356356 E0417 ,
357357 "static variables cannot be referenced in a \
358358 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) ) ;
369362 }
370363 err
371364 }
@@ -766,10 +759,6 @@ impl<'a> LexicalScopeBinding<'a> {
766759 }
767760 }
768761
769- fn def ( self ) -> Def {
770- self . local_def ( ) . def
771- }
772-
773762 fn module ( self ) -> Option < Module < ' a > > {
774763 match self {
775764 LexicalScopeBinding :: Item ( binding) => binding. module ( ) ,
@@ -2328,11 +2317,16 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
23282317 Def :: Variant ( ..) | Def :: Const ( ..) => {
23292318 self . record_def ( pattern. id , path_res) ;
23302319 }
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) ;
23362330 self . record_def ( pattern. id , err_path_resolution ( ) ) ;
23372331 }
23382332 _ => {
@@ -2464,17 +2458,18 @@ impl<'a, 'tcx> Resolver<'a, 'tcx> {
24642458
24652459 fn resolve_bare_identifier_pattern ( & mut self , ident : hir:: Ident , span : Span )
24662460 -> 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) ;
24782473 BareIdentifierPatternUnresolved
24792474 }
24802475 _ => BareIdentifierPatternUnresolved ,
0 commit comments