Skip to content

Implement edition-gated keywords #49610

Closed

Description

@Manishearth

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.

Activity

  1. self-assigned this
    on Apr 3, 2018
  2. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    An alternate fix is to have a second flag on Ident, which marks whether or not it's allowed to form a keyword. This has the additional benefit of being easier to work with for promoting contextual keywords to full keywords.

  3. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    Actually, not doing catch yet, it's contextual.

  4. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    Ah, catch is currently implemented in an unstable form as do catch. We can change this whenever we like so that it doesn't work for the 2015 epoch and in 2018 uses a non-contextual catch keyword.

  5. changed the title [-]Implement edition-gated identifiers[/-] [+]Implement edition-gated keywords[/+] on Apr 3, 2018
  6. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor
  7. cramertj commented on Apr 3, 2018

    @cramertj
    Member

    Why do async and await need to be non-contexutal keywords? AFAIK at least async could be added backwards-compatibly as a contextual keyword.

  8. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    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 catch (which causes do catch)? And if await is going to be a 2018-only keyword it seems like the entire feature should just be 2018-only, in which case, why not make async a full keyword.

    idk 😄

  9. cramertj commented on Apr 3, 2018

    @cramertj
    Member

    why not make async a full keyword

    Because I have preexisting modules named async 😛 lol

  10. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    r#async all the way 😛

  11. Manishearth commented on Apr 3, 2018

    @Manishearth
    MemberAuthor

    @nikomatsakis thoughts on what we should be doing here?

    As mentioned in Gitter, we can do this for dyn as well -- no dyn at all in 2015, and dyn becomes a full keyword in 2018. I kinda prefer that.

    cc @Centril

  12. Centril commented on Apr 3, 2018

    @Centril
    Contributor

    @Manishearth

    [..] we can do this for dyn as well -- no dyn at all in 2015, and dyn becomes a full keyword in 2018. I kinda prefer that.

    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 dyn in edition 2015.

    On async: @rpjohnst's pre-RFC has async { .. } blocks; and so this would conflict with struct async { .. } [..] async { .. } wherefore I think async needs to be a real keyword so that we can future proof things.

    On catch, the keyword reservation does not seem settled, but whatever we go with (try, catch, trap, .. ) it should be a real keyword for the same problem that async blocks would have.

    On await I have no idea.

  13. 13 remaining items

  14. nikomatsakis commented on May 23, 2018

    @nikomatsakis
    Contributor

    (Note: in discussion today, we decided this wasn't a preview blocker per se, though it is an edition blocker.)

  15. petrochenkov commented on May 23, 2018

    @petrochenkov
    Contributor

    @nikomatsakis
    I think we can visit all idents in AST as soon as NodeIds are assigned and it will be good enough.

    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.
    They would be visited as token streams because we don't know anything more about them. Left sides don't need to be checked as you've mentioned above.

    There can be false positives in corner cases, e.g. left sides of nested macros defined inside right side of a macro. Regarding the validate_expr example, I'm not even sure it would be a false positive - it certainly wouldn't hurt to rename try into something else in it, in case validate_expr stops dropping arguments.

  16. removed their assignment
    on Jun 7, 2018
  17. added
    C-enhancementCategory: An issue proposing an enhancement or a PR with one.
    T-langRelevant to the language team
    on Jun 29, 2018
  18. scottmcm commented on Jul 25, 2018

    @scottmcm
    Member

    FWIW, try is made an edition keyword by PR #52602.

  19. nikomatsakis commented on Oct 4, 2018

    @nikomatsakis
    Contributor

    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?

  20. Centril commented on Oct 4, 2018

    @Centril
    Contributor

    Yes I think we can close this; I filed #54774 for improved diagnostics, but that is tracked separately.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-edition-2018Area: The 2018 editionC-enhancementCategory: An issue proposing an enhancement or a PR with one.F-rust_2018_preview`#![feature(rust_2018_preview)]`T-langRelevant to the language teamWG-epochWorking group: Epoch (2018) management

    Type

    No type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions