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

Add support for edition 2021. #4618

Merged
merged 7 commits into from
Jan 2, 2021
Merged

Conversation

m-ou-se
Copy link
Member

@m-ou-se m-ou-se commented Jan 1, 2021

This adds initial support for Rust 2021, by making it behave the same as Rust 2018. It simply changes == Edition2018 to >= Edition2018. (And adds a PartialOrd implementation to Edition to make that possible.)

@calebcartwright
Copy link
Member

Thanks for this, we've triggered an early publish of the rustc-ap* crates so v697 is now available, and we should be able to proceed a bit earlier than Tue

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 1, 2021

Updated.

This now fails on a change in how rustfmt formats macro arguments:

-macro foo($type_name: ident, $docs: expr) {
+macro foo($type_name:ident, $docs:expr) {

Trying to find out which rustc change caused this.

Edit: This changed between rustc-ap 693 and 694.

Edit 2: git bisect points at rust-lang/rust@31d72c2 of rust-lang/rust#78837.

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 1, 2021

Looks like this is a bug that is now fixed by that change.

Before that change, format_snippet inside MacroBranch::rewrite would return None for that test case. After that change, it returns Some(..) with the newly formatted macro definition with the two spaces removed.

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 1, 2021

Ah, the problem was that rustfmt skipped formatting of the entire macro definition because of #[doc=$docs] inside the body, which was solved by that change in rustc_parse. See rust-lang/rust#78837 (comment)

I'll update the expected test output, as this seems simply a bug that is now fixed.

@m-ou-se m-ou-se marked this pull request as ready for review January 1, 2021 23:26
Copy link
Member

@calebcartwright calebcartwright left a comment

Choose a reason for hiding this comment

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

Changes LGTM, thank you! Would you mind adding a test that has the Edition set to 2021?

Something as simple as adding a single file (perhaps tests/target/imports_2021_edition.rs) with a snippet like the one below would suffice

// rustfmt-edition: 2021

use ::foo::Bar;

@m-ou-se
Copy link
Member Author

m-ou-se commented Jan 2, 2021

Done!

@@ -0,0 +1,3 @@
// rustfmt-edition: 2021

use ::happy::new::year;
Copy link
Member

Choose a reason for hiding this comment

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

😆 love it

@calebcartwright calebcartwright merged commit 761adad into rust-lang:master Jan 2, 2021
@m-ou-se m-ou-se deleted the 2021 branch January 2, 2021 11:16
calebcartwright pushed a commit that referenced this pull request Jun 9, 2021
This was added to Configurations.md in #4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
calebcartwright pushed a commit to calebcartwright/rustfmt that referenced this pull request Jun 10, 2021
This was added to Configurations.md in rust-lang#4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
calebcartwright pushed a commit to calebcartwright/rustfmt that referenced this pull request Jun 10, 2021
This was added to Configurations.md in rust-lang#4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
calebcartwright pushed a commit to calebcartwright/rustfmt that referenced this pull request Jul 26, 2021
This was added to Configurations.md in rust-lang#4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
calebcartwright pushed a commit that referenced this pull request Jul 26, 2021
This was added to Configurations.md in #4618, but the option wasn't
actually made available. This should let people who are using Rust 2021
on nightly rustc run `cargo fmt` again.
@karyon
Copy link
Contributor

karyon commented Oct 26, 2021

Backported in #4623

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

Successfully merging this pull request may close these issues.

3 participants