mirror of
https://github.com/rust-lang/rust.git
synced 2024-11-25 08:13:41 +00:00
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:
parent
bca5cd3a9d
commit
2e4d547d4a
@ -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());
|
||||||
|
@ -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()
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user