about summary refs log tree commit diff
path: root/compiler/rustc_expand/src
diff options
context:
space:
mode:
authorbohan <bohan-zhang@foxmail.com>2023-06-06 23:11:08 +0800
committerbohan <bohan-zhang@foxmail.com>2023-06-06 23:11:08 +0800
commitc927743b7b7bd382836dcce2d1140a7e829dc3d0 (patch)
treec23fed95e63c567f62b5a5551aba4102e0647e41 /compiler/rustc_expand/src
parentfd9bf594366e73efb1a26a023e0b4de8eff82b94 (diff)
downloadrust-c927743b7b7bd382836dcce2d1140a7e829dc3d0.tar.gz
rust-c927743b7b7bd382836dcce2d1140a7e829dc3d0.zip
fix(expand): prevent infinity loop in macro containing only "///"
Diffstat (limited to 'compiler/rustc_expand/src')
-rw-r--r--compiler/rustc_expand/src/mbe/macro_parser.rs1
-rw-r--r--compiler/rustc_expand/src/mbe/macro_rules.rs1
2 files changed, 2 insertions, 0 deletions
diff --git a/compiler/rustc_expand/src/mbe/macro_parser.rs b/compiler/rustc_expand/src/mbe/macro_parser.rs
index 1c222fb4a89..f0e67cfd50e 100644
--- a/compiler/rustc_expand/src/mbe/macro_parser.rs
+++ b/compiler/rustc_expand/src/mbe/macro_parser.rs
@@ -249,6 +249,7 @@ pub(super) fn compute_locs(matcher: &[TokenTree]) -> Vec<MatcherLoc> {
 }
 
 /// A single matcher position, representing the state of matching.
+#[derive(Debug)]
 struct MatcherPos {
     /// The index into `TtParser::locs`, which represents the "dot".
     idx: usize,
diff --git a/compiler/rustc_expand/src/mbe/macro_rules.rs b/compiler/rustc_expand/src/mbe/macro_rules.rs
index e4c65a2049b..576d636d489 100644
--- a/compiler/rustc_expand/src/mbe/macro_rules.rs
+++ b/compiler/rustc_expand/src/mbe/macro_rules.rs
@@ -647,6 +647,7 @@ fn check_lhs_no_empty_seq(sess: &ParseSess, tts: &[mbe::TokenTree]) -> bool {
                 if seq.separator.is_none()
                     && seq.tts.iter().all(|seq_tt| match seq_tt {
                         TokenTree::MetaVarDecl(_, _, Some(NonterminalKind::Vis)) => true,
+                        TokenTree::Token(t) => matches!(t, Token { kind: DocComment(..), .. }),
                         TokenTree::Sequence(_, sub_seq) => {
                             sub_seq.kleene.op == mbe::KleeneOp::ZeroOrMore
                                 || sub_seq.kleene.op == mbe::KleeneOp::ZeroOrOne