Skip to content
/ rust Public
forked from rust-lang/rust

Commit 1c8b741

Browse files
authored
Rollup merge of rust-lang#95390 - nnethercote:allow-doc-comments-in-macros, r=petrochenkov
Ignore doc comments in a declarative macro matcher. Fixes rust-lang#95267. Reverts to the old behaviour before rust-lang#95159 introduced a regression. r? `@petrochenkov`
2 parents 2f5e944 + 9967594 commit 1c8b741

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
@@ -516,13 +516,14 @@ impl<'tt> TtParser<'tt> {
516516
}
517517

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

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)