fix(expand): prevent infinity loop in macro containing only "///"
This commit is contained in:
parent
fd9bf59436
commit
c927743b7b
5 changed files with 95 additions and 0 deletions
|
@ -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,
|
||||
|
|
|
@ -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
|
||||
|
|
36
tests/ui/macros/issue-112342-1.rs
Normal file
36
tests/ui/macros/issue-112342-1.rs
Normal 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() {}
|
29
tests/ui/macros/issue-112342-1.stderr
Normal file
29
tests/ui/macros/issue-112342-1.stderr
Normal 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
|
||||
|
28
tests/ui/macros/issue-112342-2.rs
Normal file
28
tests/ui/macros/issue-112342-2.rs
Normal 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() {}
|
Loading…
Add table
Add a link
Reference in a new issue