Skip to content

Commit 9967594

Browse files
committed
Ignore doc comments in a declarative macro matcher.
Fixes rust-lang#95267. Reverts to the old behaviour before rust-lang#95159 introduced a regression.
1 parent 8a0c550 commit 9967594

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

compiler/rustc_expand/src/mbe/macro_parser.rs

+8-7
Original file line numberDiff line numberDiff line change
@@ -519,13 +519,14 @@ impl<'tt> TtParser<'tt> {
519519
}
520520

521521
TokenTree::Token(t) => {
522-
// Doc comments cannot appear in a matcher.
523-
debug_assert!(!matches!(t, Token { kind: DocComment(..), .. }));
524-
525-
// If the token matches, we can just advance the parser. Otherwise, this
526-
// match hash failed, there is nothing to do, and hopefully another item in
527-
// `cur_items` will match.
528-
if token_name_eq(&t, token) {
522+
// If it's a doc comment, we just ignore it and move on to the next tt in
523+
// the matcher. If the token matches, we can just advance the parser.
524+
// Otherwise, this match has failed, there is nothing to do, and hopefully
525+
// another item in `cur_items` will match.
526+
if matches!(t, Token { kind: DocComment(..), .. }) {
527+
item.idx += 1;
528+
self.cur_items.push(item);
529+
} else if token_name_eq(&t, token) {
529530
item.idx += 1;
530531
self.next_items.push(item);
531532
}

src/test/ui/macros/issue-95267.rs

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// check-pass
2+
3+
// This is a valid macro. Commit 4 in #95159 broke things such that it failed
4+
// with a "missing tokens in macro arguments" error, as reported in #95267.
5+
macro_rules! f {
6+
(
7+
/// ab
8+
) => {};
9+
}
10+
11+
fn main() {
12+
f!();
13+
}

0 commit comments

Comments
 (0)