mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
reduce unnecessary allocations a bit
This commit is contained in:
@@ -288,27 +288,24 @@ pub(super) fn emit_frag_parse_err(
|
||||
_ => annotate_err_with_kind(&mut e, kind, site_span),
|
||||
};
|
||||
|
||||
let mut bindings_rules = vec![];
|
||||
for rule in bindings {
|
||||
let MacroRule::Func { lhs, .. } = rule else { continue };
|
||||
for param in lhs {
|
||||
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
|
||||
bindings_rules.push(*bind);
|
||||
}
|
||||
}
|
||||
|
||||
let mut matched_rule_bindings_rules = vec![];
|
||||
for param in matched_rule_bindings {
|
||||
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
|
||||
matched_rule_bindings_rules.push(*bind);
|
||||
}
|
||||
|
||||
let matched_rule_bindings_names: Vec<_> =
|
||||
matched_rule_bindings_rules.iter().map(|bind| bind.name).collect();
|
||||
let bindings_name: Vec<_> = bindings_rules.iter().map(|bind| bind.name).collect();
|
||||
if parser.token.kind == token::Dollar {
|
||||
parser.bump();
|
||||
if let token::Ident(name, _) = parser.token.kind {
|
||||
let mut bindings_names = vec![];
|
||||
for rule in bindings {
|
||||
let MacroRule::Func { lhs, .. } = rule else { continue };
|
||||
for param in lhs {
|
||||
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
|
||||
bindings_names.push(bind.name);
|
||||
}
|
||||
}
|
||||
|
||||
let mut matched_rule_bindings_names = vec![];
|
||||
for param in matched_rule_bindings {
|
||||
let MatcherLoc::MetaVarDecl { bind, .. } = param else { continue };
|
||||
matched_rule_bindings_names.push(bind.name);
|
||||
}
|
||||
|
||||
if let Some(matched_name) = rustc_span::edit_distance::find_best_match_for_name(
|
||||
&matched_rule_bindings_names[..],
|
||||
name,
|
||||
@@ -316,22 +313,22 @@ pub(super) fn emit_frag_parse_err(
|
||||
) {
|
||||
e.span_suggestion_verbose(
|
||||
parser.token.span,
|
||||
"there is a macro metavariable with similar name",
|
||||
format!("{matched_name}"),
|
||||
"there is a macro metavariable with a similar name",
|
||||
matched_name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else if bindings_name.contains(&name) {
|
||||
} else if bindings_names.contains(&name) {
|
||||
e.span_label(
|
||||
parser.token.span,
|
||||
"there is an macro metavariable with this name in another macro matcher",
|
||||
);
|
||||
} else if let Some(matched_name) =
|
||||
rustc_span::edit_distance::find_best_match_for_name(&bindings_name[..], name, None)
|
||||
rustc_span::edit_distance::find_best_match_for_name(&bindings_names[..], name, None)
|
||||
{
|
||||
e.span_suggestion_verbose(
|
||||
parser.token.span,
|
||||
"there is a macro metavariable with a similar name in another macro matcher",
|
||||
format!("{matched_name}"),
|
||||
matched_name,
|
||||
Applicability::MaybeIncorrect,
|
||||
);
|
||||
} else {
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
macro_rules! m {
|
||||
(begin $ard:ident end) => {
|
||||
[$ard] //~ ERROR: expected expression, found `$`
|
||||
//~^ HELP: there is a macro metavariable with similar name
|
||||
//~^ HELP: there is a macro metavariable with a similar name
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -2,7 +2,7 @@
|
||||
macro_rules! m {
|
||||
(begin $ard:ident end) => {
|
||||
[$arg] //~ ERROR: expected expression, found `$`
|
||||
//~^ HELP: there is a macro metavariable with similar name
|
||||
//~^ HELP: there is a macro metavariable with a similar name
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -8,7 +8,7 @@ LL | let _ = m![begin x end];
|
||||
| --------------- in this macro invocation
|
||||
|
|
||||
= note: this error originates in the macro `m` (in Nightly builds, run with -Z macro-backtrace for more info)
|
||||
help: there is a macro metavariable with similar name
|
||||
help: there is a macro metavariable with a similar name
|
||||
|
|
||||
LL - [$arg]
|
||||
LL + [$ard]
|
||||
|
||||
Reference in New Issue
Block a user