From 99341e6d751263bf195875f60310d1db88a70971 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:12:08 -0500 Subject: [PATCH 1/9] feat: implement Style Edition support Adds the 'style_edition' configuration option along with documentation, 'version' option deprecation, and mapping of 'edition' and 'version' values for backwards compatibility and adherence to the style evolution RFC --- Configurations.md | 17 +++++++++++---- rustfmt.toml | 2 +- src/config/config_type.rs | 44 +++++++++++++++++++++++++++++++++++++++ src/config/mod.rs | 5 +++++ src/config/options.rs | 37 +++++++++++++++++++++++++++++--- 5 files changed, 97 insertions(+), 8 deletions(-) diff --git a/Configurations.md b/Configurations.md index f52c2573154..ec95c82fdb1 100644 --- a/Configurations.md +++ b/Configurations.md @@ -534,7 +534,7 @@ Note that this option may be soft-deprecated in the future once the [ignore](#ig Specifies which edition is used by the parser. - **Default value**: `"2015"` -- **Possible values**: `"2015"`, `"2018"`, `"2021"` +- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` - **Stable**: Yes Rustfmt is able to pick up the edition used by reading the `Cargo.toml` file if executed @@ -2692,6 +2692,17 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics) +## `style_edition` + +Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338]) + +- **Default value**: `"2015"` +- **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant) +- **Stable**: Yes + +[Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/ +[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html + ## `tab_spaces` Number of spaces per tab @@ -3051,9 +3062,7 @@ fn main() { ## `version` -Which version of the formatting rules to use. `Version::One` is backwards-compatible -with Rustfmt 1.0. Other versions are only backwards compatible within a major -version number. +This option is deprecated and has been replaced by [`style_edition`](#style_edition) - **Default value**: `One` - **Possible values**: `One`, `Two` diff --git a/rustfmt.toml b/rustfmt.toml index eccd5f9bd19..52e4d728b64 100644 --- a/rustfmt.toml +++ b/rustfmt.toml @@ -1,3 +1,3 @@ error_on_line_overflow = true error_on_unformatted = true -version = "Two" +style_edition = "2024" diff --git a/src/config/config_type.rs b/src/config/config_type.rs index c3d5b7a43cf..3a3500e4ef8 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -133,6 +133,8 @@ macro_rules! create_config { "merge_imports" => self.0.set_merge_imports(), "fn_args_layout" => self.0.set_fn_args_layout(), "hide_parse_errors" => self.0.set_hide_parse_errors(), + "version" => self.0.set_version(), + "edition" => self.0.set_edition(), &_ => (), } } @@ -259,6 +261,8 @@ macro_rules! create_config { self.set_merge_imports(); self.set_fn_args_layout(); self.set_hide_parse_errors(); + self.set_version(); + self.set_edition(); self } @@ -360,6 +364,8 @@ macro_rules! create_config { "merge_imports" => self.set_merge_imports(), "fn_args_layout" => self.set_fn_args_layout(), "hide_parse_errors" => self.set_hide_parse_errors(), + "version" => self.set_version(), + "edition" => self.set_edition(), &_ => (), } } @@ -560,6 +566,44 @@ macro_rules! create_config { } } + fn set_version(&mut self) { + if !self.was_set().version() { + return; + } + + eprintln!( + "Warning: the `version` option is deprecated. \ + Use `style_edition` instead." + ); + + if self.was_set().style_edition() { + eprintln!( + "Warning: the deprecated `version` option was \ + used in conjunction with the `edition` or \ + `style_edition` options which take precedence. \ + The value of the `version` option will be ignored." + ); + } else if matches!(self.version(), Version::Two) { + self.style_edition.2 = StyleEdition::Edition2024; + } else { + self.style_edition.2 = StyleEdition::Edition2015; + } + } + + fn set_edition(&mut self) { + if self.was_set().style_edition() || self.was_set().version() { + return; + } + + // User has explicitly specified an Edition value without + // explicitly specifying a Style Edition value, so the Style Edition + // must default to whatever value was provided for Edition + // as per: https://rust-lang.github.io/rfcs/3338-style-evolution.html#explanation + self.style_edition.2 = self.edition().into(); + } + + + #[allow(unreachable_pub)] /// Returns `true` if the config key was explicitly set and is the default value. pub fn is_default(&self, key: &str) -> bool { diff --git a/src/config/mod.rs b/src/config/mod.rs index b60b2f10ba2..9103a4859ab 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -149,6 +149,7 @@ create_config! { blank_lines_lower_bound: BlankLinesLowerBound, false, "Minimum number of blank lines which must be put between items"; edition: EditionConfig, true, "The edition of the parser (RFC 2052)"; + style_edition: StyleEditionConfig, false, "The edition of the Style Guide (RFC 3338)"; version: VersionConfig, false, "Version of formatting rules"; inline_attribute_width: InlineAttributeWidth, false, "Write an item and its attribute on the same line \ @@ -502,6 +503,9 @@ mod test { stable_option: StableOption, true, "A stable option"; unstable_option: UnstableOption, false, "An unstable option"; partially_unstable_option: PartiallyUnstable, true, "A partially unstable option"; + edition: EditionConfig, true, "blah"; + style_edition: StyleEditionConfig, true, "blah"; + version: VersionConfig, false, "blah blah" } #[cfg(test)] @@ -685,6 +689,7 @@ match_block_trailing_comma = false blank_lines_upper_bound = 1 blank_lines_lower_bound = 0 edition = "2015" +style_edition = "2015" version = "One" inline_attribute_width = 0 format_generated_files = true diff --git a/src/config/options.rs b/src/config/options.rs index e674aba86f8..7c0a3609775 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -456,6 +456,17 @@ impl From for rustc_span::edition::Edition { } } +impl From for StyleEdition { + fn from(edition: Edition) -> Self { + match edition { + Edition::Edition2015 => StyleEdition::Edition2015, + Edition::Edition2018 => StyleEdition::Edition2018, + Edition::Edition2021 => StyleEdition::Edition2021, + Edition::Edition2024 => StyleEdition::Edition2024, + } + } +} + impl PartialOrd for Edition { fn partial_cmp(&self, other: &Edition) -> Option { rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()) @@ -473,10 +484,11 @@ pub enum MatchArmLeadingPipe { Preserve, } -/// Defines the default values for each config according to [the style guide]. -/// rustfmt output may differ between style editions. +/// Defines the default values for each config according to the edition of the +/// [Style Guide] as per [RFC 3338]. Rustfmt output may differ between Style editions. /// -/// [the style guide]: https://doc.rust-lang.org/nightly/style-guide/ +/// [Style Guide]: https://doc.rust-lang.org/nightly/style-guide/ +/// [RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html #[config_type] pub enum StyleEdition { #[value = "2015"] @@ -493,10 +505,28 @@ pub enum StyleEdition { Edition2021, #[value = "2024"] #[doc_hint = "2024"] + #[unstable_variant] /// [Edition 2024](). Edition2024, } +impl From for rustc_span::edition::Edition { + fn from(edition: StyleEdition) -> Self { + match edition { + StyleEdition::Edition2015 => Self::Edition2015, + StyleEdition::Edition2018 => Self::Edition2018, + StyleEdition::Edition2021 => Self::Edition2021, + StyleEdition::Edition2024 => Self::Edition2024, + } + } +} + +impl PartialOrd for StyleEdition { + fn partial_cmp(&self, other: &StyleEdition) -> Option { + rustc_span::edition::Edition::partial_cmp(&(*self).into(), &(*other).into()) + } +} + /// Defines unit structs to implement `StyleEditionDefault` for. #[macro_export] macro_rules! config_option_with_style_edition_default { @@ -608,6 +638,7 @@ config_option_with_style_edition_default!( BlankLinesUpperBound, usize, _ => 1; BlankLinesLowerBound, usize, _ => 0; EditionConfig, Edition, _ => Edition::Edition2015; + StyleEditionConfig, StyleEdition, _ => StyleEdition::Edition2015; VersionConfig, Version, Edition2024 => Version::Two, _ => Version::One; InlineAttributeWidth, usize, _ => 0; FormatGeneratedFiles, bool, _ => true; From 17bbc683b212017adf2ca0a7c362ad9c00f07646 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:21:53 -0500 Subject: [PATCH 2/9] refactor: switch from 'version' to 'style_edition' Updates the relevant formatting logic to utilize the new 'style_edition' option directly instead of the now deprecated 'version' option. 'version' has only been soft deprecated and has auto mapping in place so there should be zero formatting impact to current 'version' users. --- src/chains.rs | 4 +- src/closures.rs | 10 ++--- src/expr.rs | 4 +- src/imports.rs | 100 ++++++++++++++++++++++++++++++-------------- src/items.rs | 24 ++++++----- src/lib.rs | 2 +- src/macros.rs | 4 +- src/matches.rs | 13 +++--- src/missed_spans.rs | 6 ++- src/overflow.rs | 11 ++--- src/patterns.rs | 6 ++- src/stmt.rs | 13 +++--- src/types.rs | 18 ++++---- src/utils.rs | 8 ++-- src/visitor.rs | 7 ++-- 15 files changed, 138 insertions(+), 92 deletions(-) diff --git a/src/chains.rs b/src/chains.rs index 2458e2b6b58..923ffeae7b7 100644 --- a/src/chains.rs +++ b/src/chains.rs @@ -62,7 +62,7 @@ use rustc_ast::{ast, ptr}; use rustc_span::{symbol, BytePos, Span}; use crate::comment::{rewrite_comment, CharClasses, FullCodeCharKind, RichChar}; -use crate::config::{IndentStyle, Version}; +use crate::config::{IndentStyle, StyleEdition}; use crate::expr::rewrite_call; use crate::lists::extract_pre_comment; use crate::macros::convert_try_mac; @@ -285,7 +285,7 @@ impl Rewrite for ChainItem { ChainItemKind::StructField(ident) => format!(".{}", rewrite_ident(context, ident)), ChainItemKind::TupleField(ident, nested) => format!( "{}.{}", - if nested && context.config.version() == Version::One { + if nested && context.config.style_edition() <= StyleEdition::Edition2021 { " " } else { "" diff --git a/src/closures.rs b/src/closures.rs index 20dc4eb6ec4..a628e3da979 100644 --- a/src/closures.rs +++ b/src/closures.rs @@ -4,7 +4,7 @@ use thin_vec::thin_vec; use crate::attr::get_attrs_from_stmt; use crate::config::lists::*; -use crate::config::Version; +use crate::config::StyleEdition; use crate::expr::{block_contains_comment, is_simple_block, is_unsafe_block, rewrite_cond}; use crate::items::{span_hi_for_param, span_lo_for_param}; use crate::lists::{definitive_tactic, itemize_list, write_list, ListFormatting, Separator}; @@ -457,18 +457,18 @@ fn is_block_closure_forced(context: &RewriteContext<'_>, expr: &ast::Expr) -> bo if context.inside_macro() { false } else { - is_block_closure_forced_inner(expr, context.config.version()) + is_block_closure_forced_inner(expr, context.config.style_edition()) } } -fn is_block_closure_forced_inner(expr: &ast::Expr, version: Version) -> bool { +fn is_block_closure_forced_inner(expr: &ast::Expr, style_edition: StyleEdition) -> bool { match expr.kind { ast::ExprKind::If(..) | ast::ExprKind::While(..) | ast::ExprKind::ForLoop { .. } => true, - ast::ExprKind::Loop(..) if version == Version::Two => true, + ast::ExprKind::Loop(..) if style_edition >= StyleEdition::Edition2024 => true, ast::ExprKind::AddrOf(_, _, ref expr) | ast::ExprKind::Try(ref expr) | ast::ExprKind::Unary(_, ref expr) - | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, version), + | ast::ExprKind::Cast(ref expr, _) => is_block_closure_forced_inner(expr, style_edition), _ => false, } } diff --git a/src/expr.rs b/src/expr.rs index ebbeeee4ae1..6f6f9fec6c0 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -13,7 +13,7 @@ use crate::comment::{ rewrite_missing_comment, CharClasses, FindUncommented, }; use crate::config::lists::*; -use crate::config::{Config, ControlBraceStyle, HexLiteralCase, IndentStyle, Version}; +use crate::config::{Config, ControlBraceStyle, HexLiteralCase, IndentStyle, StyleEdition}; use crate::lists::{ definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, struct_lit_tactic, write_list, ListFormatting, Separator, @@ -1282,7 +1282,7 @@ fn rewrite_string_lit(context: &RewriteContext<'_>, span: Span, shape: Shape) -> .lines() .dropping_back(1) .all(|line| line.ends_with('\\')) - && context.config.version() == Version::Two + && context.config.style_edition() >= StyleEdition::Edition2024 { return Some(string_lit.to_owned()); } else { diff --git a/src/imports.rs b/src/imports.rs index 4cea59ddc58..edea5230890 100644 --- a/src/imports.rs +++ b/src/imports.rs @@ -15,7 +15,7 @@ use rustc_span::{ use crate::comment::combine_strs_with_missing_comments; use crate::config::lists::*; use crate::config::ImportGranularity; -use crate::config::{Edition, IndentStyle, Version}; +use crate::config::{Edition, IndentStyle, StyleEdition}; use crate::lists::{ definitive_tactic, itemize_list, write_list, ListFormatting, ListItem, Separator, }; @@ -104,7 +104,7 @@ pub(crate) enum UseSegmentKind { #[derive(Clone, Eq, PartialEq)] pub(crate) struct UseSegment { pub(crate) kind: UseSegmentKind, - pub(crate) version: Version, + pub(crate) style_edition: StyleEdition, } #[derive(Clone)] @@ -149,7 +149,7 @@ impl UseSegment { }; UseSegment { kind, - version: self.version, + style_edition: self.style_edition, } } @@ -197,7 +197,7 @@ impl UseSegment { Some(UseSegment { kind, - version: context.config.version(), + style_edition: context.config.style_edition(), }) } @@ -444,18 +444,21 @@ impl UseTree { } } - let version = context.config.version(); + let style_edition = context.config.style_edition(); match a.kind { UseTreeKind::Glob => { // in case of a global path and the glob starts at the root, e.g., "::*" if a.prefix.segments.len() == 1 && leading_modsep { let kind = UseSegmentKind::Ident("".to_owned(), None); - result.path.push(UseSegment { kind, version }); + result.path.push(UseSegment { + kind, + style_edition, + }); } result.path.push(UseSegment { kind: UseSegmentKind::Glob, - version, + style_edition, }); } UseTreeKind::Nested { @@ -480,7 +483,10 @@ impl UseTree { // e.g., "::{foo, bar}" if a.prefix.segments.len() == 1 && leading_modsep { let kind = UseSegmentKind::Ident("".to_owned(), None); - result.path.push(UseSegment { kind, version }); + result.path.push(UseSegment { + kind, + style_edition, + }); } let kind = UseSegmentKind::List( list.iter() @@ -490,7 +496,10 @@ impl UseTree { }) .collect(), ); - result.path.push(UseSegment { kind, version }); + result.path.push(UseSegment { + kind, + style_edition, + }); } UseTreeKind::Simple(ref rename) => { // If the path has leading double colons and is composed of only 2 segments, then we @@ -519,7 +528,10 @@ impl UseTree { _ => UseSegmentKind::Ident(name, alias), }; - let segment = UseSegment { kind, version }; + let segment = UseSegment { + kind, + style_edition, + }; // `name` is already in result. result.path.pop(); @@ -614,7 +626,7 @@ impl UseTree { list.sort(); last = UseSegment { kind: UseSegmentKind::List(list), - version: last.version, + style_edition: last.style_edition, }; } @@ -732,9 +744,12 @@ impl UseTree { }) = self.path.last() { let self_segment = self.path.pop().unwrap(); - let version = self_segment.version; + let style_edition = self_segment.style_edition; let kind = UseSegmentKind::List(vec![UseTree::from_path(vec![self_segment], DUMMY_SP)]); - self.path.push(UseSegment { kind, version }); + self.path.push(UseSegment { + kind, + style_edition, + }); } self } @@ -750,7 +765,7 @@ fn merge_rest( return None; } if a.len() != len && b.len() != len { - let version = a[len].version; + let style_edition = a[len].style_edition; if let UseSegmentKind::List(ref list) = a[len].kind { let mut list = list.clone(); merge_use_trees_inner( @@ -760,7 +775,10 @@ fn merge_rest( ); let mut new_path = b[..len].to_vec(); let kind = UseSegmentKind::List(list); - new_path.push(UseSegment { kind, version }); + new_path.push(UseSegment { + kind, + style_edition, + }); return Some(new_path); } } else if len == 1 { @@ -770,9 +788,12 @@ fn merge_rest( (&b[0], &a[1..]) }; let kind = UseSegmentKind::Slf(common.get_alias().map(ToString::to_string)); - let version = a[0].version; + let style_edition = a[0].style_edition; let mut list = vec![UseTree::from_path( - vec![UseSegment { kind, version }], + vec![UseSegment { + kind, + style_edition, + }], DUMMY_SP, )]; match rest { @@ -788,7 +809,7 @@ fn merge_rest( b[0].clone(), UseSegment { kind: UseSegmentKind::List(list), - version, + style_edition, }, ]); } else { @@ -801,8 +822,11 @@ fn merge_rest( list.sort(); let mut new_path = b[..len].to_vec(); let kind = UseSegmentKind::List(list); - let version = a[0].version; - new_path.push(UseSegment { kind, version }); + let style_edition = a[0].style_edition; + new_path.push(UseSegment { + kind, + style_edition, + }); Some(new_path) } @@ -892,7 +916,7 @@ impl Ord for UseSegment { | (Super(ref a), Super(ref b)) | (Crate(ref a), Crate(ref b)) => match (a, b) { (Some(sa), Some(sb)) => { - if self.version == Version::Two { + if self.style_edition >= StyleEdition::Edition2024 { sa.trim_start_matches("r#").cmp(sb.trim_start_matches("r#")) } else { a.cmp(b) @@ -902,7 +926,7 @@ impl Ord for UseSegment { }, (Glob, Glob) => Ordering::Equal, (Ident(ref pia, ref aa), Ident(ref pib, ref ab)) => { - let (ia, ib) = if self.version == Version::Two { + let (ia, ib) = if self.style_edition >= StyleEdition::Edition2024 { (pia.trim_start_matches("r#"), pib.trim_start_matches("r#")) } else { (pia.as_str(), pib.as_str()) @@ -928,7 +952,7 @@ impl Ord for UseSegment { (None, Some(_)) => Ordering::Less, (Some(_), None) => Ordering::Greater, (Some(aas), Some(abs)) => { - if self.version == Version::Two { + if self.style_edition >= StyleEdition::Edition2024 { aas.trim_start_matches("r#") .cmp(abs.trim_start_matches("r#")) } else { @@ -1114,7 +1138,7 @@ mod test { struct Parser<'a> { input: Peekable>, - version: Version, + style_edition: StyleEdition, } impl<'a> Parser<'a> { @@ -1132,7 +1156,7 @@ mod test { buf: &mut String, alias_buf: &mut Option, ) { - let version = self.version; + let style_edition = self.style_edition; if !buf.is_empty() { let mut alias = None; swap(alias_buf, &mut alias); @@ -1140,19 +1164,28 @@ mod test { match buf.as_ref() { "self" => { let kind = UseSegmentKind::Slf(alias); - result.push(UseSegment { kind, version }); + result.push(UseSegment { + kind, + style_edition, + }); *buf = String::new(); *alias_buf = None; } "super" => { let kind = UseSegmentKind::Super(alias); - result.push(UseSegment { kind, version }); + result.push(UseSegment { + kind, + style_edition, + }); *buf = String::new(); *alias_buf = None; } "crate" => { let kind = UseSegmentKind::Crate(alias); - result.push(UseSegment { kind, version }); + result.push(UseSegment { + kind, + style_edition, + }); *buf = String::new(); *alias_buf = None; } @@ -1160,7 +1193,10 @@ mod test { let mut name = String::new(); swap(buf, &mut name); let kind = UseSegmentKind::Ident(name, alias); - result.push(UseSegment { kind, version }); + result.push(UseSegment { + kind, + style_edition, + }); } } } @@ -1178,7 +1214,7 @@ mod test { let kind = UseSegmentKind::List(self.parse_list()); result.push(UseSegment { kind, - version: self.version, + style_edition: self.style_edition, }); self.eat('}'); } @@ -1188,7 +1224,7 @@ mod test { let kind = UseSegmentKind::Glob; result.push(UseSegment { kind, - version: self.version, + style_edition: self.style_edition, }); } ':' => { @@ -1249,7 +1285,7 @@ mod test { let mut parser = Parser { input: s.chars().peekable(), - version: Version::One, + style_edition: StyleEdition::Edition2015, }; parser.parse_in_list() } diff --git a/src/items.rs b/src/items.rs index a9f86c6b7d6..6fb6d081946 100644 --- a/src/items.rs +++ b/src/items.rs @@ -15,7 +15,7 @@ use crate::comment::{ FindUncommented, }; use crate::config::lists::*; -use crate::config::{BraceStyle, Config, IndentStyle, Version}; +use crate::config::{BraceStyle, Config, IndentStyle, StyleEdition}; use crate::expr::{ is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with, rewrite_assign_rhs_with_comments, rewrite_else_kw_with_comments, rewrite_let_else_block, @@ -145,7 +145,8 @@ impl Rewrite for ast::Local { let else_kw_span = init.span.between(block.span); // Strip attributes and comments to check if newline is needed before the else // keyword from the initializer part. (#5901) - let init_str = if context.config.version() == Version::Two { + let style_edition = context.config.style_edition(); + let init_str = if style_edition >= StyleEdition::Edition2024 { &result[let_kw_offset..] } else { result.as_str() @@ -169,7 +170,8 @@ impl Rewrite for ast::Local { std::cmp::min(shape.width, context.config.single_line_let_else_max_width()); // If available_space hits zero we know for sure this will be a multi-lined block - let assign_str_with_else_kw = if context.config.version() == Version::Two { + let style_edition = context.config.style_edition(); + let assign_str_with_else_kw = if style_edition >= StyleEdition::Edition2024 { &result[let_kw_offset..] } else { result.as_str() @@ -675,10 +677,10 @@ impl<'a> FmtVisitor<'a> { let context = self.get_context(); let shape = self.shape(); - let attrs_str = if context.config.version() == Version::Two { + let attrs_str = if context.config.style_edition() >= StyleEdition::Edition2024 { field.attrs.rewrite(&context, shape)? } else { - // Version::One formatting that was off by 1. See issue #5801 + // StyleEdition::Edition20{15|18|21} formatting that was off by 1. See issue #5801 field.attrs.rewrite(&context, shape.sub_width(1)?)? }; // sub_width(1) to take the trailing comma into account @@ -966,7 +968,7 @@ fn format_impl_ref_and_type( result.push_str(format_defaultness(defaultness)); result.push_str(format_safety(safety)); - let shape = if context.config.version() == Version::Two { + let shape = if context.config.style_edition() >= StyleEdition::Edition2024 { Shape::indented(offset + last_line_width(&result), context.config) } else { generics_shape_from_config( @@ -2107,7 +2109,7 @@ impl Rewrite for ast::FnRetTy { ast::FnRetTy::Default(_) => Ok(String::new()), ast::FnRetTy::Ty(ref ty) => { let arrow_width = "-> ".len(); - if context.config.version() == Version::One + if context.config.style_edition() <= StyleEdition::Edition2021 || context.config.indent_style() == IndentStyle::Visual { let inner_width = shape @@ -2510,7 +2512,7 @@ fn rewrite_fn_base( .last() .map_or(false, |last_line| last_line.contains("//")); - if context.config.version() == Version::Two { + if context.config.style_edition() >= StyleEdition::Edition2024 { if closing_paren_overflow_max_width { result.push(')'); result.push_str(&indent.to_string_with_newline(context.config)); @@ -2553,7 +2555,7 @@ fn rewrite_fn_base( } }; let ret_shape = if ret_should_indent { - if context.config.version() == Version::One + if context.config.style_edition() <= StyleEdition::Edition2021 || context.config.indent_style() == IndentStyle::Visual { let indent = if param_str.is_empty() { @@ -2586,7 +2588,7 @@ fn rewrite_fn_base( ret_shape } } else { - if context.config.version() == Version::Two { + if context.config.style_edition() >= StyleEdition::Edition2024 { if !param_str.is_empty() || !no_params_and_over_max_width { result.push(' '); } @@ -3071,7 +3073,7 @@ fn rewrite_bounds_on_where_clause( DefinitiveListTactic::Vertical }; - let preserve_newline = context.config.version() == Version::One; + let preserve_newline = context.config.style_edition() <= StyleEdition::Edition2021; let fmt = ListFormatting::new(shape, context.config) .tactic(shape_tactic) diff --git a/src/lib.rs b/src/lib.rs index 2ef1698ead0..1e9efc5ce94 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -48,7 +48,7 @@ use crate::utils::indent_next_line; pub use crate::config::{ load_config, CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName, NewlineStyle, - Range, Verbosity, + Range, StyleEdition, Verbosity, }; pub use crate::format_report_formatter::{FormatReportFormatter, FormatReportFormatterBuilder}; diff --git a/src/macros.rs b/src/macros.rs index e08146a1f33..c520971f40c 100644 --- a/src/macros.rs +++ b/src/macros.rs @@ -25,7 +25,7 @@ use crate::comment::{ contains_comment, CharClasses, FindUncommented, FullCodeCharKind, LineClasses, }; use crate::config::lists::*; -use crate::config::Version; +use crate::config::StyleEdition; use crate::expr::{rewrite_array, rewrite_assign_rhs, RhsAssignKind}; use crate::lists::{itemize_list, write_list, ListFormatting}; use crate::overflow; @@ -1251,7 +1251,7 @@ impl MacroBranch { let old_body = context.snippet(self.body).trim(); let has_block_body = old_body.starts_with('{'); let mut prefix_width = 5; // 5 = " => {" - if context.config.version() == Version::Two { + if context.config.style_edition() >= StyleEdition::Edition2024 { if has_block_body { prefix_width = 6; // 6 = " => {{" } diff --git a/src/matches.rs b/src/matches.rs index 5884d02af15..5cb34f54f6e 100644 --- a/src/matches.rs +++ b/src/matches.rs @@ -7,7 +7,7 @@ use rustc_span::{BytePos, Span}; use crate::comment::{combine_strs_with_missing_comments, rewrite_comment, FindUncommented}; use crate::config::lists::*; -use crate::config::{Config, ControlBraceStyle, IndentStyle, MatchArmLeadingPipe, Version}; +use crate::config::{Config, ControlBraceStyle, IndentStyle, MatchArmLeadingPipe, StyleEdition}; use crate::expr::{ format_expr, is_empty_block, is_simple_block, is_unsafe_block, prefer_next_line, rewrite_cond, ExprType, RhsTactics, @@ -112,9 +112,10 @@ pub(crate) fn rewrite_match( let inner_attrs_str = if inner_attrs.is_empty() { String::new() } else { - let shape = match context.config.version() { - Version::One => shape, - _ => shape.block_indent(context.config.tab_spaces()), + let shape = if context.config.style_edition() <= StyleEdition::Edition2021 { + shape + } else { + shape.block_indent(context.config.tab_spaces()) }; inner_attrs .rewrite_result(context, shape) @@ -437,7 +438,7 @@ fn rewrite_match_body( let arrow_snippet = context.snippet(arrow_span).trim(); // search for the arrow starting from the end of the snippet since there may be a match // expression within the guard - let arrow_index = if context.config.version() == Version::One { + let arrow_index = if context.config.style_edition() <= StyleEdition::Edition2021 { arrow_snippet.rfind("=>").unwrap() } else { arrow_snippet.find_last_uncommented("=>").unwrap() @@ -475,7 +476,7 @@ fn rewrite_match_body( } else { "" }; - let semicolon = if context.config.version() == Version::One { + let semicolon = if context.config.style_edition() <= StyleEdition::Edition2021 { "" } else { if semicolon_for_expr(context, body) { diff --git a/src/missed_spans.rs b/src/missed_spans.rs index b1a7769c21b..fc5daf71d16 100644 --- a/src/missed_spans.rs +++ b/src/missed_spans.rs @@ -3,7 +3,7 @@ use rustc_span::{BytePos, Pos, Span}; use crate::comment::{is_last_comment_block, rewrite_comment, CodeCharKind, CommentCodeSlices}; use crate::config::file_lines::FileLines; use crate::config::FileName; -use crate::config::Version; +use crate::config::StyleEdition; use crate::coverage::transform_missing_snippet; use crate::shape::{Indent, Shape}; use crate::source_map::LineRangeUtils; @@ -246,7 +246,9 @@ impl<'a> FmtVisitor<'a> { let indent_str = self.block_indent.to_string(self.config); self.push_str(&indent_str); self.block_indent - } else if self.config.version() == Version::Two && !snippet.starts_with('\n') { + } else if self.config.style_edition() >= StyleEdition::Edition2024 + && !snippet.starts_with('\n') + { // The comment appears on the same line as the previous formatted code. // Assuming that comment is logically associated with that code, we want to keep it on // the same level and avoid mixing it with possible other comment. diff --git a/src/overflow.rs b/src/overflow.rs index add86799132..368a8aaec75 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -8,7 +8,7 @@ use rustc_ast::{ast, ptr}; use rustc_span::Span; use crate::closures; -use crate::config::Version; +use crate::config::StyleEdition; use crate::config::{lists::*, Config}; use crate::expr::{ can_be_overflowed_expr, is_every_expr_simple, is_method_call, is_nested_call, is_simple_expr, @@ -200,8 +200,8 @@ impl<'a> OverflowableItem<'a> { OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR, _ => &[], }; - let additional_cases = match (self, config.version()) { - (OverflowableItem::MacroArg(..), Version::Two) => SPECIAL_CASE_MACROS_V2, + let additional_cases = match (self, config.style_edition()) { + (OverflowableItem::MacroArg(..), StyleEdition::Edition2024) => SPECIAL_CASE_MACROS_V2, _ => &[], }; base_cases.iter().chain(additional_cases) @@ -494,7 +494,7 @@ impl<'a> Context<'a> { Some(OverflowableItem::MacroArg(MacroArg::Expr(expr))) if !combine_arg_with_callee && is_method_call(expr) - && self.context.config.version() == Version::Two => + && self.context.config.style_edition() >= StyleEdition::Edition2024 => { self.context.force_one_line_chain.replace(true); } @@ -690,7 +690,8 @@ impl<'a> Context<'a> { ); result.push_str(self.ident); result.push_str(prefix); - let force_single_line = if self.context.config.version() == Version::Two { + let force_single_line = if self.context.config.style_edition() >= StyleEdition::Edition2024 + { !self.context.use_block_indent() || (is_extendable && extend_width <= shape.width) } else { // 2 = `()` diff --git a/src/patterns.rs b/src/patterns.rs index ba97c1d2123..6ec083443bd 100644 --- a/src/patterns.rs +++ b/src/patterns.rs @@ -4,7 +4,7 @@ use rustc_span::{BytePos, Span}; use crate::comment::{combine_strs_with_missing_comments, FindUncommented}; use crate::config::lists::*; -use crate::config::Version; +use crate::config::StyleEdition; use crate::expr::{can_be_overflowed_expr, rewrite_unary_prefix, wrap_struct_field}; use crate::lists::{ definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting, struct_lit_shape, @@ -280,7 +280,9 @@ impl Rewrite for Pat { rewrite_tuple_pat(pat_vec, Some(path_str), self.span, context, shape).ok() } PatKind::Lit(ref expr) => expr.rewrite(context, shape), - PatKind::Slice(ref slice_pat) if context.config.version() == Version::One => { + PatKind::Slice(ref slice_pat) + if context.config.style_edition() <= StyleEdition::Edition2021 => + { let rw: Vec = slice_pat .iter() .map(|p| { diff --git a/src/stmt.rs b/src/stmt.rs index 73a9cce416c..38433433c6b 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -2,7 +2,7 @@ use rustc_ast::ast; use rustc_span::Span; use crate::comment::recover_comment_removed; -use crate::config::Version; +use crate::config::StyleEdition; use crate::expr::{format_expr, is_simple_block, ExprType}; use crate::rewrite::{Rewrite, RewriteContext}; use crate::shape::Shape; @@ -90,11 +90,12 @@ impl<'a> Stmt<'a> { impl<'a> Rewrite for Stmt<'a> { fn rewrite(&self, context: &RewriteContext<'_>, shape: Shape) -> Option { - let expr_type = if context.config.version() == Version::Two && self.is_last_expr() { - ExprType::SubExpression - } else { - ExprType::Statement - }; + let expr_type = + if context.config.style_edition() >= StyleEdition::Edition2024 && self.is_last_expr() { + ExprType::SubExpression + } else { + ExprType::Statement + }; format_stmt( context, shape, diff --git a/src/types.rs b/src/types.rs index eda607c8c9f..1c5a168b42e 100644 --- a/src/types.rs +++ b/src/types.rs @@ -6,7 +6,7 @@ use rustc_span::{symbol::kw, BytePos, Pos, Span}; use crate::comment::{combine_strs_with_missing_comments, contains_comment}; use crate::config::lists::*; -use crate::config::{IndentStyle, TypeDensity, Version}; +use crate::config::{IndentStyle, StyleEdition, TypeDensity}; use crate::expr::{ format_expr, rewrite_assign_rhs, rewrite_call, rewrite_tuple, rewrite_unary_prefix, ExprType, RhsAssignKind, @@ -888,7 +888,7 @@ impl Rewrite for ast::Ty { // FIXME: we drop any comments here, even though it's a silly place to put // comments. ast::TyKind::Paren(ref ty) => { - if context.config.version() == Version::One + if context.config.style_edition() <= StyleEdition::Edition2021 || context.config.indent_style() == IndentStyle::Visual { let budget = shape @@ -966,7 +966,7 @@ impl Rewrite for ast::Ty { if it.is_empty() { return Ok("impl".to_owned()); } - let rw = if context.config.version() == Version::One { + let rw = if context.config.style_edition() <= StyleEdition::Edition2021 { it.rewrite_result(context, shape) } else { join_bounds(context, shape, it, false) @@ -1212,16 +1212,16 @@ fn join_bounds_inner( // and either there is more than one item; // or the single item is of type `Trait`, // and any of the internal arrays contains more than one item; - let retry_with_force_newline = match context.config.version() { - Version::One => { + let retry_with_force_newline = match context.config.style_edition() { + style_edition @ _ if style_edition <= StyleEdition::Edition2021 => { !force_newline && items.len() > 1 && (result.0.contains('\n') || result.0.len() > shape.width) } - Version::Two if force_newline => false, - Version::Two if (!result.0.contains('\n') && result.0.len() <= shape.width) => false, - Version::Two if items.len() > 1 => true, - Version::Two => is_item_with_multi_items_array(&items[0]), + _ if force_newline => false, + _ if (!result.0.contains('\n') && result.0.len() <= shape.width) => false, + _ if items.len() > 1 => true, + _ => is_item_with_multi_items_array(&items[0]), }; if retry_with_force_newline { diff --git a/src/utils.rs b/src/utils.rs index eaf24f3f204..57f2f177960 100644 --- a/src/utils.rs +++ b/src/utils.rs @@ -10,7 +10,7 @@ use rustc_span::{sym, symbol, BytePos, LocalExpnId, Span, Symbol, SyntaxContext} use unicode_width::UnicodeWidthStr; use crate::comment::{filter_normal_code, CharClasses, FullCodeCharKind, LineClasses}; -use crate::config::{Config, Version}; +use crate::config::{Config, StyleEdition}; use crate::rewrite::RewriteContext; use crate::shape::{Indent, Shape}; @@ -604,7 +604,7 @@ pub(crate) fn trim_left_preserve_layout( // just InString{Commented} in order to allow the start of a string to be indented let new_veto_trim_value = (kind == FullCodeCharKind::InString - || (config.version() == Version::Two + || (config.style_edition() >= StyleEdition::Edition2024 && kind == FullCodeCharKind::InStringCommented)) && !line.ends_with('\\'); let line = if veto_trim || new_veto_trim_value { @@ -620,7 +620,7 @@ pub(crate) fn trim_left_preserve_layout( // such lines should not be taken into account when computing the minimum. match kind { FullCodeCharKind::InStringCommented | FullCodeCharKind::EndStringCommented - if config.version() == Version::Two => + if config.style_edition() >= StyleEdition::Edition2024 => { None } @@ -664,7 +664,7 @@ pub(crate) fn indent_next_line(kind: FullCodeCharKind, line: &str, config: &Conf // formatting the code block, therefore the string's indentation needs // to be adjusted for the code surrounding the code block. config.format_strings() && line.ends_with('\\') - } else if config.version() == Version::Two { + } else if config.style_edition() >= StyleEdition::Edition2024 { !kind.is_commented_string() } else { true diff --git a/src/visitor.rs b/src/visitor.rs index 1de9f5a9524..0df3d16e0cb 100644 --- a/src/visitor.rs +++ b/src/visitor.rs @@ -7,8 +7,7 @@ use rustc_span::{symbol, BytePos, Pos, Span}; use crate::attr::*; use crate::comment::{contains_comment, rewrite_comment, CodeCharKind, CommentCodeSlices}; -use crate::config::Version; -use crate::config::{BraceStyle, Config, MacroSelector}; +use crate::config::{BraceStyle, Config, MacroSelector, StyleEdition}; use crate::coverage::transform_missing_snippet; use crate::items::{ format_impl, format_trait, format_trait_alias, is_mod_decl, is_use_item, rewrite_extern_crate, @@ -290,7 +289,9 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { let mut comment_shape = Shape::indented(self.block_indent, config).comment(config); - if self.config.version() == Version::Two && comment_on_same_line { + if self.config.style_edition() >= StyleEdition::Edition2024 + && comment_on_same_line + { self.push_str(" "); // put the first line of the comment on the same line as the // block's last line From 64a64d79ec0eb8c612e3a7d6db51fa5b49398d99 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:22:42 -0500 Subject: [PATCH 3/9] feat: add --style-edition option to rustfmt binary --- src/bin/main.rs | 36 ++++++++++++++++++++++++++++++++++-- 1 file changed, 34 insertions(+), 2 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 4c9798f6c72..2b5d5209b4f 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -19,7 +19,7 @@ use getopts::{Matches, Options}; use crate::rustfmt::{ load_config, CliOptions, Color, Config, Edition, EmitMode, FileLines, FileName, - FormatReportFormatterBuilder, Input, Session, Verbosity, + FormatReportFormatterBuilder, Input, Session, StyleEdition, Verbosity, }; const BUG_REPORT_URL: &str = "https://github.com/rust-lang/rustfmt/issues/new?labels=bug"; @@ -129,7 +129,12 @@ fn make_opts() -> Options { found reverts to the input file path", "[Path for the configuration file]", ); - opts.optopt("", "edition", "Rust edition to use", "[2015|2018|2021]"); + opts.optopt( + "", + "edition", + "Rust edition to use", + "[2015|2018|2021|2024]", + ); opts.optopt( "", "color", @@ -181,6 +186,12 @@ fn make_opts() -> Options { "skip-children", "Don't reformat child modules (unstable).", ); + opts.optopt( + "", + "style-edition", + "The edition of the Style Guide (unstable).", + "[2015|2018|2021|2024]", + ); } opts.optflag("v", "verbose", "Print verbose output"); @@ -525,6 +536,7 @@ struct GetOptsOptions { backup: bool, check: bool, edition: Option, + style_edition: Option, color: Option, file_lines: FileLines, // Default is all lines in all files. unstable_features: bool, @@ -556,6 +568,10 @@ impl GetOptsOptions { if let Some(ref file_lines) = matches.opt_str("file-lines") { options.file_lines = file_lines.parse()?; } + if let Some(ref edition_str) = matches.opt_str("style-edition") { + options.style_edition = + Some(style_edition_from_style_edition_str(edition_str)?); + } } else { let mut unstable_options = vec![]; if matches.opt_present("skip-children") { @@ -567,6 +583,9 @@ impl GetOptsOptions { if matches.opt_present("file-lines") { unstable_options.push("`--file-lines`"); } + if matches.opt_present("style-edition") { + unstable_options.push("`--style-edition`"); + } if !unstable_options.is_empty() { let s = if unstable_options.len() == 1 { "" } else { "s" }; return Err(format_err!( @@ -688,6 +707,9 @@ impl CliOptions for GetOptsOptions { if let Some(edition) = self.edition { config.set_cli().edition(edition); } + if let Some(edition) = self.style_edition { + config.set().style_edition(edition); + } if self.check { config.set_cli().emit_mode(EmitMode::Diff); } else if let Some(emit_mode) = self.emit_mode { @@ -723,6 +745,16 @@ fn edition_from_edition_str(edition_str: &str) -> Result { } } +fn style_edition_from_style_edition_str(edition_str: &str) -> Result { + match edition_str { + "2015" => Ok(StyleEdition::Edition2015), + "2018" => Ok(StyleEdition::Edition2018), + "2021" => Ok(StyleEdition::Edition2021), + "2024" => Ok(StyleEdition::Edition2024), + _ => Err(format_err!("Invalid value for `--style-edition`")), + } +} + fn emit_mode_from_emit_str(emit_str: &str) -> Result { match emit_str { "files" => Ok(EmitMode::Files), From fedad7f7507e7dcb8b20eb49aff8331714229f02 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:23:16 -0500 Subject: [PATCH 4/9] tests: validate style_edition derivation Adds a few tests that validate the various scenarios of precendence, overrides, and defaults to ensure the correct 'style_edition' value is selected even when other options like 'edition' and/or 'version' are included. --- .../indent_style/block_trailing_comma_call/one.rs | 2 +- .../indent_style/block_trailing_comma_call/two.rs | 2 +- tests/target/configs/version/mapped.rs | 9 +++++++++ tests/target/style_edition/default.rs | 10 ++++++++++ tests/target/style_edition/follows_edition.rs | 14 ++++++++++++++ .../style_edition/overrides_edition_when_set.rs | 14 ++++++++++++++ 6 files changed, 49 insertions(+), 2 deletions(-) create mode 100644 tests/target/configs/version/mapped.rs create mode 100644 tests/target/style_edition/default.rs create mode 100644 tests/target/style_edition/follows_edition.rs create mode 100644 tests/target/style_edition/overrides_edition_when_set.rs diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs b/tests/target/configs/indent_style/block_trailing_comma_call/one.rs index 6b9489bef55..204dce6d655 100644 --- a/tests/target/configs/indent_style/block_trailing_comma_call/one.rs +++ b/tests/target/configs/indent_style/block_trailing_comma_call/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs b/tests/target/configs/indent_style/block_trailing_comma_call/two.rs index 4f4292e5f48..887e8328ccc 100644 --- a/tests/target/configs/indent_style/block_trailing_comma_call/two.rs +++ b/tests/target/configs/indent_style/block_trailing_comma_call/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/target/configs/version/mapped.rs b/tests/target/configs/version/mapped.rs new file mode 100644 index 00000000000..296dc559a93 --- /dev/null +++ b/tests/target/configs/version/mapped.rs @@ -0,0 +1,9 @@ +// rustfmt-version: Two +fn main() { + let [ + aaaaaaaaaaaaaaaaaaaaaaaaaa, + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, + cccccccccccccccccccccccccc, + ddddddddddddddddddddddddd, + ] = panic!(); +} diff --git a/tests/target/style_edition/default.rs b/tests/target/style_edition/default.rs new file mode 100644 index 00000000000..17442df6c49 --- /dev/null +++ b/tests/target/style_edition/default.rs @@ -0,0 +1,10 @@ +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> (impl Fn( + AlphabeticalTraversal, + Box>, +) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static) { +} diff --git a/tests/target/style_edition/follows_edition.rs b/tests/target/style_edition/follows_edition.rs new file mode 100644 index 00000000000..c36a993d842 --- /dev/null +++ b/tests/target/style_edition/follows_edition.rs @@ -0,0 +1,14 @@ +// rustfmt-edition: 2024 + +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> ( + impl Fn( + AlphabeticalTraversal, + Box>, + ) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static +) { +} diff --git a/tests/target/style_edition/overrides_edition_when_set.rs b/tests/target/style_edition/overrides_edition_when_set.rs new file mode 100644 index 00000000000..6d0eaac8970 --- /dev/null +++ b/tests/target/style_edition/overrides_edition_when_set.rs @@ -0,0 +1,14 @@ +// rustfmt-edition: 2018 +// rustfmt-style_edition: 2024 +fn build_sorted_static_get_entry_names( + mut entries: Vec<(u8, &'static str)>, +) -> ( + impl Fn( + AlphabeticalTraversal, + Box>, + ) -> BoxFuture<'static, Result, Status>> + + Send + + Sync + + 'static +) { +} From 5d1980ee82d8ea83a33afcfe743a56f2ec3944b8 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:25:11 -0500 Subject: [PATCH 5/9] refactor: switch idempotence/system tests to style_edition Updates all the various files utilized in the system and idempotence tests to directly use the corresponding 'style_edition' configuration as opposed to keeping the original 'version' values and relying on the mapping. --- tests/config/issue-5801-v2.toml | 2 +- tests/source/arrow_in_comments/arrow_in_single_comment.rs | 2 +- tests/source/arrow_in_comments/multiple_arrows.rs | 2 +- .../configs/indent_style/block_trailing_comma_call/one.rs | 2 +- .../configs/indent_style/block_trailing_comma_call/two.rs | 2 +- tests/source/fn-single-line/version_one.rs | 2 +- tests/source/fn-single-line/version_two.rs | 2 +- tests/source/issue-2179/one.rs | 2 +- tests/source/issue-2179/two.rs | 2 +- tests/source/issue-3213/version_one.rs | 2 +- tests/source/issue-3213/version_two.rs | 2 +- tests/source/issue-3227/two.rs | 2 +- tests/source/issue-3270/one.rs | 2 +- tests/source/issue-3270/two.rs | 2 +- tests/source/issue-3272/v1.rs | 2 +- tests/source/issue-3272/v2.rs | 2 +- tests/source/issue-3278/version_one.rs | 2 +- tests/source/issue-3278/version_two.rs | 2 +- tests/source/issue-3295/two.rs | 2 +- tests/source/issue-3302.rs | 2 +- tests/source/issue-3701/one.rs | 2 +- tests/source/issue-3701/two.rs | 2 +- tests/source/issue-3805.rs | 2 +- tests/source/issue-3840/version-two_hard-tabs.rs | 2 +- tests/source/issue-3840/version-two_soft-tabs.rs | 2 +- tests/source/issue-4530.rs | 2 +- tests/source/issue-4689/one.rs | 2 +- tests/source/issue-4689/two.rs | 2 +- tests/source/issue-5586.rs | 2 +- tests/source/issue-5655/one.rs | 2 +- tests/source/issue-5655/two.rs | 2 +- .../issue-5801/comment_unexpectedly_wraps_before_max_width.rs | 2 +- tests/source/issue-5987/two.rs | 2 +- tests/source/issue-6147/case_rustfmt_v1.rs | 2 +- tests/source/issue-6147/case_rustfmt_v2.rs | 2 +- tests/source/issue_5027.rs | 2 +- tests/source/let_else_v2.rs | 2 +- tests/source/long-fn-1/version_one.rs | 2 +- tests/source/long-fn-1/version_two.rs | 2 +- tests/source/one_line_if_v1.rs | 2 +- tests/source/one_line_if_v2.rs | 2 +- tests/source/single-line-macro/v1.rs | 2 +- tests/source/single-line-macro/v2.rs | 2 +- tests/source/trailing_comments/hard_tabs.rs | 2 +- tests/source/trailing_comments/soft_tabs.rs | 2 +- tests/source/tuple_v2.rs | 2 +- tests/target/arrow_in_comments/arrow_in_single_comment.rs | 2 +- tests/target/arrow_in_comments/multiple_arrows.rs | 2 +- tests/target/fn-single-line/version_one.rs | 2 +- tests/target/fn-single-line/version_two.rs | 2 +- tests/target/issue-2179/one.rs | 2 +- tests/target/issue-2179/two.rs | 2 +- tests/target/issue-3132.rs | 2 +- tests/target/issue-3213/version_one.rs | 2 +- tests/target/issue-3213/version_two.rs | 2 +- tests/target/issue-3227/one.rs | 2 +- tests/target/issue-3227/two.rs | 2 +- tests/target/issue-3270/one.rs | 2 +- tests/target/issue-3270/two.rs | 2 +- tests/target/issue-3270/wrap.rs | 2 +- tests/target/issue-3272/v1.rs | 2 +- tests/target/issue-3272/v2.rs | 2 +- tests/target/issue-3278/version_one.rs | 2 +- tests/target/issue-3278/version_two.rs | 2 +- tests/target/issue-3295/two.rs | 2 +- tests/target/issue-3302.rs | 2 +- tests/target/issue-3614/version_one.rs | 2 +- tests/target/issue-3614/version_two.rs | 2 +- tests/target/issue-3701/one.rs | 2 +- tests/target/issue-3701/two.rs | 2 +- tests/target/issue-3805.rs | 2 +- tests/target/issue-3840/version-two_hard-tabs.rs | 2 +- tests/target/issue-3840/version-two_soft-tabs.rs | 2 +- tests/target/issue-3882.rs | 2 +- tests/target/issue-4530.rs | 2 +- tests/target/issue-4689/one.rs | 2 +- tests/target/issue-4689/two.rs | 2 +- tests/target/issue-5586.rs | 2 +- tests/target/issue-5655/one.rs | 2 +- tests/target/issue-5655/two.rs | 2 +- .../target/issue-5801/comment_does_not_wrap_within_max_width.rs | 2 +- .../issue-5801/comment_unexpectedly_wraps_before_max_width.rs | 2 +- tests/target/issue-5987/one.rs | 2 +- tests/target/issue-5987/two.rs | 2 +- tests/target/issue-6147/case_rustfmt_v1.rs | 2 +- tests/target/issue-6147/case_rustfmt_v2.rs | 2 +- tests/target/issue_5027.rs | 2 +- tests/target/let_else_v2.rs | 2 +- tests/target/long-fn-1/version_one.rs | 2 +- tests/target/long-fn-1/version_two.rs | 2 +- tests/target/one_line_if_v1.rs | 2 +- tests/target/one_line_if_v2.rs | 2 +- tests/target/single-line-macro/v1.rs | 2 +- tests/target/single-line-macro/v2.rs | 2 +- tests/target/trailing_comments/hard_tabs.rs | 2 +- tests/target/trailing_comments/soft_tabs.rs | 2 +- tests/target/tuple_v2.rs | 2 +- 97 files changed, 97 insertions(+), 97 deletions(-) diff --git a/tests/config/issue-5801-v2.toml b/tests/config/issue-5801-v2.toml index 948f4fb66bf..98e89d37916 100644 --- a/tests/config/issue-5801-v2.toml +++ b/tests/config/issue-5801-v2.toml @@ -1,3 +1,3 @@ max_width = 120 version = "Two" -attr_fn_like_width = 120 \ No newline at end of file +attr_fn_like_width = 120 diff --git a/tests/source/arrow_in_comments/arrow_in_single_comment.rs b/tests/source/arrow_in_comments/arrow_in_single_comment.rs index fb0576a4822..38e8967e7e6 100644 --- a/tests/source/arrow_in_comments/arrow_in_single_comment.rs +++ b/tests/source/arrow_in_comments/arrow_in_single_comment.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { match a { _ => diff --git a/tests/source/arrow_in_comments/multiple_arrows.rs b/tests/source/arrow_in_comments/multiple_arrows.rs index fc696b309f2..98ef919450f 100644 --- a/tests/source/arrow_in_comments/multiple_arrows.rs +++ b/tests/source/arrow_in_comments/multiple_arrows.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { match a { _ => // comment with => diff --git a/tests/source/configs/indent_style/block_trailing_comma_call/one.rs b/tests/source/configs/indent_style/block_trailing_comma_call/one.rs index 6d48ea742fc..66e2f538415 100644 --- a/tests/source/configs/indent_style/block_trailing_comma_call/one.rs +++ b/tests/source/configs/indent_style/block_trailing_comma_call/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/source/configs/indent_style/block_trailing_comma_call/two.rs b/tests/source/configs/indent_style/block_trailing_comma_call/two.rs index 7a62d722c6e..51aa6376e23 100644 --- a/tests/source/configs/indent_style/block_trailing_comma_call/two.rs +++ b/tests/source/configs/indent_style/block_trailing_comma_call/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-error_on_line_overflow: false // rustfmt-indent_style: Block diff --git a/tests/source/fn-single-line/version_one.rs b/tests/source/fn-single-line/version_one.rs index 469ab621567..85957e3fdcc 100644 --- a/tests/source/fn-single-line/version_one.rs +++ b/tests/source/fn-single-line/version_one.rs @@ -1,5 +1,5 @@ // rustfmt-fn_single_line: true -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Test single-line functions. fn foo_expr() { diff --git a/tests/source/fn-single-line/version_two.rs b/tests/source/fn-single-line/version_two.rs index bf381ff1065..f119e581217 100644 --- a/tests/source/fn-single-line/version_two.rs +++ b/tests/source/fn-single-line/version_two.rs @@ -1,5 +1,5 @@ // rustfmt-fn_single_line: true -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Test single-line functions. fn foo_expr() { diff --git a/tests/source/issue-2179/one.rs b/tests/source/issue-2179/one.rs index d23947931ff..8bbd56f0521 100644 --- a/tests/source/issue-2179/one.rs +++ b/tests/source/issue-2179/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/source/issue-2179/two.rs b/tests/source/issue-2179/two.rs index f4cc9cc488b..631b0f3c86e 100644 --- a/tests/source/issue-2179/two.rs +++ b/tests/source/issue-2179/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/source/issue-3213/version_one.rs b/tests/source/issue-3213/version_one.rs index f9f4cab55e3..ed7d5145150 100644 --- a/tests/source/issue-3213/version_one.rs +++ b/tests/source/issue-3213/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn foo() { match 0 { diff --git a/tests/source/issue-3213/version_two.rs b/tests/source/issue-3213/version_two.rs index 0f068c19d74..c6d04aced8d 100644 --- a/tests/source/issue-3213/version_two.rs +++ b/tests/source/issue-3213/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn foo() { match 0 { diff --git a/tests/source/issue-3227/two.rs b/tests/source/issue-3227/two.rs index c1572c00d57..50c0ad47dc1 100644 --- a/tests/source/issue-3227/two.rs +++ b/tests/source/issue-3227/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { thread::spawn(|| { diff --git a/tests/source/issue-3270/one.rs b/tests/source/issue-3270/one.rs index 3c2e27e2293..64861176b91 100644 --- a/tests/source/issue-3270/one.rs +++ b/tests/source/issue-3270/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn main() { /* let s = String::from( diff --git a/tests/source/issue-3270/two.rs b/tests/source/issue-3270/two.rs index 0eb756471e7..1342cf03c39 100644 --- a/tests/source/issue-3270/two.rs +++ b/tests/source/issue-3270/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn main() { /* let s = String::from( diff --git a/tests/source/issue-3272/v1.rs b/tests/source/issue-3272/v1.rs index f4c1b7c992b..56dc048bf8a 100644 --- a/tests/source/issue-3272/v1.rs +++ b/tests/source/issue-3272/v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn main() { assert!(HAYSTACK diff --git a/tests/source/issue-3272/v2.rs b/tests/source/issue-3272/v2.rs index 0148368edc8..f3adbe37c76 100644 --- a/tests/source/issue-3272/v2.rs +++ b/tests/source/issue-3272/v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { assert!(HAYSTACK diff --git a/tests/source/issue-3278/version_one.rs b/tests/source/issue-3278/version_one.rs index 580679fbae3..718a32b4c7e 100644 --- a/tests/source/issue-3278/version_one.rs +++ b/tests/source/issue-3278/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn parse_conditional<'a, I: 'a>( ) -> impl Parser + 'a diff --git a/tests/source/issue-3278/version_two.rs b/tests/source/issue-3278/version_two.rs index c17b1742d39..eb605e509f9 100644 --- a/tests/source/issue-3278/version_two.rs +++ b/tests/source/issue-3278/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a diff --git a/tests/source/issue-3295/two.rs b/tests/source/issue-3295/two.rs index 0eaf022249b..ae3d2ec28c0 100644 --- a/tests/source/issue-3295/two.rs +++ b/tests/source/issue-3295/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub enum TestEnum { a, b, diff --git a/tests/source/issue-3302.rs b/tests/source/issue-3302.rs index c037584fd71..5e0862cb399 100644 --- a/tests/source/issue-3302.rs +++ b/tests/source/issue-3302.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 macro_rules! moo1 { () => { diff --git a/tests/source/issue-3701/one.rs b/tests/source/issue-3701/one.rs index a7f0bd3aa17..4e8518b6f18 100644 --- a/tests/source/issue-3701/one.rs +++ b/tests/source/issue-3701/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, diff --git a/tests/source/issue-3701/two.rs b/tests/source/issue-3701/two.rs index 8e15c58b8b2..d7cb790a754 100644 --- a/tests/source/issue-3701/two.rs +++ b/tests/source/issue-3701/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, diff --git a/tests/source/issue-3805.rs b/tests/source/issue-3805.rs index a0289b57974..aadc4a9dddc 100644 --- a/tests/source/issue-3805.rs +++ b/tests/source/issue-3805.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-format_macro_matchers: true // From original issue example - Line length 101 diff --git a/tests/source/issue-3840/version-two_hard-tabs.rs b/tests/source/issue-3840/version-two_hard-tabs.rs index 7b505fda87c..8d009eabdec 100644 --- a/tests/source/issue-3840/version-two_hard-tabs.rs +++ b/tests/source/issue-3840/version-two_hard-tabs.rs @@ -1,5 +1,5 @@ // rustfmt-hard_tabs: true -// rustfmt-version: Two +// rustfmt-style_edition: 2024 impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter { diff --git a/tests/source/issue-3840/version-two_soft-tabs.rs b/tests/source/issue-3840/version-two_soft-tabs.rs index 39c8ef31292..9e283d3be0a 100644 --- a/tests/source/issue-3840/version-two_soft-tabs.rs +++ b/tests/source/issue-3840/version-two_soft-tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 impl + FromEvent, A: Widget2, B: Widget2, C: for<'a> CtxFamily<'a>> Widget2 for WidgetEventLifter { diff --git a/tests/source/issue-4530.rs b/tests/source/issue-4530.rs index 9d2882abb3c..6b92122f0c0 100644 --- a/tests/source/issue-4530.rs +++ b/tests/source/issue-4530.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { let [aaaaaaaaaaaaaaaaaaaaaaaaaa, bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb, cccccccccccccccccccccccccc, ddddddddddddddddddddddddd] = panic!(); } diff --git a/tests/source/issue-4689/one.rs b/tests/source/issue-4689/one.rs index d048eb10fb1..bff090a3525 100644 --- a/tests/source/issue-4689/one.rs +++ b/tests/source/issue-4689/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Based on the issue description pub trait PrettyPrinter<'tcx>: diff --git a/tests/source/issue-4689/two.rs b/tests/source/issue-4689/two.rs index ea7feda825d..217535c046e 100644 --- a/tests/source/issue-4689/two.rs +++ b/tests/source/issue-4689/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Based on the issue description pub trait PrettyPrinter<'tcx>: diff --git a/tests/source/issue-5586.rs b/tests/source/issue-5586.rs index 9cf6c1d58dd..061ad4bdaa4 100644 --- a/tests/source/issue-5586.rs +++ b/tests/source/issue-5586.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { // sample 1 { diff --git a/tests/source/issue-5655/one.rs b/tests/source/issue-5655/one.rs index 1758ec56f8b..62df2655c29 100644 --- a/tests/source/issue-5655/one.rs +++ b/tests/source/issue-5655/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn foo(_: T) where diff --git a/tests/source/issue-5655/two.rs b/tests/source/issue-5655/two.rs index e37ebbea8af..bfe1d3813bb 100644 --- a/tests/source/issue-5655/two.rs +++ b/tests/source/issue-5655/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn foo(_: T) where diff --git a/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs b/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs index 5847afd9560..e61d34604a1 100644 --- a/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs +++ b/tests/source/issue-5801/comment_unexpectedly_wraps_before_max_width.rs @@ -1,7 +1,7 @@ // rustfmt-comment_width: 120 // rustfmt-wrap_comments: true // rustfmt-max_width: 120 -// rustfmt-version: One +// rustfmt-style_edition: 2015 /// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { diff --git a/tests/source/issue-5987/two.rs b/tests/source/issue-5987/two.rs index e20026b5565..98ed35c4f9a 100644 --- a/tests/source/issue-5987/two.rs +++ b/tests/source/issue-5987/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { trace!( diff --git a/tests/source/issue-6147/case_rustfmt_v1.rs b/tests/source/issue-6147/case_rustfmt_v1.rs index 2ac2e0361c3..bcae86aaff2 100644 --- a/tests/source/issue-6147/case_rustfmt_v1.rs +++ b/tests/source/issue-6147/case_rustfmt_v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn main() { let a = Some(12); diff --git a/tests/source/issue-6147/case_rustfmt_v2.rs b/tests/source/issue-6147/case_rustfmt_v2.rs index c1bf1ad4bf8..da612b213fc 100644 --- a/tests/source/issue-6147/case_rustfmt_v2.rs +++ b/tests/source/issue-6147/case_rustfmt_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn main() { let a = Some(12); diff --git a/tests/source/issue_5027.rs b/tests/source/issue_5027.rs index 67beeb23b71..a47d6df6f0f 100644 --- a/tests/source/issue_5027.rs +++ b/tests/source/issue_5027.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub type Iter<'a, D> = impl DoubleEndedIterator)>+ ExactSizeIterator+ 'a; diff --git a/tests/source/let_else_v2.rs b/tests/source/let_else_v2.rs index a420fbcf95b..23be32d629a 100644 --- a/tests/source/let_else_v2.rs +++ b/tests/source/let_else_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-single_line_let_else_max_width: 100 fn issue5901() { diff --git a/tests/source/long-fn-1/version_one.rs b/tests/source/long-fn-1/version_one.rs index d6832c2af09..60083024810 100644 --- a/tests/source/long-fn-1/version_one.rs +++ b/tests/source/long-fn-1/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/source/long-fn-1/version_two.rs b/tests/source/long-fn-1/version_two.rs index f402a26e8b6..bce2c551c6a 100644 --- a/tests/source/long-fn-1/version_two.rs +++ b/tests/source/long-fn-1/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/source/one_line_if_v1.rs b/tests/source/one_line_if_v1.rs index d3dcbe6787a..bf7bc75fb88 100644 --- a/tests/source/one_line_if_v1.rs +++ b/tests/source/one_line_if_v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn plain_if(x: bool) -> u8 { if x { diff --git a/tests/source/one_line_if_v2.rs b/tests/source/one_line_if_v2.rs index 40c834959f9..f3c974b12db 100644 --- a/tests/source/one_line_if_v2.rs +++ b/tests/source/one_line_if_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn plain_if(x: bool) -> u8 { if x { diff --git a/tests/source/single-line-macro/v1.rs b/tests/source/single-line-macro/v1.rs index a3aa631ed4a..fea146d8d33 100644 --- a/tests/source/single-line-macro/v1.rs +++ b/tests/source/single-line-macro/v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // #2652 // Preserve trailing comma inside macro, even if it looks an array. diff --git a/tests/source/single-line-macro/v2.rs b/tests/source/single-line-macro/v2.rs index 51a665f7560..d9fba64ac70 100644 --- a/tests/source/single-line-macro/v2.rs +++ b/tests/source/single-line-macro/v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // #2652 // Preserve trailing comma inside macro, even if it looks an array. diff --git a/tests/source/trailing_comments/hard_tabs.rs b/tests/source/trailing_comments/hard_tabs.rs index 88249aa5fb9..c6d1b3f0ab7 100644 --- a/tests/source/trailing_comments/hard_tabs.rs +++ b/tests/source/trailing_comments/hard_tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true diff --git a/tests/source/trailing_comments/soft_tabs.rs b/tests/source/trailing_comments/soft_tabs.rs index 7845f713b8a..431875989f3 100644 --- a/tests/source/trailing_comments/soft_tabs.rs +++ b/tests/source/trailing_comments/soft_tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-wrap_comments: true pub const IFF_MULTICAST: ::c_int = 0x0000000800; // Supports multicast diff --git a/tests/source/tuple_v2.rs b/tests/source/tuple_v2.rs index 9223033832b..6dc18e00d7e 100644 --- a/tests/source/tuple_v2.rs +++ b/tests/source/tuple_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn issue_4355() { let _ = ((1,),).0 .0; diff --git a/tests/target/arrow_in_comments/arrow_in_single_comment.rs b/tests/target/arrow_in_comments/arrow_in_single_comment.rs index deffdbeeaaf..d638a6b4ef0 100644 --- a/tests/target/arrow_in_comments/arrow_in_single_comment.rs +++ b/tests/target/arrow_in_comments/arrow_in_single_comment.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { match a { _ => diff --git a/tests/target/arrow_in_comments/multiple_arrows.rs b/tests/target/arrow_in_comments/multiple_arrows.rs index b0443411816..f6f4a60eec3 100644 --- a/tests/target/arrow_in_comments/multiple_arrows.rs +++ b/tests/target/arrow_in_comments/multiple_arrows.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { match a { _ => diff --git a/tests/target/fn-single-line/version_one.rs b/tests/target/fn-single-line/version_one.rs index 013b2cd7216..5b704474d6d 100644 --- a/tests/target/fn-single-line/version_one.rs +++ b/tests/target/fn-single-line/version_one.rs @@ -1,5 +1,5 @@ // rustfmt-fn_single_line: true -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Test single-line functions. fn foo_expr() { 1 } diff --git a/tests/target/fn-single-line/version_two.rs b/tests/target/fn-single-line/version_two.rs index b8053d4c2f5..aedd1d481b6 100644 --- a/tests/target/fn-single-line/version_two.rs +++ b/tests/target/fn-single-line/version_two.rs @@ -1,5 +1,5 @@ // rustfmt-fn_single_line: true -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Test single-line functions. fn foo_expr() { 1 } diff --git a/tests/target/issue-2179/one.rs b/tests/target/issue-2179/one.rs index 3f98acc8dcd..6593624e589 100644 --- a/tests/target/issue-2179/one.rs +++ b/tests/target/issue-2179/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/target/issue-2179/two.rs b/tests/target/issue-2179/two.rs index 96531509ea2..088518705fe 100644 --- a/tests/target/issue-2179/two.rs +++ b/tests/target/issue-2179/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-error_on_line_overflow: false fn issue_2179() { diff --git a/tests/target/issue-3132.rs b/tests/target/issue-3132.rs index 4dffe0ab836..4d61baa7507 100644 --- a/tests/target/issue-3132.rs +++ b/tests/target/issue-3132.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn test() { /* diff --git a/tests/target/issue-3213/version_one.rs b/tests/target/issue-3213/version_one.rs index 307903b128b..a20915df761 100644 --- a/tests/target/issue-3213/version_one.rs +++ b/tests/target/issue-3213/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn foo() { match 0 { diff --git a/tests/target/issue-3213/version_two.rs b/tests/target/issue-3213/version_two.rs index de93d04ba95..fb609f6a67a 100644 --- a/tests/target/issue-3213/version_two.rs +++ b/tests/target/issue-3213/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn foo() { match 0 { diff --git a/tests/target/issue-3227/one.rs b/tests/target/issue-3227/one.rs index fcc8331000d..2922bfdfef7 100644 --- a/tests/target/issue-3227/one.rs +++ b/tests/target/issue-3227/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn main() { thread::spawn(|| { diff --git a/tests/target/issue-3227/two.rs b/tests/target/issue-3227/two.rs index 374ab54305d..ae7eee47194 100644 --- a/tests/target/issue-3227/two.rs +++ b/tests/target/issue-3227/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { thread::spawn(|| { diff --git a/tests/target/issue-3270/one.rs b/tests/target/issue-3270/one.rs index 78de9473243..a31a0ff5742 100644 --- a/tests/target/issue-3270/one.rs +++ b/tests/target/issue-3270/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn main() { /* let s = String::from( diff --git a/tests/target/issue-3270/two.rs b/tests/target/issue-3270/two.rs index e48b5921329..8e26f8ac23d 100644 --- a/tests/target/issue-3270/two.rs +++ b/tests/target/issue-3270/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn main() { /* let s = String::from( diff --git a/tests/target/issue-3270/wrap.rs b/tests/target/issue-3270/wrap.rs index 7435c5f0866..967bfb5534c 100644 --- a/tests/target/issue-3270/wrap.rs +++ b/tests/target/issue-3270/wrap.rs @@ -1,5 +1,5 @@ // rustfmt-wrap_comments: true -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // check that a line below max_width does not get over the limit when wrapping // it in a block comment diff --git a/tests/target/issue-3272/v1.rs b/tests/target/issue-3272/v1.rs index aab201027d5..7cca7ea7896 100644 --- a/tests/target/issue-3272/v1.rs +++ b/tests/target/issue-3272/v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn main() { assert!(HAYSTACK diff --git a/tests/target/issue-3272/v2.rs b/tests/target/issue-3272/v2.rs index a42a2fccd5b..ca7718c5a61 100644 --- a/tests/target/issue-3272/v2.rs +++ b/tests/target/issue-3272/v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { assert!( diff --git a/tests/target/issue-3278/version_one.rs b/tests/target/issue-3278/version_one.rs index 580679fbae3..718a32b4c7e 100644 --- a/tests/target/issue-3278/version_one.rs +++ b/tests/target/issue-3278/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn parse_conditional<'a, I: 'a>( ) -> impl Parser + 'a diff --git a/tests/target/issue-3278/version_two.rs b/tests/target/issue-3278/version_two.rs index c17b1742d39..eb605e509f9 100644 --- a/tests/target/issue-3278/version_two.rs +++ b/tests/target/issue-3278/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn parse_conditional<'a, I: 'a>() -> impl Parser + 'a diff --git a/tests/target/issue-3295/two.rs b/tests/target/issue-3295/two.rs index 3e669a0bb75..4f685172cfa 100644 --- a/tests/target/issue-3295/two.rs +++ b/tests/target/issue-3295/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub enum TestEnum { a, b, diff --git a/tests/target/issue-3302.rs b/tests/target/issue-3302.rs index 146cb983819..504bfd987f5 100644 --- a/tests/target/issue-3302.rs +++ b/tests/target/issue-3302.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 macro_rules! moo1 { () => { diff --git a/tests/target/issue-3614/version_one.rs b/tests/target/issue-3614/version_one.rs index 8ab28304732..4bd972aa87a 100644 --- a/tests/target/issue-3614/version_one.rs +++ b/tests/target/issue-3614/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn main() { let toto = || { diff --git a/tests/target/issue-3614/version_two.rs b/tests/target/issue-3614/version_two.rs index 5d6f8e7a313..7b9534caa02 100644 --- a/tests/target/issue-3614/version_two.rs +++ b/tests/target/issue-3614/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { let toto = || { diff --git a/tests/target/issue-3701/one.rs b/tests/target/issue-3701/one.rs index 9d1ef9eed9a..b154724d341 100644 --- a/tests/target/issue-3701/one.rs +++ b/tests/target/issue-3701/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, diff --git a/tests/target/issue-3701/two.rs b/tests/target/issue-3701/two.rs index 62ffc9d823d..995763ef291 100644 --- a/tests/target/issue-3701/two.rs +++ b/tests/target/issue-3701/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn build_sorted_static_get_entry_names( mut entries: Vec<(u8, &'static str)>, diff --git a/tests/target/issue-3805.rs b/tests/target/issue-3805.rs index a247a43fe6d..a1eda832d76 100644 --- a/tests/target/issue-3805.rs +++ b/tests/target/issue-3805.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-format_macro_matchers: true // From original issue example - Line length 101 diff --git a/tests/target/issue-3840/version-two_hard-tabs.rs b/tests/target/issue-3840/version-two_hard-tabs.rs index 084db3d1465..78a2f921735 100644 --- a/tests/target/issue-3840/version-two_hard-tabs.rs +++ b/tests/target/issue-3840/version-two_hard-tabs.rs @@ -1,5 +1,5 @@ // rustfmt-hard_tabs: true -// rustfmt-version: Two +// rustfmt-style_edition: 2024 impl< Target: FromEvent + FromEvent, diff --git a/tests/target/issue-3840/version-two_soft-tabs.rs b/tests/target/issue-3840/version-two_soft-tabs.rs index bc59b0baa56..c76dd4dafbb 100644 --- a/tests/target/issue-3840/version-two_soft-tabs.rs +++ b/tests/target/issue-3840/version-two_soft-tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 impl< Target: FromEvent + FromEvent, diff --git a/tests/target/issue-3882.rs b/tests/target/issue-3882.rs index 5eb442af974..8e617635b7c 100644 --- a/tests/target/issue-3882.rs +++ b/tests/target/issue-3882.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn bar(_t: T, // bar ) { } diff --git a/tests/target/issue-4530.rs b/tests/target/issue-4530.rs index 296dc559a93..9e9fbf95c2d 100644 --- a/tests/target/issue-4530.rs +++ b/tests/target/issue-4530.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { let [ aaaaaaaaaaaaaaaaaaaaaaaaaa, diff --git a/tests/target/issue-4689/one.rs b/tests/target/issue-4689/one.rs index 7735e34f3b5..fb523f38501 100644 --- a/tests/target/issue-4689/one.rs +++ b/tests/target/issue-4689/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Based on the issue description pub trait PrettyPrinter<'tcx>: diff --git a/tests/target/issue-4689/two.rs b/tests/target/issue-4689/two.rs index e3b5cd22810..30303490129 100644 --- a/tests/target/issue-4689/two.rs +++ b/tests/target/issue-4689/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Based on the issue description pub trait PrettyPrinter<'tcx>: diff --git a/tests/target/issue-5586.rs b/tests/target/issue-5586.rs index 7033ae975b3..afe13d1fb1c 100644 --- a/tests/target/issue-5586.rs +++ b/tests/target/issue-5586.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { // sample 1 { diff --git a/tests/target/issue-5655/one.rs b/tests/target/issue-5655/one.rs index 1758ec56f8b..62df2655c29 100644 --- a/tests/target/issue-5655/one.rs +++ b/tests/target/issue-5655/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn foo(_: T) where diff --git a/tests/target/issue-5655/two.rs b/tests/target/issue-5655/two.rs index 14fbc3d1321..4a7eb4f4bc2 100644 --- a/tests/target/issue-5655/two.rs +++ b/tests/target/issue-5655/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn foo(_: T) where diff --git a/tests/target/issue-5801/comment_does_not_wrap_within_max_width.rs b/tests/target/issue-5801/comment_does_not_wrap_within_max_width.rs index 9f294751108..461b5873a68 100644 --- a/tests/target/issue-5801/comment_does_not_wrap_within_max_width.rs +++ b/tests/target/issue-5801/comment_does_not_wrap_within_max_width.rs @@ -1,7 +1,7 @@ // rustfmt-comment_width: 120 // rustfmt-wrap_comments: true // rustfmt-max_width: 120 -// rustfmt-version: Two +// rustfmt-style_edition: 2024 /// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { diff --git a/tests/target/issue-5801/comment_unexpectedly_wraps_before_max_width.rs b/tests/target/issue-5801/comment_unexpectedly_wraps_before_max_width.rs index dd839dd4548..58bb8a1c2e3 100644 --- a/tests/target/issue-5801/comment_unexpectedly_wraps_before_max_width.rs +++ b/tests/target/issue-5801/comment_unexpectedly_wraps_before_max_width.rs @@ -1,7 +1,7 @@ // rustfmt-comment_width: 120 // rustfmt-wrap_comments: true // rustfmt-max_width: 120 -// rustfmt-version: One +// rustfmt-style_edition: 2015 /// This function is 120 columns wide and is left alone. This comment is 120 columns wide and the formatter is also fine fn my_super_cool_function_name(my_very_cool_argument_name: String, my_other_very_cool_argument_name: String) -> String { diff --git a/tests/target/issue-5987/one.rs b/tests/target/issue-5987/one.rs index 3c995ed28ba..17327feead5 100644 --- a/tests/target/issue-5987/one.rs +++ b/tests/target/issue-5987/one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn main() { trace!( diff --git a/tests/target/issue-5987/two.rs b/tests/target/issue-5987/two.rs index 8fd92fc179e..41ecb13e3db 100644 --- a/tests/target/issue-5987/two.rs +++ b/tests/target/issue-5987/two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn main() { trace!( diff --git a/tests/target/issue-6147/case_rustfmt_v1.rs b/tests/target/issue-6147/case_rustfmt_v1.rs index 75800012c63..d8e67655e4c 100644 --- a/tests/target/issue-6147/case_rustfmt_v1.rs +++ b/tests/target/issue-6147/case_rustfmt_v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 pub fn main() { let a = Some(12); diff --git a/tests/target/issue-6147/case_rustfmt_v2.rs b/tests/target/issue-6147/case_rustfmt_v2.rs index 5e4220e7306..9d0b12d686b 100644 --- a/tests/target/issue-6147/case_rustfmt_v2.rs +++ b/tests/target/issue-6147/case_rustfmt_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub fn main() { let a = Some(12); diff --git a/tests/target/issue_5027.rs b/tests/target/issue_5027.rs index 26d771720b6..1de3e0d4f15 100644 --- a/tests/target/issue_5027.rs +++ b/tests/target/issue_5027.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 pub type Iter<'a, D> = impl DoubleEndedIterator)> + ExactSizeIterator diff --git a/tests/target/let_else_v2.rs b/tests/target/let_else_v2.rs index b25ac1609d8..6e886299cb0 100644 --- a/tests/target/let_else_v2.rs +++ b/tests/target/let_else_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-single_line_let_else_max_width: 100 fn issue5901() { diff --git a/tests/target/long-fn-1/version_one.rs b/tests/target/long-fn-1/version_one.rs index 05f69953c26..60f672c1837 100644 --- a/tests/target/long-fn-1/version_one.rs +++ b/tests/target/long-fn-1/version_one.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/target/long-fn-1/version_two.rs b/tests/target/long-fn-1/version_two.rs index 32794bccde2..f6007398bcc 100644 --- a/tests/target/long-fn-1/version_two.rs +++ b/tests/target/long-fn-1/version_two.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // Tests that a function which is almost short enough, but not quite, gets // formatted correctly. diff --git a/tests/target/one_line_if_v1.rs b/tests/target/one_line_if_v1.rs index b3c6c4cbeb2..5160ea0264c 100644 --- a/tests/target/one_line_if_v1.rs +++ b/tests/target/one_line_if_v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 fn plain_if(x: bool) -> u8 { if x { diff --git a/tests/target/one_line_if_v2.rs b/tests/target/one_line_if_v2.rs index 81ca4c8b8b4..a9610ec9749 100644 --- a/tests/target/one_line_if_v2.rs +++ b/tests/target/one_line_if_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn plain_if(x: bool) -> u8 { if x { 0 } else { 1 } diff --git a/tests/target/single-line-macro/v1.rs b/tests/target/single-line-macro/v1.rs index a3aa631ed4a..fea146d8d33 100644 --- a/tests/target/single-line-macro/v1.rs +++ b/tests/target/single-line-macro/v1.rs @@ -1,4 +1,4 @@ -// rustfmt-version: One +// rustfmt-style_edition: 2015 // #2652 // Preserve trailing comma inside macro, even if it looks an array. diff --git a/tests/target/single-line-macro/v2.rs b/tests/target/single-line-macro/v2.rs index 9c6bcf33ad5..6fcacb70ba3 100644 --- a/tests/target/single-line-macro/v2.rs +++ b/tests/target/single-line-macro/v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // #2652 // Preserve trailing comma inside macro, even if it looks an array. diff --git a/tests/target/trailing_comments/hard_tabs.rs b/tests/target/trailing_comments/hard_tabs.rs index 35e72f1affd..e7009ac00c0 100644 --- a/tests/target/trailing_comments/hard_tabs.rs +++ b/tests/target/trailing_comments/hard_tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-wrap_comments: true // rustfmt-hard_tabs: true diff --git a/tests/target/trailing_comments/soft_tabs.rs b/tests/target/trailing_comments/soft_tabs.rs index eba943042ad..34cfed1a229 100644 --- a/tests/target/trailing_comments/soft_tabs.rs +++ b/tests/target/trailing_comments/soft_tabs.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 // rustfmt-wrap_comments: true pub const IFF_MULTICAST: ::c_int = 0x0000000800; // Supports multicast diff --git a/tests/target/tuple_v2.rs b/tests/target/tuple_v2.rs index ba653291c2f..fa508332be5 100644 --- a/tests/target/tuple_v2.rs +++ b/tests/target/tuple_v2.rs @@ -1,4 +1,4 @@ -// rustfmt-version: Two +// rustfmt-style_edition: 2024 fn issue_4355() { let _ = ((1,),).0.0; From 0f53d2b2471e4fb0422043116de8bc8dc071c596 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Fri, 19 Jul 2024 18:31:18 -0500 Subject: [PATCH 6/9] docs: use StyleEdition in dev guide s --- Contributing.md | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/Contributing.md b/Contributing.md index 2f2ccfb175a..85754a8658a 100644 --- a/Contributing.md +++ b/Contributing.md @@ -109,17 +109,17 @@ If you want to test modified `cargo-fmt`, or run `rustfmt` on the whole project RUSTFMT="./target/debug/rustfmt" cargo run --bin cargo-fmt -- --manifest-path path/to/project/you/want2test/Cargo.toml ``` -### Version-gate formatting changes +### Gate formatting changes -A change that introduces a different code-formatting should be gated on the -`version` configuration. This is to ensure the formatting of the current major -release is preserved, while allowing fixes to be implemented for the next -release. +A change that introduces a different code-formatting must be gated on the +`style_edition` configuration. This is to ensure rustfmt upholds its formatting +stability guarantees and adheres to the Style Edition process set in [RFC 3338] -This is done by conditionally guarding the change like so: +This can be done by conditionally guarding the formatting change, e.g.: ```rust -if config.version() == Version::One { // if the current major release is 1.x +// if the current stable Style Edition is Edition 2024 +if config.style_edition() <= StyleEdition::Edition2024 { // current formatting } else { // new formatting @@ -129,13 +129,14 @@ if config.version() == Version::One { // if the current major release is 1.x This allows the user to apply the next formatting explicitly via the configuration, while being stable by default. -When the next major release is done, the code block of the previous formatting -can be deleted, e.g., the first block in the example above when going from `1.x` -to `2.x`. +This can then be enhanced as needed if and when there are +new Style Editions with differing formatting prescriptions. | Note: Only formatting changes with default options need to be gated. | | --- | +[RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html + ### A quick tour of Rustfmt Rustfmt is basically a pretty printer - that is, its mode of operation is to From 1f8c5eb70542027bcf8ca02ccd01bd5257235213 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sat, 27 Jul 2024 17:56:03 -0500 Subject: [PATCH 7/9] refactor: rebase with set_cli() behavior --- src/bin/main.rs | 2 +- src/config/config_type.rs | 9 +++++++-- src/config/mod.rs | 1 + src/config/options.rs | 3 ++- 4 files changed, 11 insertions(+), 4 deletions(-) diff --git a/src/bin/main.rs b/src/bin/main.rs index 2b5d5209b4f..0876c515dde 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -708,7 +708,7 @@ impl CliOptions for GetOptsOptions { config.set_cli().edition(edition); } if let Some(edition) = self.style_edition { - config.set().style_edition(edition); + config.set_cli().style_edition(edition); } if self.check { config.set_cli().emit_mode(EmitMode::Diff); diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 3a3500e4ef8..43f014764c9 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -164,6 +164,8 @@ macro_rules! create_config { "merge_imports" => self.0.set_merge_imports(), "fn_args_layout" => self.0.set_fn_args_layout(), "hide_parse_errors" => self.0.set_hide_parse_errors(), + "version" => self.0.set_version(), + "edition" => self.0.set_edition(), &_ => (), } } @@ -576,7 +578,7 @@ macro_rules! create_config { Use `style_edition` instead." ); - if self.was_set().style_edition() { + if self.was_set().style_edition() || self.was_set_cli().style_edition() { eprintln!( "Warning: the deprecated `version` option was \ used in conjunction with the `edition` or \ @@ -591,7 +593,10 @@ macro_rules! create_config { } fn set_edition(&mut self) { - if self.was_set().style_edition() || self.was_set().version() { + let style_edition_set = self.was_set().style_edition() + || self.was_set_cli().style_edition(); + + if style_edition_set || self.was_set().version() { return; } diff --git a/src/config/mod.rs b/src/config/mod.rs index 9103a4859ab..e4690e5beca 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -779,6 +779,7 @@ match_block_trailing_comma = false blank_lines_upper_bound = 1 blank_lines_lower_bound = 0 edition = "2015" +style_edition = "2024" version = "Two" inline_attribute_width = 0 format_generated_files = true diff --git a/src/config/options.rs b/src/config/options.rs index 7c0a3609775..65fc702c4bc 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -638,7 +638,8 @@ config_option_with_style_edition_default!( BlankLinesUpperBound, usize, _ => 1; BlankLinesLowerBound, usize, _ => 0; EditionConfig, Edition, _ => Edition::Edition2015; - StyleEditionConfig, StyleEdition, _ => StyleEdition::Edition2015; + StyleEditionConfig, StyleEdition, + Edition2024 => StyleEdition::Edition2024, _ => StyleEdition::Edition2015; VersionConfig, Version, Edition2024 => Version::Two, _ => Version::One; InlineAttributeWidth, usize, _ => 0; FormatGeneratedFiles, bool, _ => true; From 85059eef4bfa5773a5a22e4c8b0db83eda9884e6 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sun, 28 Jul 2024 16:03:46 -0500 Subject: [PATCH 8/9] tests: add new load_config tests --- src/bin/main.rs | 138 ++++++++++++++++++ .../just-style-edition/rustfmt.toml | 1 + .../style-edition-and-edition/rustfmt.toml | 2 + .../version-edition/rustfmt.toml | 2 + .../rustfmt.toml | 3 + .../version-style-edition/rustfmt.toml | 2 + 6 files changed, 148 insertions(+) create mode 100644 tests/config/style-edition/just-style-edition/rustfmt.toml create mode 100644 tests/config/style-edition/style-edition-and-edition/rustfmt.toml create mode 100644 tests/config/style-edition/version-edition/rustfmt.toml create mode 100644 tests/config/style-edition/version-style-edition-and-edition/rustfmt.toml create mode 100644 tests/config/style-edition/version-style-edition/rustfmt.toml diff --git a/src/bin/main.rs b/src/bin/main.rs index 0876c515dde..6959f56ccc7 100644 --- a/src/bin/main.rs +++ b/src/bin/main.rs @@ -765,3 +765,141 @@ fn emit_mode_from_emit_str(emit_str: &str) -> Result { _ => Err(format_err!("Invalid value for `--emit`")), } } + +#[cfg(test)] +#[allow(dead_code)] +mod test { + use super::*; + use rustfmt_config_proc_macro::nightly_only_test; + + fn get_config(path: Option<&Path>, options: Option) -> Config { + load_config(path, options).unwrap().0 + } + + #[nightly_only_test] + #[test] + fn flag_sets_style_edition_override_correctly() { + let mut options = GetOptsOptions::default(); + options.style_edition = Some(StyleEdition::Edition2024); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn edition_sets_style_edition_override_correctly() { + let mut options = GetOptsOptions::default(); + options.edition = Some(Edition::Edition2024); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn version_sets_style_edition_override_correctly() { + let mut options = GetOptsOptions::default(); + options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn style_edition_flag_has_correct_precedence_over_edition() { + let mut options = GetOptsOptions::default(); + options.style_edition = Some(StyleEdition::Edition2021); + options.edition = Some(Edition::Edition2024); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2021); + } + + #[nightly_only_test] + #[test] + fn style_edition_flag_has_correct_precedence_over_version() { + let mut options = GetOptsOptions::default(); + options.style_edition = Some(StyleEdition::Edition2018); + options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2018); + } + + #[nightly_only_test] + #[test] + fn style_edition_flag_has_correct_precedence_over_edition_version() { + let mut options = GetOptsOptions::default(); + options.style_edition = Some(StyleEdition::Edition2021); + options.edition = Some(Edition::Edition2018); + options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2021); + } + + #[nightly_only_test] + #[test] + fn style_edition_inline_has_correct_precedence_over_edition_version() { + let mut options = GetOptsOptions::default(); + options.edition = Some(Edition::Edition2018); + options.inline_config = HashMap::from([ + ("version".to_owned(), "One".to_owned()), + ("style_edition".to_owned(), "2024".to_owned()), + ]); + let config = get_config(None, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn style_edition_config_file_trumps_edition_flag_version_inline() { + let mut options = GetOptsOptions::default(); + let config_file = Some(Path::new("tests/config/style-edition/just-style-edition")); + options.edition = Some(Edition::Edition2018); + options.inline_config = HashMap::from([("version".to_owned(), "One".to_owned())]); + let config = get_config(config_file, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn style_edition_config_file_trumps_edition_config_and_version_inline() { + let mut options = GetOptsOptions::default(); + let config_file = Some(Path::new( + "tests/config/style-edition/style-edition-and-edition", + )); + options.inline_config = HashMap::from([("version".to_owned(), "Two".to_owned())]); + let config = get_config(config_file, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2021); + assert_eq!(config.edition(), Edition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn version_config_trumps_edition_config_and_flag() { + let mut options = GetOptsOptions::default(); + let config_file = Some(Path::new("tests/config/style-edition/version-edition")); + options.edition = Some(Edition::Edition2018); + let config = get_config(config_file, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2024); + } + + #[nightly_only_test] + #[test] + fn style_edition_config_file_trumps_version_config() { + let options = GetOptsOptions::default(); + let config_file = Some(Path::new( + "tests/config/style-edition/version-style-edition", + )); + let config = get_config(config_file, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2021); + } + + #[nightly_only_test] + #[test] + fn style_edition_config_file_trumps_edition_version_config() { + let options = GetOptsOptions::default(); + let config_file = Some(Path::new( + "tests/config/style-edition/version-style-edition-and-edition", + )); + let config = get_config(config_file, Some(options)); + assert_eq!(config.style_edition(), StyleEdition::Edition2021); + } +} diff --git a/tests/config/style-edition/just-style-edition/rustfmt.toml b/tests/config/style-edition/just-style-edition/rustfmt.toml new file mode 100644 index 00000000000..3501136812c --- /dev/null +++ b/tests/config/style-edition/just-style-edition/rustfmt.toml @@ -0,0 +1 @@ +style_edition = "2024" diff --git a/tests/config/style-edition/style-edition-and-edition/rustfmt.toml b/tests/config/style-edition/style-edition-and-edition/rustfmt.toml new file mode 100644 index 00000000000..92844e03ab6 --- /dev/null +++ b/tests/config/style-edition/style-edition-and-edition/rustfmt.toml @@ -0,0 +1,2 @@ +style_edition = "2021" +edition = "2024" diff --git a/tests/config/style-edition/version-edition/rustfmt.toml b/tests/config/style-edition/version-edition/rustfmt.toml new file mode 100644 index 00000000000..16ea9a13f36 --- /dev/null +++ b/tests/config/style-edition/version-edition/rustfmt.toml @@ -0,0 +1,2 @@ +version = "Two" +edition = "2018" diff --git a/tests/config/style-edition/version-style-edition-and-edition/rustfmt.toml b/tests/config/style-edition/version-style-edition-and-edition/rustfmt.toml new file mode 100644 index 00000000000..187ba13cfb6 --- /dev/null +++ b/tests/config/style-edition/version-style-edition-and-edition/rustfmt.toml @@ -0,0 +1,3 @@ +version = "Two" +edition = "2018" +style_edition = "2021" diff --git a/tests/config/style-edition/version-style-edition/rustfmt.toml b/tests/config/style-edition/version-style-edition/rustfmt.toml new file mode 100644 index 00000000000..c894bd981bc --- /dev/null +++ b/tests/config/style-edition/version-style-edition/rustfmt.toml @@ -0,0 +1,2 @@ +version = "Two" +style_edition = "2021" From 3a6eb5c55923b3446faf7654cacf3810d57c3c55 Mon Sep 17 00:00:00 2001 From: Caleb Cartwright Date: Sun, 28 Jul 2024 18:58:38 -0500 Subject: [PATCH 9/9] chore: apply review suggestions --- Configurations.md | 2 +- src/config/config_type.rs | 4 ++-- src/overflow.rs | 8 ++++++-- 3 files changed, 9 insertions(+), 5 deletions(-) diff --git a/Configurations.md b/Configurations.md index ec95c82fdb1..b1f54060392 100644 --- a/Configurations.md +++ b/Configurations.md @@ -2698,7 +2698,7 @@ Controls the edition of the [Rust Style Guide] to use for formatting ([RFC 3338] - **Default value**: `"2015"` - **Possible values**: `"2015"`, `"2018"`, `"2021"`, `"2024"` (unstable variant) -- **Stable**: Yes +- **Stable**: No [Rust Style Guide]: https://doc.rust-lang.org/nightly/style-guide/ [RFC 3338]: https://rust-lang.github.io/rfcs/3338-style-evolution.html diff --git a/src/config/config_type.rs b/src/config/config_type.rs index 43f014764c9..91efb71744b 100644 --- a/src/config/config_type.rs +++ b/src/config/config_type.rs @@ -581,8 +581,8 @@ macro_rules! create_config { if self.was_set().style_edition() || self.was_set_cli().style_edition() { eprintln!( "Warning: the deprecated `version` option was \ - used in conjunction with the `edition` or \ - `style_edition` options which take precedence. \ + used in conjunction with the `style_edition` \ + option which takes precedence. \ The value of the `version` option will be ignored." ); } else if matches!(self.version(), Version::Two) { diff --git a/src/overflow.rs b/src/overflow.rs index 368a8aaec75..510ad3c642e 100644 --- a/src/overflow.rs +++ b/src/overflow.rs @@ -200,8 +200,12 @@ impl<'a> OverflowableItem<'a> { OverflowableItem::NestedMetaItem(..) => SPECIAL_CASE_ATTR, _ => &[], }; - let additional_cases = match (self, config.style_edition()) { - (OverflowableItem::MacroArg(..), StyleEdition::Edition2024) => SPECIAL_CASE_MACROS_V2, + let additional_cases = match self { + OverflowableItem::MacroArg(..) + if config.style_edition() >= StyleEdition::Edition2024 => + { + SPECIAL_CASE_MACROS_V2 + } _ => &[], }; base_cases.iter().chain(additional_cases)