1
Fork 0

fix(expand): prevent infinity loop in macro containing only "///"

This commit is contained in:
bohan 2023-06-06 23:11:08 +08:00
parent fd9bf59436
commit c927743b7b
5 changed files with 95 additions and 0 deletions

View file

@ -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,

View file

@ -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

View file

@ -0,0 +1,36 @@
// same as #95267, ignore doc comment although it's a bug.
macro_rules! m1 {
(
$(
///
)*
//~^^^ERROR repetition matches empty token tree
) => {};
}
m1! {}
macro_rules! m2 {
(
$(
///
)+
//~^^^ERROR repetition matches empty token tree
) => {};
}
m2! {}
macro_rules! m3 {
(
$(
///
)?
//~^^^ERROR repetition matches empty token tree
) => {};
}
m3! {}
fn main() {}

View file

@ -0,0 +1,29 @@
error: repetition matches empty token tree
--> $DIR/issue-112342-1.rs:5:10
|
LL | $(
| __________^
LL | | ///
LL | | )*
| |_________^
error: repetition matches empty token tree
--> $DIR/issue-112342-1.rs:16:10
|
LL | $(
| __________^
LL | | ///
LL | | )+
| |_________^
error: repetition matches empty token tree
--> $DIR/issue-112342-1.rs:27:10
|
LL | $(
| __________^
LL | | ///
LL | | )?
| |_________^
error: aborting due to 3 previous errors

View file

@ -0,0 +1,28 @@
// check-pass
// same as #95267, ignore doc comment although it's a bug.
macro_rules! m1 {
(
$(
///
$expr: expr,
)*
) => {};
}
m1! {}
macro_rules! m2 {
(
$(
///
$expr: expr,
///
)*
) => {};
}
m2! {}
fn main() {}