From 3ec0c76b45fc6be61871b37a92ea4c281fab70b6 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 1 Jan 2021 17:00:40 +0100 Subject: [PATCH 1/7] Add support for edition 2021. --- Configurations.md | 2 +- src/config/options.rs | 11 +++++++++++ src/formatting/imports.rs | 2 +- 3 files changed, 13 insertions(+), 2 deletions(-) diff --git a/Configurations.md b/Configurations.md index 7130e80bfdc..415089596e0 100644 --- a/Configurations.md +++ b/Configurations.md @@ -569,7 +569,7 @@ fn main() { Specifies which edition is used by the parser. - **Default value**: `"2015"` -- **Possible values**: `"2015"`, `"2018"` +- **Possible values**: `"2015"`, `"2018"`, `"2021"` - **Stable**: Yes Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed diff --git a/src/config/options.rs b/src/config/options.rs index aea67749a45..af4df0e5c4f 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -343,6 +343,10 @@ pub enum Edition { #[doc_hint = "2018"] /// Edition 2018. Edition2018, + #[value = "2021"] + #[doc_hint = "2021"] + /// Edition 2021. + Edition2021, } impl Default for Edition { @@ -356,10 +360,17 @@ impl From for rustc_span::edition::Edition { match edition { Edition::Edition2015 => Self::Edition2015, Edition::Edition2018 => Self::Edition2018, + Edition::Edition2021 => Self::Edition2021, } } } +impl PartialOrd for Edition { + fn partial_cmp(&self, other: &Edition) -> Option { + rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()) + } +} + /// Controls how rustfmt should handle leading pipes on match arms. #[config_type] pub enum MatchArmLeadingPipe { diff --git a/src/formatting/imports.rs b/src/formatting/imports.rs index 72aff70987a..f9db42469a0 100644 --- a/src/formatting/imports.rs +++ b/src/formatting/imports.rs @@ -333,7 +333,7 @@ impl UseTree { }; let leading_modsep = - context.config.edition() == Edition::Edition2018 && a.prefix.is_global(); + context.config.edition() >= Edition::Edition2018 && a.prefix.is_global(); let mut modsep = leading_modsep; From 1320420e42425622fd8ce6e046d156975802d2c9 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 1 Jan 2021 17:00:52 +0100 Subject: [PATCH 2/7] Fixes for new rustc changes. --- src/formatting/closures.rs | 1 - src/formatting/items.rs | 2 +- src/formatting/macros.rs | 2 +- 3 files changed, 2 insertions(+), 3 deletions(-) diff --git a/src/formatting/closures.rs b/src/formatting/closures.rs index d7e54d8f633..635b670985c 100644 --- a/src/formatting/closures.rs +++ b/src/formatting/closures.rs @@ -199,7 +199,6 @@ fn rewrite_closure_with_block( id: ast::NodeId::root(), kind: ast::StmtKind::Expr(ptr::P(body.clone())), span: body.span, - tokens: None, }], id: ast::NodeId::root(), rules: ast::BlockCheckMode::Default, diff --git a/src/formatting/items.rs b/src/formatting/items.rs index 5a8abd8312c..7b199df9698 100644 --- a/src/formatting/items.rs +++ b/src/formatting/items.rs @@ -2275,7 +2275,7 @@ pub(crate) fn span_hi_for_param(context: &RewriteContext<'_>, param: &ast::Param pub(crate) fn is_named_param(param: &ast::Param) -> bool { if let ast::PatKind::Ident(_, ident, _) = param.pat.kind { - ident.name != symbol::kw::Invalid + ident.name != symbol::kw::Empty } else { true } diff --git a/src/formatting/macros.rs b/src/formatting/macros.rs index cff47329266..c785b46926b 100644 --- a/src/formatting/macros.rs +++ b/src/formatting/macros.rs @@ -157,7 +157,7 @@ fn rewrite_macro_name( format!("{}!", pprust::path_to_string(path)) }; match extra_ident { - Some(ident) if ident.name != kw::Invalid => format!("{} {}", name, ident), + Some(ident) if ident.name != kw::Empty => format!("{} {}", name, ident), _ => name, } } From a9afa986acf723ad8778e645589d0c2ab6645a4f Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 1 Jan 2021 20:45:03 +0100 Subject: [PATCH 3/7] Bump rustc-ap to v697. --- Cargo.toml | 16 ++++++++-------- rust-toolchain | 2 +- 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index fa3159b2a4a..4fd59a27181 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -107,32 +107,32 @@ lazy_static = "1.0.0" [dependencies.rustc_ast] package = "rustc-ap-rustc_ast" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_ast_pretty] package = "rustc-ap-rustc_ast_pretty" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_data_structures] package = "rustc-ap-rustc_data_structures" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_errors] package = "rustc-ap-rustc_errors" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_expand] package = "rustc-ap-rustc_expand" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_parse] package = "rustc-ap-rustc_parse" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_session] package = "rustc-ap-rustc_session" -version = "691.0.0" +version = "697.0.0" [dependencies.rustc_span] package = "rustc-ap-rustc_span" -version = "691.0.0" +version = "697.0.0" diff --git a/rust-toolchain b/rust-toolchain index 3a0caaede5f..32429dab56e 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -nightly-2020-11-29 +nightly-2020-12-31 From 0088533d44971eb192f06aed257b3b987f661f76 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 1 Jan 2021 20:47:30 +0100 Subject: [PATCH 4/7] Account for new ast::GenericParamKind::Const::default in rust_ast. --- src/formatting/spanned.rs | 7 ++++++- src/formatting/types.rs | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/src/formatting/spanned.rs b/src/formatting/spanned.rs index c23958b14a0..9911fb887da 100644 --- a/src/formatting/spanned.rs +++ b/src/formatting/spanned.rs @@ -116,7 +116,12 @@ impl Spanned for ast::Param { impl Spanned for ast::GenericParam { fn span(&self) -> Span { - let lo = if let ast::GenericParamKind::Const { ty: _, kw_span } = self.kind { + let lo = if let ast::GenericParamKind::Const { + ty: _, + kw_span, + default: _, + } = self.kind + { kw_span.lo() } else if self.attrs.is_empty() { self.ident.span.lo() diff --git a/src/formatting/types.rs b/src/formatting/types.rs index b50ad459a77..d9802ea5f45 100644 --- a/src/formatting/types.rs +++ b/src/formatting/types.rs @@ -563,7 +563,12 @@ impl Rewrite for ast::GenericParam { _ => {} } - if let ast::GenericParamKind::Const { ref ty, kw_span: _ } = &self.kind { + if let ast::GenericParamKind::Const { + ref ty, + kw_span: _, + default: _, + } = &self.kind + { result.push_str("const "); result.push_str(rewrite_ident(context, self.ident)); result.push_str(": "); From c074c6ab31f3c2d00cdacfde381e9d392bdb7185 Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Fri, 1 Jan 2021 23:57:19 +0100 Subject: [PATCH 5/7] Fix expected macro formatting test output. --- tests/target/macro_rules.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/target/macro_rules.rs b/tests/target/macro_rules.rs index a83f334cb63..c174c719eb3 100644 --- a/tests/target/macro_rules.rs +++ b/tests/target/macro_rules.rs @@ -172,7 +172,7 @@ macro_rules! m [ ]; // #2470 -macro foo($type_name: ident, $docs: expr) { +macro foo($type_name:ident, $docs:expr) { #[allow(non_camel_case_types)] #[doc=$docs] #[derive(Debug, Clone, Copy)] From ec41b78b0e0727256a9da0d74ecd0b5fa193293e Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 2 Jan 2021 02:21:22 +0100 Subject: [PATCH 6/7] Add 2021 test. --- tests/target/imports_2021_edition.rs | 3 +++ 1 file changed, 3 insertions(+) create mode 100644 tests/target/imports_2021_edition.rs diff --git a/tests/target/imports_2021_edition.rs b/tests/target/imports_2021_edition.rs new file mode 100644 index 00000000000..34dcc866a0b --- /dev/null +++ b/tests/target/imports_2021_edition.rs @@ -0,0 +1,3 @@ +// rustfmt-edition: 2021 + +use ::happy::new::year; From 9c11e6a42797b7cd35f6872433fbd91d7e48a79a Mon Sep 17 00:00:00 2001 From: Mara Bos Date: Sat, 2 Jan 2021 02:21:48 +0100 Subject: [PATCH 7/7] Update Cargo.lock. --- Cargo.lock | 80 +++++++++++++++++++++++++++--------------------------- 1 file changed, 40 insertions(+), 40 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index be5f8743ebb..c5b04196ddd 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -735,18 +735,18 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_arena" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "81f7b9bc5a6f79b1f230833cb4c8f8928d48c129b21df5b372c202fb826c0b5e" +checksum = "fb953bea2006184c8f01a6fd3ed51658c73380992a9aefc113e8d32ece6b7516" dependencies = [ "smallvec", ] [[package]] name = "rustc-ap-rustc_ast" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3d77f313e9f30af93f2737f1a99d6552e26b702c5cef3bb65e35f5b4fe5191f1" +checksum = "94da60fa49b2f60d2539e8823cf2b4d4e61583ba4ee796b8289e12f017d3dc5b" dependencies = [ "bitflags", "rustc-ap-rustc_data_structures", @@ -761,9 +761,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_ast_passes" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "30408fbf42fa6fbeb383d3fce0f24d2490c3d12527beb2f48e6e728765bc8695" +checksum = "3e9f9eaaee223832187a398abe0f9cb8bc4e5cd538322d8f3864aea65239c79e" dependencies = [ "itertools 0.9.0", "rustc-ap-rustc_ast", @@ -780,9 +780,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_ast_pretty" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d47b8a3adcccc204578b0ee9cd2f9952921fa43977f58343913cca04cce87043" +checksum = "302b43429c62efc43b159b1f8ab94c8b517fb553cbae854c3fcf34e01c36accb" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_span", @@ -792,9 +792,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_attr" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "66f5f53ecdbf7d8b47905936f93eb1fdae496137e94b7e4023a0b866b0e1a92d" +checksum = "2cbd78cb6f7ca0991478d7f1bc5646b6eca58c37ccbdf70b5d83c490a7c47be7" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_ast_pretty", @@ -811,9 +811,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_data_structures" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3aa913fa40b90157067b17dd7ddfd5df0d8566e339ffa8351a638bdf3fc7ee81" +checksum = "7b9ebd359b0f21086a88595a25d92dc7e8e5f7b111e41c52bb6c97e2d95fd0bb" dependencies = [ "arrayvec", "bitflags", @@ -842,9 +842,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_errors" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "5d4b4956287d7c4996409b8362aa69c0c9a6853751ff00ee0a6f78223c5ef3ad" +checksum = "3b810fcac4d738c47d7793afe3e0f2e03d5193c36c698b0fbcebfb64e468c06b" dependencies = [ "annotate-snippets", "atty", @@ -862,9 +862,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_expand" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "3fa908bb1b67230dd4309e93edefc6a6c2f3d8b6a195f77c47743c882114a22e" +checksum = "f5b44aadd09c05a42a21a063e9f2241fd3d9c00c3dd6e474e22c3a3e8274c959" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_ast_passes", @@ -885,9 +885,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_feature" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "d9b7a1db115893ed7ed0db80f70d2246c1709de7854238acde76471495930f2a" +checksum = "a2f4121cb9718c8c1c6350a3aaea619fbbae38fb1aadd3d7305586460babb531" dependencies = [ "rustc-ap-rustc_data_structures", "rustc-ap-rustc_span", @@ -895,21 +895,21 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_fs_util" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "55937887cb606cc72193ea3c5feb8bbbb810d812aa233b9a1e7749155c4a3501" +checksum = "fdb0f36e34fafb725795bef3ec6f414cac34e7ca98e6d25927be36d95ae1c6ac" [[package]] name = "rustc-ap-rustc_graphviz" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "e39e179e616356927f0c4eda43e3a35d88476f91e1ac8e4a0a09661dbab44a6e" +checksum = "a98402e20e2913016ed54f12aead5c987fe227a0fb31cc720e17ff51c6f32466" [[package]] name = "rustc-ap-rustc_index" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "572d3962d6999f3b1a71d335308e939e204339d4ad36e6ebe7a591c9d4329f5d" +checksum = "ec91408d727f73f682cd8ae836d762c8dab0ed4e81994ced03aa1edcee3b99a4" dependencies = [ "arrayvec", "rustc-ap-rustc_macros", @@ -918,18 +918,18 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_lexer" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "44bc89d9ca7a78fb82e103b389362c55f03800745f8ba14e068b805cfaf783ec" +checksum = "67adbe260a0a11910624d6d28c0304fcf7b063e666682111005c83b09f73429d" dependencies = [ "unicode-xid", ] [[package]] name = "rustc-ap-rustc_lint_defs" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "7d39bda92aabd77e49ac8ad5e24fccf9d7245b8ff2bf1249ab98733e2e5a2863" +checksum = "6bf11d0646da7bd136fbca53834afcc3760fbfc20fa4875e139b3ada41ec53a5" dependencies = [ "rustc-ap-rustc_ast", "rustc-ap-rustc_data_structures", @@ -941,9 +941,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_macros" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "a3295fbc9625197494e356e92d8ac08370eddafa60189861c7b2f084b3b5a6b8" +checksum = "c454b10b66750ffd9bfd7d53b0f30eaba1462356e9ac91f0d037cb0556dc7681" dependencies = [ "proc-macro2", "quote", @@ -953,9 +953,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_parse" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9ff5d0094396844efead43303a6eb25b8a4962e2c80fb0ea4a86e4101fbfd404" +checksum = "3d03f423948137a8370a88447382a18015d47a273268e3ead2d0a987c3b14070" dependencies = [ "bitflags", "rustc-ap-rustc_ast", @@ -973,9 +973,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_serialize" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "2d5cff6709a8b51a3730288a9ead17cabe8146b1c787db52298447ef7890140a" +checksum = "e7ed5df71bd37d1e179b4bbedf77db76c9e0eb2e03159c58a691adbf29f74682" dependencies = [ "indexmap", "smallvec", @@ -983,9 +983,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_session" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "36bb15ef12174b5ed6419a7e4260a899ce8927e8c8fd1f0cddf178818737dcdf" +checksum = "3e3b92b51fad25a897b23ec98961126aea038abeab8d47989f774f7727016b5e" dependencies = [ "bitflags", "getopts", @@ -1005,9 +1005,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_span" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "104d349a32be9cfd3d39a5a70ad6c5e682ce262fc5cc8717d35a01e980c0d8b2" +checksum = "d98273206d8a571c780f233f3391ea30e29c5e75ecdc60335ccef346046e1953" dependencies = [ "cfg-if 0.1.10", "md-5", @@ -1025,9 +1025,9 @@ dependencies = [ [[package]] name = "rustc-ap-rustc_target" -version = "691.0.0" +version = "697.0.0" source = "registry+https://github.com/rust-lang/crates.io-index" -checksum = "9d7ac4ded9a6aecb534744c836a160497985f0d53b272581e95e7890d31b9e17" +checksum = "08ce81fe0130e61112db5f3b2db6b21d407e4b14ae467ab9637f4696cc340ad1" dependencies = [ "bitflags", "rustc-ap-rustc_data_structures",