Extra panic cases.

Just some extra sanity checking, making explicit some values not
possible in code working with token trees -- we shouldn't be seeing
explicit delimiter tokens, because they should be represented as
`TokenTree::Delimited`.
This commit is contained in:
Nicholas Nethercote 2024-05-15 09:29:11 +10:00
parent bca5cd3a9d
commit 2e4d547d4a
2 changed files with 14 additions and 1 deletions

View File

@ -327,7 +327,8 @@ impl MetaItem {
I: Iterator<Item = &'a TokenTree>, I: Iterator<Item = &'a TokenTree>,
{ {
// FIXME: Share code with `parse_path`. // FIXME: Share code with `parse_path`.
let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() { let tt = tokens.next().map(|tt| TokenTree::uninterpolate(tt));
let path = match tt.as_deref() {
Some(&TokenTree::Token( Some(&TokenTree::Token(
Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span }, Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span },
_, _,
@ -368,6 +369,12 @@ impl MetaItem {
token::Nonterminal::NtPath(path) => (**path).clone(), token::Nonterminal::NtPath(path) => (**path).clone(),
_ => return None, _ => return None,
}, },
Some(TokenTree::Token(
Token { kind: token::OpenDelim(_) | token::CloseDelim(_), .. },
_,
)) => {
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tt);
}
_ => return None, _ => return None,
}; };
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi()); let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());

View File

@ -214,6 +214,12 @@ impl<'a> StripUnconfigured<'a> {
) => { ) => {
panic!("Nonterminal should have been flattened: {:?}", tree); panic!("Nonterminal should have been flattened: {:?}", tree);
} }
AttrTokenTree::Token(
Token { kind: TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_), .. },
_,
) => {
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tree);
}
AttrTokenTree::Token(token, spacing) => { AttrTokenTree::Token(token, spacing) => {
Some(AttrTokenTree::Token(token, spacing)).into_iter() Some(AttrTokenTree::Token(token, spacing)).into_iter()
} }