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