Skip to content

Commit e6b60a4

Browse files
scampitopecongiro
authored andcommitted
stabilise fn_args_density (#3581)
1 parent 1922094 commit e6b60a4

20 files changed

+38
-39
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,12 @@
22

33
## [Unreleased]
44

5+
### Changed
6+
57
- Change option `format_doc_comment` to `format_code_in_doc_comment`.
68
- `use_small_heuristics` changed to be an enum and stabilised. Configuration
79
options are now ready for 1.0.
10+
- Stabilise `fn_args_density` configuration option and rename it to `fn_args_layout` #3581
811

912
## [1.2.2] 2019-04-24
1013

Configurations.md

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -629,13 +629,13 @@ trailing whitespaces.
629629
- **Possible values**: `true`, `false`
630630
- **Stable**: No (tracking issue: #3392)
631631

632-
## `fn_args_density`
632+
## `fn_args_layout`
633633

634-
Argument density in functions
634+
Control the layout of arguments in a function
635635

636636
- **Default value**: `"Tall"`
637637
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
638-
- **Stable**: No (tracking issue: #3375)
638+
- **Stable**: Yes
639639

640640
#### `"Tall"` (default):
641641

Processes.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ Open a pull request that closes the tracking issue. The tracking issue is listed
1717

1818
- Update the `Config` enum marking the option as stable.
1919
- Update the the `Configuration.md` file marking the option as stable.
20+
- Update `CHANGELOG.md` marking the option as stable.
2021

2122
## After the stabilisation
2223

src/config/mod.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -92,7 +92,8 @@ create_config! {
9292
the same line with the pattern of arms";
9393
force_multiline_blocks: bool, false, false,
9494
"Force multiline closure bodies and match arms to be wrapped in a block";
95-
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
95+
fn_args_layout: Density, Density::Tall, true,
96+
"Control the layout of arguments in a function";
9697
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
9798
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
9899
"Brace style for control flow constructs";
@@ -501,7 +502,7 @@ struct_field_align_threshold = 0
501502
enum_discrim_align_threshold = 0
502503
match_arm_blocks = true
503504
force_multiline_blocks = false
504-
fn_args_density = "Tall"
505+
fn_args_layout = "Tall"
505506
brace_style = "SameLineWhere"
506507
control_brace_style = "AlwaysSameLine"
507508
trailing_semicolon = true

src/config/options.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,10 +58,11 @@ pub enum IndentStyle {
5858

5959
#[config_type]
6060
/// How to place a list-like items.
61+
/// FIXME: Issue-3581: this should be renamed to ItemsLayout when publishing 2.0
6162
pub enum Density {
6263
/// Fit as much on one line as possible.
6364
Compressed,
64-
/// Use more lines.
65+
/// Items are placed horizontally if sufficient space, vertically otherwise.
6566
Tall,
6667
/// Place every item on a separate line.
6768
Vertical,

src/items.rs

Lines changed: 12 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ use crate::comment::{
1515
FindUncommented,
1616
};
1717
use crate::config::lists::*;
18-
use crate::config::{BraceStyle, Config, Density, IndentStyle, Version};
18+
use crate::config::{BraceStyle, Config, IndentStyle, Version};
1919
use crate::expr::{
2020
format_expr, is_empty_block, is_simple_block_stmt, rewrite_assign_rhs, rewrite_assign_rhs_with,
2121
ExprType, RhsTactics,
@@ -703,7 +703,7 @@ pub(crate) fn format_impl(
703703
&generics.where_clause,
704704
context.config.brace_style(),
705705
Shape::legacy(where_budget, offset.block_only()),
706-
Density::Vertical,
706+
false,
707707
"{",
708708
where_span_end,
709709
self_ty.span.hi(),
@@ -1044,11 +1044,7 @@ pub(crate) fn format_trait(
10441044

10451045
// Rewrite where-clause.
10461046
if !generics.where_clause.predicates.is_empty() {
1047-
let where_density = if context.config.indent_style() == IndentStyle::Block {
1048-
Density::Compressed
1049-
} else {
1050-
Density::Tall
1051-
};
1047+
let where_on_new_line = context.config.indent_style() != IndentStyle::Block;
10521048

10531049
let where_budget = context.budget(last_line_width(&result));
10541050
let pos_before_where = if generic_bounds.is_empty() {
@@ -1062,7 +1058,7 @@ pub(crate) fn format_trait(
10621058
&generics.where_clause,
10631059
context.config.brace_style(),
10641060
Shape::legacy(where_budget, offset.block_only()),
1065-
where_density,
1061+
where_on_new_line,
10661062
"{",
10671063
None,
10681064
pos_before_where,
@@ -1171,7 +1167,7 @@ impl<'a> Rewrite for TraitAliasBounds<'a> {
11711167
&self.generics.where_clause,
11721168
context.config.brace_style(),
11731169
shape,
1174-
Density::Compressed,
1170+
false,
11751171
";",
11761172
None,
11771173
self.generics.where_clause.span.lo(),
@@ -1423,7 +1419,7 @@ fn format_tuple_struct(
14231419
&generics.where_clause,
14241420
context.config.brace_style(),
14251421
Shape::legacy(where_budget, offset.block_only()),
1426-
Density::Compressed,
1422+
false,
14271423
";",
14281424
None,
14291425
body_hi,
@@ -1499,7 +1495,7 @@ fn rewrite_type_prefix(
14991495
&generics.where_clause,
15001496
context.config.brace_style(),
15011497
Shape::legacy(where_budget, indent),
1502-
Density::Vertical,
1498+
false,
15031499
"=",
15041500
None,
15051501
generics.span.hi(),
@@ -2258,7 +2254,7 @@ fn rewrite_fn_base(
22582254
where_clause,
22592255
context.config.brace_style(),
22602256
Shape::indented(indent, context.config),
2261-
Density::Tall,
2257+
true,
22622258
"{",
22632259
Some(span.hi()),
22642260
pos_before_where,
@@ -2390,7 +2386,7 @@ fn rewrite_args(
23902386
&arg_items,
23912387
context
23922388
.config
2393-
.fn_args_density()
2389+
.fn_args_layout()
23942390
.to_list_tactic(arg_items.len()),
23952391
Separator::Comma,
23962392
one_line_budget,
@@ -2677,7 +2673,7 @@ fn rewrite_where_clause(
26772673
where_clause: &ast::WhereClause,
26782674
brace_style: BraceStyle,
26792675
shape: Shape,
2680-
density: Density,
2676+
on_new_line: bool,
26812677
terminator: &str,
26822678
span_end: Option<BytePos>,
26832679
span_end_before_where: BytePos,
@@ -2757,7 +2753,7 @@ fn rewrite_where_clause(
27572753
} else {
27582754
terminator.len()
27592755
};
2760-
if density == Density::Tall
2756+
if on_new_line
27612757
|| preds_str.contains('\n')
27622758
|| shape.indent.width() + " where ".len() + preds_str.len() + end_length > shape.width
27632759
{
@@ -2848,7 +2844,7 @@ fn format_generics(
28482844
&generics.where_clause,
28492845
brace_style,
28502846
Shape::legacy(budget, offset.block_only()),
2851-
Density::Tall,
2847+
true,
28522848
"{",
28532849
Some(span.hi()),
28542850
span_end_before_where,

src/lists.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -246,10 +246,7 @@ where
246246
let total_sep_len = sep.len() * sep_count.saturating_sub(1);
247247
let real_total = total_width + total_sep_len;
248248

249-
if real_total <= limit
250-
&& !pre_line_comments
251-
&& !items.into_iter().any(|item| item.as_ref().is_multiline())
252-
{
249+
if real_total <= limit && !items.into_iter().any(|item| item.as_ref().is_multiline()) {
253250
DefinitiveListTactic::Horizontal
254251
} else {
255252
match tactic {

tests/config/small_tabs.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ comment_width = 80
33
tab_spaces = 2
44
newline_style = "Unix"
55
brace_style = "SameLineWhere"
6-
fn_args_density = "Tall"
6+
fn_args_layout = "Tall"
77
trailing_comma = "Vertical"
88
indent_style = "Block"
99
report_todo = "Always"

tests/source/configs/fn_args_density/compressed.rs renamed to tests/source/configs/fn_args_layout/compressed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Compressed
1+
// rustfmt-fn_args_layout: Compressed
22
// Function arguments density
33

44
trait Lorem {

tests/source/configs/fn_args_density/tall.rs renamed to tests/source/configs/fn_args_layout/tall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Tall
1+
// rustfmt-fn_args_layout: Tall
22
// Function arguments density
33

44
trait Lorem {

tests/source/configs/fn_args_density/vertical.rs renamed to tests/source/configs/fn_args_layout/vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Vertical
1+
// rustfmt-fn_args_layout: Vertical
22
// Function arguments density
33

44
trait Lorem {

tests/source/fn-custom-7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-normalize_comments: true
2-
// rustfmt-fn_args_density: Vertical
2+
// rustfmt-fn_args_layout: Vertical
33
// rustfmt-brace_style: AlwaysNextLine
44

55
// Case with only one variable.

tests/source/fn-custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Compressed
1+
// rustfmt-fn_args_layout: Compressed
22
// Test some of the ways function signatures can be customised.
33

44
// Test compressed layout of args.

tests/source/fn_args_density-vertical.rs renamed to tests/source/fn_args_layout-vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Vertical
1+
// rustfmt-fn_args_layout: Vertical
22

33
// Empty list should stay on one line.
44
fn do_bar(

tests/target/configs/fn_args_density/compressed.rs renamed to tests/target/configs/fn_args_layout/compressed.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Compressed
1+
// rustfmt-fn_args_layout: Compressed
22
// Function arguments density
33

44
trait Lorem {

tests/target/configs/fn_args_density/tall.rs renamed to tests/target/configs/fn_args_layout/tall.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Tall
1+
// rustfmt-fn_args_layout: Tall
22
// Function arguments density
33

44
trait Lorem {

tests/target/configs/fn_args_density/vertical.rs renamed to tests/target/configs/fn_args_layout/vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Vertical
1+
// rustfmt-fn_args_layout: Vertical
22
// Function arguments density
33

44
trait Lorem {

tests/target/fn-custom-7.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// rustfmt-normalize_comments: true
2-
// rustfmt-fn_args_density: Vertical
2+
// rustfmt-fn_args_layout: Vertical
33
// rustfmt-brace_style: AlwaysNextLine
44

55
// Case with only one variable.

tests/target/fn-custom.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Compressed
1+
// rustfmt-fn_args_layout: Compressed
22
// Test some of the ways function signatures can be customised.
33

44
// Test compressed layout of args.

tests/target/fn_args_density-vertical.rs renamed to tests/target/fn_args_layout-vertical.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// rustfmt-fn_args_density: Vertical
1+
// rustfmt-fn_args_layout: Vertical
22

33
// Empty list should stay on one line.
44
fn do_bar() -> u8 {

0 commit comments

Comments
 (0)