Skip to content

Commit c5bccfd

Browse files
committed
Extra panic cases.
Just some extra sanity checking, making explicit some values not possible in code working with token trees.
1 parent ee08666 commit c5bccfd

File tree

2 files changed

+14
-1
lines changed

2 files changed

+14
-1
lines changed

compiler/rustc_ast/src/attr/mod.rs

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -309,7 +309,8 @@ impl MetaItem {
309309
I: Iterator<Item = &'a TokenTree>,
310310
{
311311
// FIXME: Share code with `parse_path`.
312-
let path = match tokens.next().map(|tt| TokenTree::uninterpolate(tt)).as_deref() {
312+
let tt = tokens.next().map(|tt| TokenTree::uninterpolate(tt));
313+
let path = match tt.as_deref() {
313314
Some(&TokenTree::Token(
314315
Token { kind: ref kind @ (token::Ident(..) | token::PathSep), span },
315316
_,
@@ -350,6 +351,12 @@ impl MetaItem {
350351
token::Nonterminal::NtPath(path) => (**path).clone(),
351352
_ => return None,
352353
},
354+
Some(TokenTree::Token(
355+
Token { kind: token::OpenDelim(_) | token::CloseDelim(_), .. },
356+
_,
357+
)) => {
358+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tt);
359+
}
353360
_ => return None,
354361
};
355362
let list_closing_paren_pos = tokens.peek().map(|tt| tt.span().hi());

compiler/rustc_expand/src/config.rs

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,12 @@ impl<'a> StripUnconfigured<'a> {
213213
) => {
214214
panic!("Nonterminal should have been flattened: {:?}", tree);
215215
}
216+
AttrTokenTree::Token(
217+
Token { kind: TokenKind::OpenDelim(_) | TokenKind::CloseDelim(_), .. },
218+
_,
219+
) => {
220+
panic!("Should be `AttrTokenTree::Delimited`, not delim tokens: {:?}", tree);
221+
}
216222
AttrTokenTree::Token(token, spacing) => {
217223
Some(AttrTokenTree::Token(token, spacing)).into_iter()
218224
}

0 commit comments

Comments
 (0)