diff --git a/CHANGELOG.md b/CHANGELOG.md index 836b2fd81a1..be4e6c42074 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,9 +2,12 @@ ## [Unreleased] +### Changed + - Change option `format_doc_comment` to `format_code_in_doc_comment`. - `use_small_heuristics` changed to be an enum and stabilised. Configuration options are now ready for 1.0. +- Stabilise `fn_args_density` configuration option and rename it to `fn_args_layout` #3581 ## [1.2.2] 2019-04-24 diff --git a/Configurations.md b/Configurations.md index 3737b1c9a4e..304bc690034 100644 --- a/Configurations.md +++ b/Configurations.md @@ -629,13 +629,13 @@ trailing whitespaces. - **Possible values**: `true`, `false` - **Stable**: No (tracking issue: #3392) -## `fn_args_density` +## `fn_args_layout` -Argument density in functions +Control the layout of arguments in a function - **Default value**: `"Tall"` - **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"` -- **Stable**: No (tracking issue: #3375) +- **Stable**: Yes #### `"Tall"` (default): diff --git a/Processes.md b/Processes.md index 3f1c07c52b3..9d86d52b122 100644 --- a/Processes.md +++ b/Processes.md @@ -17,6 +17,7 @@ Open a pull request that closes the tracking issue. The tracking issue is listed - Update the `Config` enum marking the option as stable. - Update the the `Configuration.md` file marking the option as stable. +- Update `CHANGELOG.md` marking the option as stable. ## After the stabilisation diff --git a/src/config/mod.rs b/src/config/mod.rs index eaa6d012d5b..1b9e97fc5bf 100644 --- a/src/config/mod.rs +++ b/src/config/mod.rs @@ -92,7 +92,8 @@ create_config! { the same line with the pattern of arms"; force_multiline_blocks: bool, false, false, "Force multiline closure bodies and match arms to be wrapped in a block"; - fn_args_density: Density, Density::Tall, false, "Argument density in functions"; + fn_args_layout: Density, Density::Tall, true, + "Control the layout of arguments in a function"; brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items"; control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false, "Brace style for control flow constructs"; @@ -501,7 +502,7 @@ struct_field_align_threshold = 0 enum_discrim_align_threshold = 0 match_arm_blocks = true force_multiline_blocks = false -fn_args_density = "Tall" +fn_args_layout = "Tall" brace_style = "SameLineWhere" control_brace_style = "AlwaysSameLine" trailing_semicolon = true diff --git a/src/config/options.rs b/src/config/options.rs index 72acaacd348..663c5d4dee2 100644 --- a/src/config/options.rs +++ b/src/config/options.rs @@ -58,10 +58,11 @@ pub enum IndentStyle { #[config_type] /// How to place a list-like items. +/// FIXME: Issue-3581: this should be renamed to ItemsLayout when publishing 2.0 pub enum Density { /// Fit as much on one line as possible. Compressed, - /// Use more lines. + /// Items are placed horizontally if sufficient space, vertically otherwise. Tall, /// Place every item on a separate line. Vertical, diff --git a/src/items.rs b/src/items.rs index 7640fa32d22..ea0475ccc57 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, Density, IndentStyle, Version}; +use crate::config::{BraceStyle, Config, IndentStyle, Version}; use crate::expr::{ format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with, ExprType, RhsTactics, @@ -703,7 +703,7 @@ pub(crate) fn format_impl( &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), - Density::Vertical, + false, "{", where_span_end, self_ty.span.hi(), @@ -1044,11 +1044,7 @@ pub(crate) fn format_trait( // Rewrite where-clause. if !generics.where_clause.predicates.is_empty() { - let where_density = if context.config.indent_style() == IndentStyle::Block { - Density::Compressed - } else { - Density::Tall - }; + let where_on_new_line = context.config.indent_style() != IndentStyle::Block; let where_budget = context.budget(last_line_width(&result)); let pos_before_where = if generic_bounds.is_empty() { @@ -1062,7 +1058,7 @@ pub(crate) fn format_trait( &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), - where_density, + where_on_new_line, "{", None, pos_before_where, @@ -1171,7 +1167,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> { &self.generics.where_clause, context.config.brace_style(), shape, - Density::Compressed, + false, ";", None, self.generics.where_clause.span.lo(), @@ -1423,7 +1419,7 @@ fn format_tuple_struct( &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, offset.block_only()), - Density::Compressed, + false, ";", None, body_hi, @@ -1499,7 +1495,7 @@ fn rewrite_type_prefix( &generics.where_clause, context.config.brace_style(), Shape::legacy(where_budget, indent), - Density::Vertical, + false, "=", None, generics.span.hi(), @@ -2258,7 +2254,7 @@ fn rewrite_fn_base( where_clause, context.config.brace_style(), Shape::indented(indent, context.config), - Density::Tall, + true, "{", Some(span.hi()), pos_before_where, @@ -2390,7 +2386,7 @@ fn rewrite_args( &arg_items, context .config - .fn_args_density() + .fn_args_layout() .to_list_tactic(arg_items.len()), Separator::Comma, one_line_budget, @@ -2677,7 +2673,7 @@ fn rewrite_where_clause( where_clause: &ast::WhereClause, brace_style: BraceStyle, shape: Shape, - density: Density, + on_new_line: bool, terminator: &str, span_end: Option, span_end_before_where: BytePos, @@ -2757,7 +2753,7 @@ fn rewrite_where_clause( } else { terminator.len() }; - if density == Density::Tall + if on_new_line || preds_str.contains('\n') || shape.indent.width() + " where ".len() + preds_str.len() + end_length > shape.width { @@ -2848,7 +2844,7 @@ fn format_generics( &generics.where_clause, brace_style, Shape::legacy(budget, offset.block_only()), - Density::Tall, + true, "{", Some(span.hi()), span_end_before_where, diff --git a/src/lists.rs b/src/lists.rs index f57a78f9874..428a0eab9b0 100644 --- a/src/lists.rs +++ b/src/lists.rs @@ -246,10 +246,7 @@ where let total_sep_len = sep.len() * sep_count.saturating_sub(1); let real_total = total_width + total_sep_len; - if real_total <= limit - && !pre_line_comments - && !items.into_iter().any(|item| item.as_ref().is_multiline()) - { + if real_total <= limit && !items.into_iter().any(|item| item.as_ref().is_multiline()) { DefinitiveListTactic::Horizontal } else { match tactic { diff --git a/tests/config/small_tabs.toml b/tests/config/small_tabs.toml index d03ac281acb..35c8fd86467 100644 --- a/tests/config/small_tabs.toml +++ b/tests/config/small_tabs.toml @@ -3,7 +3,7 @@ comment_width = 80 tab_spaces = 2 newline_style = "Unix" brace_style = "SameLineWhere" -fn_args_density = "Tall" +fn_args_layout = "Tall" trailing_comma = "Vertical" indent_style = "Block" report_todo = "Always" diff --git a/tests/source/configs/fn_args_density/compressed.rs b/tests/source/configs/fn_args_layout/compressed.rs similarity index 92% rename from tests/source/configs/fn_args_density/compressed.rs rename to tests/source/configs/fn_args_layout/compressed.rs index 86c0b42e53c..66a371c259f 100644 --- a/tests/source/configs/fn_args_density/compressed.rs +++ b/tests/source/configs/fn_args_layout/compressed.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Compressed +// rustfmt-fn_args_layout: Compressed // Function arguments density trait Lorem { diff --git a/tests/source/configs/fn_args_density/tall.rs b/tests/source/configs/fn_args_layout/tall.rs similarity index 93% rename from tests/source/configs/fn_args_density/tall.rs rename to tests/source/configs/fn_args_layout/tall.rs index fc400e1c113..f11e86fd313 100644 --- a/tests/source/configs/fn_args_density/tall.rs +++ b/tests/source/configs/fn_args_layout/tall.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Tall +// rustfmt-fn_args_layout: Tall // Function arguments density trait Lorem { diff --git a/tests/source/configs/fn_args_density/vertical.rs b/tests/source/configs/fn_args_layout/vertical.rs similarity index 92% rename from tests/source/configs/fn_args_density/vertical.rs rename to tests/source/configs/fn_args_layout/vertical.rs index 20b1427d83d..a23cc025225 100644 --- a/tests/source/configs/fn_args_density/vertical.rs +++ b/tests/source/configs/fn_args_layout/vertical.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // Function arguments density trait Lorem { diff --git a/tests/source/fn-custom-7.rs b/tests/source/fn-custom-7.rs index d76125234fa..d5330196bf7 100644 --- a/tests/source/fn-custom-7.rs +++ b/tests/source/fn-custom-7.rs @@ -1,5 +1,5 @@ // rustfmt-normalize_comments: true -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // rustfmt-brace_style: AlwaysNextLine // Case with only one variable. diff --git a/tests/source/fn-custom.rs b/tests/source/fn-custom.rs index b8d734bfbaf..77ced4c5e0e 100644 --- a/tests/source/fn-custom.rs +++ b/tests/source/fn-custom.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Compressed +// rustfmt-fn_args_layout: Compressed // Test some of the ways function signatures can be customised. // Test compressed layout of args. diff --git a/tests/source/fn_args_density-vertical.rs b/tests/source/fn_args_layout-vertical.rs similarity index 96% rename from tests/source/fn_args_density-vertical.rs rename to tests/source/fn_args_layout-vertical.rs index b61c337dfb9..759bc83d015 100644 --- a/tests/source/fn_args_density-vertical.rs +++ b/tests/source/fn_args_layout-vertical.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // Empty list should stay on one line. fn do_bar( diff --git a/tests/target/configs/fn_args_density/compressed.rs b/tests/target/configs/fn_args_layout/compressed.rs similarity index 93% rename from tests/target/configs/fn_args_density/compressed.rs rename to tests/target/configs/fn_args_layout/compressed.rs index 99283722bee..f189446e25d 100644 --- a/tests/target/configs/fn_args_density/compressed.rs +++ b/tests/target/configs/fn_args_layout/compressed.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Compressed +// rustfmt-fn_args_layout: Compressed // Function arguments density trait Lorem { diff --git a/tests/target/configs/fn_args_density/tall.rs b/tests/target/configs/fn_args_layout/tall.rs similarity index 94% rename from tests/target/configs/fn_args_density/tall.rs rename to tests/target/configs/fn_args_layout/tall.rs index 6ee43b41a19..20f308973ac 100644 --- a/tests/target/configs/fn_args_density/tall.rs +++ b/tests/target/configs/fn_args_layout/tall.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Tall +// rustfmt-fn_args_layout: Tall // Function arguments density trait Lorem { diff --git a/tests/target/configs/fn_args_density/vertical.rs b/tests/target/configs/fn_args_layout/vertical.rs similarity index 94% rename from tests/target/configs/fn_args_density/vertical.rs rename to tests/target/configs/fn_args_layout/vertical.rs index d48b3492452..6c695a75df9 100644 --- a/tests/target/configs/fn_args_density/vertical.rs +++ b/tests/target/configs/fn_args_layout/vertical.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // Function arguments density trait Lorem { diff --git a/tests/target/fn-custom-7.rs b/tests/target/fn-custom-7.rs index f98150c4291..2c20ac5a752 100644 --- a/tests/target/fn-custom-7.rs +++ b/tests/target/fn-custom-7.rs @@ -1,5 +1,5 @@ // rustfmt-normalize_comments: true -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // rustfmt-brace_style: AlwaysNextLine // Case with only one variable. diff --git a/tests/target/fn-custom.rs b/tests/target/fn-custom.rs index bf87553dedc..2eb2a973d24 100644 --- a/tests/target/fn-custom.rs +++ b/tests/target/fn-custom.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Compressed +// rustfmt-fn_args_layout: Compressed // Test some of the ways function signatures can be customised. // Test compressed layout of args. diff --git a/tests/target/fn_args_density-vertical.rs b/tests/target/fn_args_layout-vertical.rs similarity index 96% rename from tests/target/fn_args_density-vertical.rs rename to tests/target/fn_args_layout-vertical.rs index 477a48cc35f..da0ac981d87 100644 --- a/tests/target/fn_args_density-vertical.rs +++ b/tests/target/fn_args_layout-vertical.rs @@ -1,4 +1,4 @@ -// rustfmt-fn_args_density: Vertical +// rustfmt-fn_args_layout: Vertical // Empty list should stay on one line. fn do_bar() -> u8 {