Skip to content

Ignore doc comments in a declarative macro matcher. #95390

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 28, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 8 additions & 7 deletions compiler/rustc_expand/src/mbe/macro_parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -519,13 +519,14 @@ impl<'tt> TtParser<'tt> {
}

TokenTree::Token(t) => {
// Doc comments cannot appear in a matcher.
debug_assert!(!matches!(t, Token { kind: DocComment(..), .. }));

// If the token matches, we can just advance the parser. Otherwise, this
// match hash failed, there is nothing to do, and hopefully another item in
// `cur_items` will match.
if token_name_eq(&t, token) {
// If it's a doc comment, we just ignore it and move on to the next tt in
// the matcher. If the token matches, we can just advance the parser.
// Otherwise, this match has failed, there is nothing to do, and hopefully
// another item in `cur_items` will match.
if matches!(t, Token { kind: DocComment(..), .. }) {
item.idx += 1;
self.cur_items.push(item);
} else if token_name_eq(&t, token) {
item.idx += 1;
self.next_items.push(item);
}
Expand Down
13 changes: 13 additions & 0 deletions src/test/ui/macros/issue-95267.rs
Original file line number Diff line number Diff line change
@@ -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!();
}