-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Make sure that macros that didn't pass LHS checking are not expanded. #33713
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
Conversation
r? @nrc (rust_highfive has picked a reviewer for you, use r? to override) |
Can you add a compile-fail test for this? |
See #29231. |
86fc91e
to
b00a85d
Compare
Added two tests, also made sure that the help message indicating which fragment specifiers are valid is still emitted. This required to make |
49fcbcb
to
ab351a1
Compare
r? @pnkfelix |
@@ -291,17 +291,16 @@ pub fn compile<'cx>(cx: &'cx mut ExtCtxt, | |||
let lhses = match **argument_map.get(&lhs_nm.name).unwrap() { | |||
MatchedSeq(ref s, _) => { | |||
s.iter().map(|m| match **m { | |||
MatchedNonterminal(NtTT(ref tt)) => (**tt).clone(), | |||
MatchedNonterminal(NtTT(ref tt)) => { | |||
valid &= check_lhs_nt_follows(cx, lhs); |
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.
lhs
should be 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.
Right, looks like I copy-pasted too fast...
ccabeab
to
40ddcce
Compare
&TokenTree::Delimited(_, ref tts) => { | ||
check_matcher(cx, &tts.tts); | ||
}, | ||
tt @ &TokenTree::Sequence(..) => { |
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.
I don't know if we have code formatting conventions for macro_rules but I think it looked better before (more uniform in terms of identifying the left and right hand sides of each rule )
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.
:(
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.
(To be clear I am not saying you must change if; I don't even care enough to look up whether we have established convention here)
r=me once above comments are addressed |
40ddcce
to
0169dca
Compare
@pnkfelix Fixed the test to include the help message. |
@LeoTestard Travis says you've put the expected error on the wrong line in your test (that, or you need to adjust the span you use in the error reporting) |
Actually the span is fine, the error was in the test. |
This avoids duplicate errors for things like invalid fragment specifiers, or parsing errors for ambiguous macros. Fixes rust-lang#29231.
0169dca
to
7d52144
Compare
r? @pnkfelix |
@bors r+ |
📌 Commit 7d52144 has been approved by |
⌛ Testing commit 7d52144 with merge da66f2f... |
Make sure that macros that didn't pass LHS checking are not expanded. This avoid duplicate errors for things like invalid fragment specifiers, or parsing errors for ambiguous macros.
This avoid duplicate errors for things like invalid fragment specifiers, or
parsing errors for ambiguous macros.