Skip to content

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

Merged
merged 2 commits into from
May 25, 2016

Conversation

LeoTestard
Copy link
Contributor

This avoid duplicate errors for things like invalid fragment specifiers, or
parsing errors for ambiguous macros.

@rust-highfive
Copy link
Contributor

r? @nrc

(rust_highfive has picked a reviewer for you, use r? to override)

@oli-obk
Copy link
Contributor

oli-obk commented May 18, 2016

Can you add a compile-fail test for this?

@sanxiyn
Copy link
Member

sanxiyn commented May 18, 2016

See #29231.

@LeoTestard LeoTestard force-pushed the macro-rules-invalid-lhs branch from 86fc91e to b00a85d Compare May 18, 2016 16:29
@LeoTestard
Copy link
Contributor Author

Added two tests, also made sure that the help message indicating which fragment specifiers are valid is still emitted. This required to make OnFail able to span help messages.

@LeoTestard LeoTestard force-pushed the macro-rules-invalid-lhs branch 2 times, most recently from 49fcbcb to ab351a1 Compare May 19, 2016 00:19
@nrc
Copy link
Member

nrc commented May 19, 2016

r? @pnkfelix

@rust-highfive rust-highfive assigned pnkfelix and unassigned nrc May 19, 2016
@@ -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);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lhs should be tt?

Copy link
Contributor Author

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

@LeoTestard LeoTestard force-pushed the macro-rules-invalid-lhs branch 2 times, most recently from ccabeab to 40ddcce Compare May 19, 2016 10:10
&TokenTree::Delimited(_, ref tts) => {
check_matcher(cx, &tts.tts);
},
tt @ &TokenTree::Sequence(..) => {
Copy link
Member

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 )

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

:(

Copy link
Member

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)

@pnkfelix
Copy link
Member

r=me once above comments are addressed

@LeoTestard LeoTestard force-pushed the macro-rules-invalid-lhs branch from 40ddcce to 0169dca Compare May 23, 2016 09:59
@LeoTestard
Copy link
Contributor Author

@pnkfelix Fixed the test to include the help message.

@pnkfelix
Copy link
Member

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

@LeoTestard
Copy link
Contributor Author

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.
@LeoTestard LeoTestard force-pushed the macro-rules-invalid-lhs branch from 0169dca to 7d52144 Compare May 24, 2016 09:21
@LeoTestard
Copy link
Contributor Author

r? @pnkfelix

@pnkfelix
Copy link
Member

@bors r+

@bors
Copy link
Collaborator

bors commented May 24, 2016

📌 Commit 7d52144 has been approved by pnkfelix

@bors
Copy link
Collaborator

bors commented May 25, 2016

⌛ Testing commit 7d52144 with merge da66f2f...

bors added a commit that referenced this pull request May 25, 2016
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.
@bors bors merged commit 7d52144 into rust-lang:master May 25, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants