Skip to content
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

macros sometimes allow expr followed by ident #44975

Open
durka opened this issue Oct 2, 2017 · 10 comments
Open

macros sometimes allow expr followed by ident #44975

durka opened this issue Oct 2, 2017 · 10 comments
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.

Comments

@durka
Copy link
Contributor

durka commented Oct 2, 2017

You can use a repetition to get around the future proofer.

macro_rules! bad {
    ($e:expr $i:ident) => {} //~ERROR
}

macro_rules! sneaky {
    ($($i:ident $e:expr)*) => {} // no error
}

fn main() {
    sneaky!(a b c d);
}

I feel that both of these should be accepted, or neither. BTW, I am using the equivalent of sneaky! in brainmunch (found this while preparing my RustFest talk).

Fixing this by disallowing both macros would require cratering.

cc @jseyfried @LeoTestard

@TimNN TimNN added A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) I-nominated T-lang Relevant to the language team, which will review and decide on the PR/issue. labels Oct 3, 2017
@aturon
Copy link
Member

aturon commented Oct 19, 2017

cc @pnkfelix

@nikomatsakis
Copy link
Contributor

The danger here is that contextual keywords become impossible. In particular, consider if we added await f as an expression, which would work with bad! today but fail tomorrow.

@joshtriplett
Copy link
Member

One possibility would be to leave this alone and fix it in macros 2.0. The other would be a crater run and evaluation for a fix.

@nikomatsakis
Copy link
Contributor

Some possible routes:

  • I don't think we should accept bad!, for the reasons given above.
  • We could leave this as is -- we have said in the past that when you break the forwards compatibility rules "in spirit" you may get broken.
  • Or, better really, we would do a fix and try to do a crater run.

@nikomatsakis
Copy link
Contributor

triage: P-medium

@rust-highfive rust-highfive added the P-medium Medium priority label Oct 19, 2017
@nikomatsakis
Copy link
Contributor

I feel like we should at least try the fix -- though it may be hard to ascertain the impact entirely.

@durka
Copy link
Contributor Author

durka commented Oct 25, 2017

@nikomatsakis do you have any idea how to fix it?

@XAMPPRocky XAMPPRocky added the C-enhancement Category: An issue proposing an enhancement or a PR with one. label Jan 22, 2018
@estebank
Copy link
Contributor

I'm afraid fixing this is going to be problematic, because even we are using this "feature" in rustc. I'll post a PR with the fix (including changing our mis-uses), but will expect there to be breakage. If that is the case after a crater run, should we still include the fix as a warning?

bors added a commit that referenced this issue Oct 26, 2018
Disallow incorrect unseparated repetition

Macro pattern `($a:expr, $b:expr)` is invalid, for good reason.
Correctly reject pattern `($($a:expr)*)`, as it is functionally the
same.

Fix #44975, fix #48220.
@durka
Copy link
Contributor Author

durka commented Oct 26, 2018 via email

@estebank
Copy link
Contributor

(callers too?)

@durka It'd be nice to do, but I'm tempted at leaving devs to deal with the fallout after changing the signature by following the errors they'll get then instead of trying to preempt them, as extending the diagnostic to the callers would be a bigger PR, I fear.

bors added a commit that referenced this issue Oct 26, 2018
Disallow incorrect unseparated repetition

Macro pattern `($a:expr, $b:expr)` is invalid, for good reason.
Correctly reject pattern `($($a:expr)*)`, as it is functionally the
same.

Fix #44975, fix #48220.
bors added a commit that referenced this issue Oct 29, 2018
Disallow incorrect unseparated repetition

Macro pattern `($a:expr, $b:expr)` is invalid, for good reason.
Correctly reject pattern `($($a:expr)*)`, as it is functionally the
same.

Fix #44975, fix #48220.
bors added a commit that referenced this issue Nov 22, 2018
Warn on incorrect unseparated repetition

Macro pattern `($a:expr $b:expr)` is invalid, for good reason.
Correctly reject pattern `($($a:expr)*)`, as it is functionally the
same.

Fix #44975, fix #48220.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-macros Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..) C-enhancement Category: An issue proposing an enhancement or a PR with one. P-medium Medium priority T-lang Relevant to the language team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants