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

RFC: 2021 Edition #3085

Merged
merged 11 commits into from May 29, 2021
Merged

Conversation

nikomatsakis
Copy link
Contributor

@nikomatsakis nikomatsakis commented Feb 19, 2021

This RFC describes the plan for the 2021 Edition. It supercedes RFC 2052. The proposed 2021 Edition is intentionally more limited than the 2018 Edition. Rather than representing a major marketing push, the 2021 Edition represents a chance for us to introduce changes that would otherwise be backwards incompatible. It is meant to be marketed in many ways as something closer to "just another release".

Rendered

Key points include:

  • Editions are used to introduce changes into the language that would otherwise have the potential to break existing code, such as the introduction of a new keyword.
  • Editions are never allowed to split the ecosystem. We only permit changes that still allow crates in different editions to interoperate.
  • Editions are named after the year in which they occur (e.g., Rust 2015, Rust 2018, Rust 2021).
  • When we release a new edition, we also release tooling to automate the migration of crates. Some manual work may be required but that should be the rare case.
  • The nightly toolchain offers "preview" access to upcoming editions, so that we can land work that targets future editions at any time.
  • We maintain an Edition Migration Guide that offers guidance on how to migrate to the next edition.
  • Whenever possible, new features should be made to work across all editions.

This RFC is meant to establish the high-level purpose of an edition and to describe how the RFC feels to end users. It intentionally avoids detailed policy discussions, which are deferred to the appropriate subteams (compiler, lang, dev-tools, etc) to figure out.

Thanks

Thanks to @Mark-Simulacrum, @rylev, @ehuss and others for feedback.

Thanks to simulacrum, rylev, ehuss, and others for feedback.
@Mark-Simulacrum Mark-Simulacrum added the T-core Relevant to the core team, which will review and decide on the RFC. label Feb 19, 2021
@trevyn trevyn mentioned this pull request Feb 19, 2021
2 tasks
@mark-i-m
Copy link
Member

I've generally been against having an edition 2021 so far, but this assuages my main concerns.

text/0000-edition-2021.md Outdated Show resolved Hide resolved
Copy link

@Wodann Wodann left a comment

Choose a reason for hiding this comment

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

A huge step forward in terms of the previous proposal, imo. My main concerns were resolved, and I like this new lean approach for editions. Great work! 👍

text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
@nikomatsakis
Copy link
Contributor Author

(Thanks all for the comments! I'm a bit busy today but I'll go through and incorporate feedback later this week, hopefully tomorrow.)

text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
nikomatsakis and others added 2 commits March 4, 2021 19:07
Co-authored-by: Ibraheem Ahmed <ibrah1440@gmail.com>
Co-authored-by: bstrie <865233+bstrie@users.noreply.github.com>
Copy link

@Kixunil Kixunil left a comment

Choose a reason for hiding this comment

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

Overall I like this approach. I have some concerns and I hope they are not hard to fix.

text/0000-edition-2021.md Show resolved Hide resolved
Some examples of changes the editions can make:

* Introducing a new keyword, as with `async-await`.
* This change comes with automated tooling that rewrites identifiers using that keyword to use `r#` form.
Copy link

Choose a reason for hiding this comment

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

I don't think this is great. Sure the code works but it's ugly. Yes, the proper fix requires developer interaction but it will require it anyway unless the developer is fine with ugly marker.

Having an option to replace it with some other specific identifier would be much nicer. I realize that it may need to be different in different contexts.

If this is too complicated (but maybe the code can be reused in a general-purpose refactoring tool?), then at least a message saying "Keyword foo was replaced in 5 scopes" would be helpful reminder.

Copy link

Choose a reason for hiding this comment

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

it would be nice if a preference list could be given, e.g. I've seen the pattern that variables which wanted to use internal keywords as a name, were given the name {name}_ (e.g. with an appended underscore at the end) instead of r#{name} (which I've also seen, but less often).

Copy link

Choose a reason for hiding this comment

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

I meant having the option configurable. E.g. if you try to apply cargo fix it will fail "the code uses new keywords as identifiers" message and then the user would supply either:

  • --raw-identifiers
  • --replace-ident async=asynchronous --replace-ident await=awaiting

This would probably cover all major use cases. The only thing it can't do is replacing based on context (maybe the different replacement is better in different functions), but this seems like an acceptable limitation to me.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

That does sound like a nice option, but I would prefer not to add it as required by this RFC. We've added keywords in the past using the simpler system and it did seem adequate; one can also do a search-and-replace with ripgrep readily enough as well.

Copy link

