-
Notifications
You must be signed in to change notification settings - Fork 13.2k
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
fix(expand): prevent infinity loop in macro containing only "///" #112345
Conversation
r? @eholk (rustbot has picked a reviewer for you, use r? to override) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me except two small nits, very good PR edit: see comment below
Hmm yeah so what is happening here is that the compiler attempts to try another repetition, infinitely many times. This would also happen for code like: macro_rules! foo {
($()*) => {};
}
foo!(); Similarly: macro_rules! foo {
($($(foo:tt)?)*) => {};
} But thankfully the compiler catches that before it gets into the matching code and errors with "repetition matches empty token tree". I think it would be best to instead edit |
nice solution! |
btw, what do you think emit warning such as "doc comment is Illegal syntax, it may throw error in future"? |
doing it like @est31 suggested is what I just wanted to suggest too, so that sounds great emitting a future compatibility warning for doc comments in matcher position doesn't sound too bad to me but is a separate issue that should be discussed with the language team. |
Already revised, thank you both for your help, I learned a lot |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
r=me if you add a test for ///
together with another ///
doc comment, as well as one test with ///
and $(foo:tt)?
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Some final nits. I promised approval before, but given you are learning I thought this would be useful to know.
f181264
to
f8175c9
Compare
@bors r=nilstrieb,est31 as per #112345 (comment) |
Rollup of 6 pull requests Successful merges: - rust-lang#112076 (Fall back to bidirectional normalizes-to if no subst-relate candidate in alias-relate goal) - rust-lang#112122 (Add `-Ztrait-solver=next-coherence`) - rust-lang#112251 (rustdoc: convert `if let Some()` that always matches to variable) - rust-lang#112345 (fix(expand): prevent infinity loop in macro containing only "///") - rust-lang#112359 (Respect `RUST_BACKTRACE` for delayed bugs) - rust-lang#112382 (download-rustc: Fix `x test core` on MacOS) r? `@ghost` `@rustbot` modify labels: rollup
Fixes #112342
Issue #112342 was caused by an infinity loop in
parse_tt_inner
, and the state of it is as follows:matcher
:[Sequence, Token(Doc), SequenceKleeneOpNoSep(op: ZeroOrMore), Eof]
loop:
Sequence
Token(Doc)
andmp.idx += 1
had been executedSequenceKleeneOpNoSep
and resetmp.idx
to1
Token(Doc)
againTo prevent the infinite loop, a check for whether it only contains
DocComment
incheck_lhs_no_empty_seq
had been added.