-
Notifications
You must be signed in to change notification settings - Fork 12.9k
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
Macro invocations bypass new keyword identifier checks #53686
Comments
So there's an unresolved question in #50412 about cc @scottmcm, @nikomatsakis, and @est31. |
Also cc @rust-lang/lang. |
Per #52602 (comment) I've nominated this and marked as p-high to ensure we can get some eyes on this; I've also added T-compiler to hopefully assign someone who can do the legwork once lang arrives at a decision (I believe it's not quite clear what we want here). |
@Centril I disagree in the general case, because IMO you should have to use |
@eddyb hmm; for I think we should try to be consistent in what we do, so if we say ixnay on However, a point for consideration is that |
@Centril Won't |
@eddyb I mean, that's what the choice before us is. We can make
There's arguments in favor of and against each choice here. 🤔 |
|
If you're switching to the Rust 2018 edition, I'd argue |
Sounds like there is a decision that needs to be made here, given the options laid out by @Centril Tagging with T-lang and adding I-needsdecision. (Also, once a decision is made, we also need to assign the ticket to someone to actually implement that decision...) |
I am fine with having The more important problem seems to be building up the machinery to make this transition happen "pre-macro-expansion". Seems doable, though, but it requires some special-case handling presumably. |
I think we should:
|
@rfcbot fcp merge The problem here is that we permit some keywords (but not all) to be used as macros. Specifically, (I believe) we permit only the new 2018 keywords (e.g., To correct this inconsistency, I proposed that we do the following:
|
Team member @nikomatsakis has proposed to merge this. The next step is review by the rest of the tagged teams:
Concerns:
Once a majority of reviewers approve (and none object), this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up! See this document for info about what commands tagged team members can give me. |
I wanted to point out that what Niko proposes is exactly how editions were designed to work: if an API is using a new keyword, it gets swapped out for the |
@rfcbot concern
|
It's worth noting that Python also had a builtin zero-configuration migration tool that had no trouble with |
We discussed your comment in the @rust-lang/lang meeting today. As you pointed out, there are basically two reasons that people might want to use
Older code is not an issue: the migration lints are not on by default, and anyway, they are lints. Such code continues to work as it ever did. In newer code, people could of course opt to continue using Rust 2015, though I would hope they don't. Otherwise, they can use This trade-off seems perfectly acceptable to me! One purpose of the edition, after all, is to allow us to "consolidate" idiom shifts -- such as the shift from Basically, in moving to merge, our judgement was that uses of In any case, we are operating under definite time pressure here. Normally we would wait for the formal objection to be cleared, but since we're trying to get this settled for the upcoming Release Candidate, and believe the objection has a reasonable response, we are going to go ahead and make a PR. But please, if you feel the objection is not sufficiently dealt with, speak up! |
@rfcbot resolve |
Can someone assign themselves to this issue? I'm not sure exactly what's involved in making the necessary changes here, so it's hard to estimate the difficulty/scope of this task. |
Looks like this was implemented recently by @mark-i-m ( |
Is anyone working on this issue? I had thought to start on it today but didn't get to it |
My understanding is that, today, macro invocations are actually still present in the AST. I wonder if we might do this in a different way-- basically by walking the AST post expansion and looking for cases that will become a problem? |
Ah, this is interesting: this might be a case where the "cross-crate edition hygiene" becomes relevant in practice. In particular, if I use a macro from another crate that uses |
Well, "wait and see" still applies, I suppose |
If that is true, I can't figure out where from some brief reading of the code :) |
Hmm, I see that the existing keyword lint is registered as a "pre-expansion" lint -- but perhaps some expansion happens before? It's certainly true that this example gets no warnings today. |
OK, I think I found the problem. Once I verify I am correct, I'm going to open a minimal PR first and file a bug for a more proper fix. (I think the bug is more in the visitor infrastructure than anything else.) |
OK, spoke too soon, but I do actually have it fixed now. 😛 Now trying to figure out if the first fix that I did is truly needed or not... |
…r=alexcrichton warn about keywords in macro invocations Fixes #53686 r? @alexcrichton
This code currently compiles on nightly:
.. with no warnings, but it should get a warning about the macro invocation!
cc @zackmdavis, do you know if there's a good location we can run lints before macro expansion? I think the bug here is that the macro is fully expanded by the time we hit the lint passes, so it's not even present in the AST.
The text was updated successfully, but these errors were encountered: