diff options
| author | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-28 08:55:59 +1100 |
|---|---|---|
| committer | Nicholas Nethercote <n.nethercote@gmail.com> | 2022-03-28 10:45:24 +1100 |
| commit | 996759434610a151c71476ab85305bfcf2d6d5e7 (patch) | |
| tree | 70c79f9cec5673a5bb5e7cd434c210aea3b0da31 | |
| parent | 8a0c55046c7092d9e019dad03729e8d32e38df72 (diff) | |
| download | rust-996759434610a151c71476ab85305bfcf2d6d5e7.tar.gz rust-996759434610a151c71476ab85305bfcf2d6d5e7.zip | |
Ignore doc comments in a declarative macro matcher.
Fixes #95267. Reverts to the old behaviour before #95159 introduced a regression.
| -rw-r--r-- | compiler/rustc_expand/src/mbe/macro_parser.rs | 15 | ||||
| -rw-r--r-- | src/test/ui/macros/issue-95267.rs | 13 |
2 files changed, 21 insertions, 7 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs index 5e97fc90320..0417bea3594 100644 --- a/compiler/rustc_expand/src/mbe/macro_parser.rs +++ b/compiler/rustc_expand/src/mbe/macro_parser.rs @@ -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); } diff --git a/src/test/ui/macros/issue-95267.rs b/src/test/ui/macros/issue-95267.rs new file mode 100644 index 00000000000..4d59c7ea5e9 --- /dev/null +++ b/src/test/ui/macros/issue-95267.rs @@ -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!(); +} |
