@@ -288,52 +288,47 @@ pub(super) fn emit_frag_parse_err(
288288 _ => annotate_err_with_kind ( & mut e, kind, site_span) ,
289289 } ;
290290
291- let mut bindings_rules = vec ! [ ] ;
292- for rule in bindings {
293- let MacroRule :: Func { lhs, .. } = rule else { continue } ;
294- for param in lhs {
295- let MatcherLoc :: MetaVarDecl { bind, .. } = param else { continue } ;
296- bindings_rules. push ( * bind) ;
297- }
298- }
299-
300- let mut matched_rule_bindings_rules = vec ! [ ] ;
301- for param in matched_rule_bindings {
302- let MatcherLoc :: MetaVarDecl { bind, .. } = param else { continue } ;
303- matched_rule_bindings_rules. push ( * bind) ;
304- }
305-
306- let matched_rule_bindings_names: Vec < _ > =
307- matched_rule_bindings_rules. iter ( ) . map ( |bind| bind. name ) . collect ( ) ;
308- let bindings_name: Vec < _ > = bindings_rules. iter ( ) . map ( |bind| bind. name ) . collect ( ) ;
309291 if parser. token . kind == token:: Dollar {
310292 parser. bump ( ) ;
311293 if let token:: Ident ( name, _) = parser. token . kind {
294+ let mut bindings_names = vec ! [ ] ;
295+ for rule in bindings {
296+ let MacroRule :: Func { lhs, .. } = rule else { continue } ;
297+ for param in lhs {
298+ let MatcherLoc :: MetaVarDecl { bind, .. } = param else { continue } ;
299+ bindings_names. push ( bind. name ) ;
300+ }
301+ }
302+
303+ let mut matched_rule_bindings_names = vec ! [ ] ;
304+ for param in matched_rule_bindings {
305+ let MatcherLoc :: MetaVarDecl { bind, .. } = param else { continue } ;
306+ matched_rule_bindings_names. push ( bind. name ) ;
307+ }
308+
312309 if let Some ( matched_name) = rustc_span:: edit_distance:: find_best_match_for_name (
313310 & matched_rule_bindings_names[ ..] ,
314311 name,
315312 None ,
316313 ) {
317314 e. span_suggestion_verbose (
318315 parser. token . span ,
319- "there is a macro metavariable with similar name" ,
320- format ! ( "{ matched_name}" ) ,
316+ "there is a macro metavariable with a similar name" ,
317+ matched_name,
321318 Applicability :: MaybeIncorrect ,
322319 ) ;
323- } else if bindings_name . contains ( & name) {
320+ } else if bindings_names . contains ( & name) {
324321 e. span_label (
325322 parser. token . span ,
326- format ! (
327- "there is an macro metavariable with this name in another macro matcher"
328- ) ,
323+ "there is an macro metavariable with this name in another macro matcher" ,
329324 ) ;
330325 } else if let Some ( matched_name) =
331- rustc_span:: edit_distance:: find_best_match_for_name ( & bindings_name [ ..] , name, None )
326+ rustc_span:: edit_distance:: find_best_match_for_name ( & bindings_names [ ..] , name, None )
332327 {
333328 e. span_suggestion_verbose (
334329 parser. token . span ,
335330 "there is a macro metavariable with a similar name in another macro matcher" ,
336- format ! ( "{ matched_name}" ) ,
331+ matched_name,
337332 Applicability :: MaybeIncorrect ,
338333 ) ;
339334 } else {
@@ -343,7 +338,7 @@ pub(super) fn emit_frag_parse_err(
343338 . collect :: < Vec < _ > > ( )
344339 . join ( ", " ) ;
345340
346- e. span_label ( parser. token . span , format ! ( "macro metavariable not found" ) ) ;
341+ e. span_label ( parser. token . span , "macro metavariable not found" ) ;
347342 if !matched_rule_bindings_names. is_empty ( ) {
348343 e. note ( format ! ( "available metavariable names are: {msg}" ) ) ;
349344 }
0 commit comments