Skip to content

Commit b23f272

Browse files
committed
Make clear that TokenTree::Token shouldn't contain a delimiter.
1 parent af1d16e commit b23f272

File tree

2 files changed

+9
-2
lines changed

2 files changed

+9
-2
lines changed

compiler/rustc_ast/src/tokenstream.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,8 @@ use std::{fmt, iter};
4141
/// Nothing special happens to misnamed or misplaced `SubstNt`s.
4242
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable_Generic)]
4343
pub enum TokenTree {
44-
/// A single token.
44+
/// A single token. Should never be `OpenDelim` or `CloseDelim`, because
45+
/// delimiters are implicitly represented by `Delimited`.
4546
Token(Token, Spacing),
4647
/// A delimited sequence of token trees.
4748
Delimited(DelimSpan, Delimiter, TokenStream),

compiler/rustc_parse/src/parser/mod.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -290,7 +290,13 @@ impl TokenCursor {
290290
self.frame.tree_cursor.replace_prev_and_rewind(desugared);
291291
// Continue to get the first token of the desugared doc comment.
292292
}
293-
_ => return (token.clone(), spacing),
293+
_ => {
294+
debug_assert!(!matches!(
295+
token.kind,
296+
token::OpenDelim(_) | token::CloseDelim(_)
297+
));
298+
return (token.clone(), spacing);
299+
}
294300
},
295301
&TokenTree::Delimited(sp, delim, ref tts) => {
296302
// Set `open_delim` to true here because we deal with it immediately.

0 commit comments

Comments
 (0)