mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-23 07:14:28 +00:00
Move a parse_tt
error case into a separate function.
This commit is contained in:
parent
235a87fbd3
commit
95d13fa37d
@ -762,10 +762,7 @@ pub(super) fn parse_tt(
|
|||||||
Err(mut err) => {
|
Err(mut err) => {
|
||||||
err.span_label(
|
err.span_label(
|
||||||
span,
|
span,
|
||||||
format!(
|
format!("while parsing argument for this `{kind}` macro fragment"),
|
||||||
"while parsing argument for this `{}` macro fragment",
|
|
||||||
kind
|
|
||||||
),
|
|
||||||
)
|
)
|
||||||
.emit();
|
.emit();
|
||||||
return ErrorReported;
|
return ErrorReported;
|
||||||
@ -784,27 +781,11 @@ pub(super) fn parse_tt(
|
|||||||
(_, _) => {
|
(_, _) => {
|
||||||
// We need to call the black-box parser to get some nonterminal, but something is
|
// We need to call the black-box parser to get some nonterminal, but something is
|
||||||
// wrong.
|
// wrong.
|
||||||
let nts = bb_items
|
return bb_items_ambiguity_error(
|
||||||
.iter()
|
macro_name,
|
||||||
.map(|item| match item.top_elts.get_tt(item.idx) {
|
next_items,
|
||||||
TokenTree::MetaVarDecl(_, bind, Some(kind)) => {
|
bb_items,
|
||||||
format!("{} ('{}')", kind, bind)
|
|
||||||
}
|
|
||||||
_ => panic!(),
|
|
||||||
})
|
|
||||||
.collect::<Vec<String>>()
|
|
||||||
.join(" or ");
|
|
||||||
|
|
||||||
return Error(
|
|
||||||
parser.token.span,
|
parser.token.span,
|
||||||
format!(
|
|
||||||
"local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}",
|
|
||||||
match next_items.len() {
|
|
||||||
0 => format!("built-in NTs {}.", nts),
|
|
||||||
1 => format!("built-in NTs {} or 1 other option.", nts),
|
|
||||||
n => format!("built-in NTs {} or {} other options.", nts, n),
|
|
||||||
}
|
|
||||||
),
|
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -812,3 +793,33 @@ pub(super) fn parse_tt(
|
|||||||
assert!(!cur_items.is_empty());
|
assert!(!cur_items.is_empty());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn bb_items_ambiguity_error<'root, 'tt>(
|
||||||
|
macro_name: Ident,
|
||||||
|
next_items: SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
|
||||||
|
bb_items: SmallVec<[MatcherPosHandle<'root, 'tt>; 1]>,
|
||||||
|
token_span: rustc_span::Span,
|
||||||
|
) -> NamedParseResult {
|
||||||
|
let nts = bb_items
|
||||||
|
.iter()
|
||||||
|
.map(|item| match item.top_elts.get_tt(item.idx) {
|
||||||
|
TokenTree::MetaVarDecl(_, bind, Some(kind)) => {
|
||||||
|
format!("{} ('{}')", kind, bind)
|
||||||
|
}
|
||||||
|
_ => panic!(),
|
||||||
|
})
|
||||||
|
.collect::<Vec<String>>()
|
||||||
|
.join(" or ");
|
||||||
|
|
||||||
|
Error(
|
||||||
|
token_span,
|
||||||
|
format!(
|
||||||
|
"local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}",
|
||||||
|
match next_items.len() {
|
||||||
|
0 => format!("built-in NTs {}.", nts),
|
||||||
|
1 => format!("built-in NTs {} or 1 other option.", nts),
|
||||||
|
n => format!("built-in NTs {} or {} other options.", nts, n),
|
||||||
|
}
|
||||||
|
),
|
||||||
|
)
|
||||||
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user