Choose a reason for hiding this comment

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

My primary concern is people running cargo fix, they'll see it "works" and don't notice changed identifier. So I believe at least warning should be strongly encouraged.

Copy link
Member

Choose a reason for hiding this comment

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

Hm. I think one of our key goals is that editions can be migrated to piecemeal, and ultimately in rarely read code, this is fine; asking users to add an allow for working code is not too typical in Rust. Regardless, I think this could be added without changes to this rfc, per usual lang team processes (as an extension to the existing lints around identifier naming); I am not inclined to specify a particular behavior here.

Copy link

Choose a reason for hiding this comment

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

I meant one-time warning emitted from cargo fix. (Something like "The identifier x, which is now a keyword, was converted to raw form 5 times, you may wish to rename it to something else.")

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 want to prescribe such specifics in this RFC, but I think it may make sense for migrations to have the ability to give some kind of report - I know the closure changes for example could tell you how much the closures in your code changed size, etc. which might be difficult otherwise. I'd say this feels like something you could file an issue for on rust-lang/rust, though, just like any other diagnostic improvement, and we can discuss there.

text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
* The expectation is that `cargo fix` should be able to fix the majority of crates out there, but it is not required that the tooling is able to handle every case. As long as code does not occur frequently in the wild, it is acceptable for the automated suggestions to be inapplicable to edge cases. The metrics section in this RFC includes some guidelines for how to measure this.
* **Upgrade:** Edit your cargo.toml to include `edition = "2021"` instead of the older edition.
* The code should still build, but it may be necessary to make some fixes or other changes.
* **Cleanup:** After upgrading, you should run `cargo fix` again. This second step will apply any remaining changes that are only possible in the new edition.
Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure if it is worth pointing out, but I think the intent here is to use the --edition-idioms flag at this step.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

This is something that @Manishearth and I have been discussing a bit on Zulip. I am not entirely convinced whether 'edition idioms' as a distinct category makes sense, or whether those lints are simply "style lints" that trigger on Rust 2021 code.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It'd be good to discuss this a bit more on Zulip, I'd like to go over some of the examples of idiom lints I guess and think about it.

text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
text/0000-edition-2021.md Outdated Show resolved Hide resolved
nikomatsakis and others added 2 commits April 12, 2021 18:25
Co-authored-by: Eric Huss <eric@huss.org>
Co-authored-by: Eric Huss <eric@huss.org>
@nikomatsakis nikomatsakis added this to Public Test Blockers in 2021 Edition Blockers Apr 26, 2021
@Mark-Simulacrum
Copy link
Member

Overall this looks good to me, so let's move to merge. I just left some comments in response to some of the unresolved questions, but I think they are not blockers to merging, and box checking is likely to take some time.

@rustbot fcp merge

@Mark-Simulacrum
Copy link
Member

Er and I did the same thing Niko was telling me about just today...

@rfcbot fcp merge

@rfcbot
Copy link
Collaborator

rfcbot commented May 6, 2021

Team member @Mark-Simulacrum has proposed to merge this. The next step is review by the rest of the tagged team members:

No concerns currently listed.

Once a majority of reviewers approve (and at most 2 approvals are outstanding), 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.

@rfcbot rfcbot added proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. labels May 6, 2021
@rfcbot rfcbot added final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. and removed proposed-final-comment-period Currently awaiting signoff of all team members in order to enter the final comment period. labels May 18, 2021
@rfcbot
Copy link
Collaborator

rfcbot commented May 18, 2021

🔔 This is now entering its final comment period, as per the review above. 🔔

@rfcbot rfcbot added finished-final-comment-period The final comment period is finished for this RFC. and removed final-comment-period Will be merged/postponed/closed in ~10 calendar days unless new substational objections are raised. labels May 28, 2021
@rfcbot
Copy link
Collaborator

rfcbot commented May 28, 2021

The final comment period, with a disposition to merge, as per the review above, is now complete.

As the automated representative of the governance process, I would like to thank the author for their work and everyone else who contributed.

The RFC will be merged soon.

@Manishearth Manishearth merged commit 25c6d04 into rust-lang:master May 29, 2021
@m-ou-se m-ou-se moved this from Public Test Blockers to Completed items in 2021 Edition Blockers May 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
disposition-merge This RFC is in PFCP or FCP with a disposition to merge it. finished-final-comment-period The final comment period is finished for this RFC. T-core Relevant to the core team, which will review and decide on the RFC. to-announce
Projects
2021 Edition Blockers
  
Completed items
Development

Successfully merging this pull request may close these issues.

None yet