1
Fork 0

Ignore doc comments in a declarative macro matcher.

Fixes #95267. Reverts to the old behaviour before #95159 introduced a
regression.
This commit is contained in:
Nicholas Nethercote 2022-03-28 08:55:59 +11:00
parent 8a0c55046c
commit 9967594346
2 changed files with 21 additions and 7 deletions

View file

@ -519,13 +519,14 @@ impl<'tt> TtParser<'tt> {
} }
TokenTree::Token(t) => { TokenTree::Token(t) => {
// Doc comments cannot appear in a matcher. // If it's a doc comment, we just ignore it and move on to the next tt in
debug_assert!(!matches!(t, Token { kind: DocComment(..), .. })); // the matcher. If the token matches, we can just advance the parser.
// Otherwise, this match has failed, there is nothing to do, and hopefully
// If the token matches, we can just advance the parser. Otherwise, this // another item in `cur_items` will match.
// match hash failed, there is nothing to do, and hopefully another item in if matches!(t, Token { kind: DocComment(..), .. }) {
// `cur_items` will match. item.idx += 1;
if token_name_eq(&t, token) { self.cur_items.push(item);
} else if token_name_eq(&t, token) {
item.idx += 1; item.idx += 1;
self.next_items.push(item); self.next_items.push(item);
} }

View file

@ -0,0 +1,13 @@
// check-pass
// This is a valid macro. Commit 4 in #95159 broke things such that it failed
// with a "missing tokens in macro arguments" error, as reported in #95267.
macro_rules! f {
(
/// ab
) => {};
}
fn main() {
f!();
}