Skip to content

Add support for edition 2021. #4618

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

Merged
merged 7 commits into from
Jan 2, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 40 additions & 40 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

16 changes: 8 additions & 8 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -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"
2 changes: 1 addition & 1 deletion Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion rust-toolchain
Original file line number Diff line number Diff line change
@@ -1 +1 @@
nightly-2020-11-29
nightly-2020-12-31
11 changes: 11 additions & 0 deletions src/config/options.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand All @@ -356,10 +360,17 @@ impl From<Edition> 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<std::cmp::Ordering> {
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 {
Expand Down
1 change: 0 additions & 1 deletion src/formatting/closures.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion src/formatting/imports.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
2 changes: 1 addition & 1 deletion src/formatting/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down
2 changes: 1 addition & 1 deletion src/formatting/macros.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
}
Expand Down
7 changes: 6 additions & 1 deletion src/formatting/spanned.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down
7 changes: 6 additions & 1 deletion src/formatting/types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(": ");
Expand Down
3 changes: 3 additions & 0 deletions tests/target/imports_2021_edition.rs
Original file line number Diff line number Diff line change
@@ -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

2 changes: 1 addition & 1 deletion tests/target/macro_rules.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)]
Expand Down