Move a parse_tt error case into a separate function.

This commit is contained in:
Nicholas Nethercote 2022-03-09 14:51:31 +11:00
parent 235a87fbd3
commit 95d13fa37d

View File

@ -762,10 +762,7 @@ pub(super) fn parse_tt(
Err(mut err) => {
err.span_label(
span,
format!(
"while parsing argument for this `{}` macro fragment",
kind
),
format!("while parsing argument for this `{kind}` macro fragment"),
)
.emit();
return ErrorReported;
@ -784,6 +781,25 @@ pub(super) fn parse_tt(
(_, _) => {
// We need to call the black-box parser to get some nonterminal, but something is
// wrong.
return bb_items_ambiguity_error(
macro_name,
next_items,
bb_items,
parser.token.span,
);
}
}
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) {
@ -795,8 +811,8 @@ pub(super) fn parse_tt(
.collect::<Vec<String>>()
.join(" or ");
return Error(
parser.token.span,
Error(
token_span,
format!(
"local ambiguity when calling macro `{macro_name}`: multiple parsing options: {}",
match next_items.len() {
@ -805,10 +821,5 @@ pub(super) fn parse_tt(
n => format!("built-in NTs {} or {} other options.", nts, n),
}
),
);
}
}
assert!(!cur_items.is_empty());
}
)
}