-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Implement edition-gated keywords #49610
Comments
An alternate fix is to have a second flag on |
Actually, not doing |
Ah, |
Why do |
Because I picked the two keywords I knew we definitely wanted 😄 (most of the others are under discussion or otherwise iffy). I wasn't aware we were fine with them as contextual keywords -- I thought we wanted to epochify anything that we may need as a keyword in the next epoch. Personally I'd rather add things as full keywords. But thinking about it I guess it would be nice if Rust 2015 got async/await as well. However, AFAICT await will have to be a real keyword? Or it will be prone to the same issue we have with idk 😄 |
Because I have preexisting modules named |
|
@nikomatsakis thoughts on what we should be doing here? As mentioned in Gitter, we can do this for cc @Centril |
Yes, this ^. All the way. I think we should make switching to Rust 2018 as enticing as possible, and reduce technical debt if we can. So I'm 👍 for no On On On |
(I intentionally didn't think too hard about syntax. |
@rpjohnst what about await? Are either of these in a situation where we want a non-contextual keyword? |
The proposal I wrote doesn't use the I think @withoutboats has thought a lot more about the syntax of async/await. |
Tagging this as A-rust-2018-preview. The main work remaining here, afaik, is to issue a lint when people use identifiers that will become keywords in the future. I've been debating how to implement that. I can see three basic approaches so far:
Modifying the parser would be harder to tie in with a lint, in that we lose the "scope" information we typically use to decide if the lint is enabled, but we could say that you have to put the migration lint at the root of the crate for it to work, and I'd be ok with that. The first two seem like they might be easier though. Have to find the right time to do it. We might be able to leverage the existing folders etc to visit every keyword, though, which is very nice. If we do it on the AST, I guess we might be able to intercept macro-related things, but I we actually don't have to do that, since AST matching (e.g., (Due in part to our behavior in #49520, which I was concerned about, but now I think I see why @petrochenkov preferred it.) cc @petrochenkov @Manishearth — I know both of you have put some thought into this, would appreciate your feedback. |
A tricky bit is handling keywords in macro definitions and invocations, but aside from that i think walking the tree is fine |
In what way is that tricky, say more =) I guess the idea is if we use a macro to parse something as an expression and then drop it on the floor? e.g., macro_rules! validate_expr {
($t:expr) => { }
}
macro_rules! gen_expr {
() => { validate_expr! { { let try = 22; } }
} Now (Though if we used the span of the stuff being parsed to decide the edition, that example would probably just work...) |
(Note: in discussion today, we decided this wasn't a preview blocker per se, though it is an edition blocker.) |
@nikomatsakis This visiting would include right sides of macro definitions which are possibly never expanded in the current crate, but will start generating errors in other crates once the edition of this crate is bumped. There can be false positives in corner cases, e.g. left sides of nested macros defined inside right side of a macro. Regarding the |
FWIW, |
Does anyone have any idea what work remains to be done here? We are now linting for the use of 2018 keywords in Rust 2015, for example, at least afaik. Based on the code I see four keywords, and all of them appear to have at least rudimentary tests:
So maybe we can close this? |
Yes I think we can close this; I filed #54774 for improved diagnostics, but that is tracked separately. |
We want to reserve a bunch of keywords in the 2018 edition. There's a full list of potential keywords, but for now I'll probably just reserve async, await, and catch.
EDIT: Here's my preliminary review of potential keywords and stuff: https://hackmd.io/lu7wxNbRTuO3C0NITUum6Q?both# // @Centril
For edition hygiene reasons this will be done entirely at the lexer level. Keywords in Rust are all lexed as identifiers, however you can have "raw identifiers" which let you create idents treated explicitly as idents. We overload this, so that if the lexer comes across the identifier "async" on Rust 2015, it lexes it as if it were
r#async
. We may want to fix it up in the pretty printer as well.The text was updated successfully, but these errors were encountered: