Skip to content

Commit 0cb294f

Browse files
ytmimicalebcartwright
authored andcommitted
Deprecate and Rename fn_args_layout -> fn_params_layout
fn_args_layout is now deprecated. This option was renamed to better communicate that it affects the layout of parameters in function signatures and not the layout of arguments in function calls. Because the `fn_args_layout` is a stable option the renamed option is also stable, however users who set `fn_args_layout` will get a warning message letting them know that the option has been renamed.
1 parent c240f3a commit 0cb294f

File tree

18 files changed

+164
-20
lines changed

18 files changed

+164
-20
lines changed

Configurations.md

Lines changed: 115 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,8 @@ trailing whitespaces.
645645

646646
## `fn_args_layout`
647647

648-
Control the layout of arguments in a function
648+
This option is deprecated and has been renamed to `fn_params_layout` to better communicate that
649+
it affects the layout of parameters in function signatures.
649650

650651
- **Default value**: `"Tall"`
651652
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
@@ -753,6 +754,8 @@ trait Lorem {
753754
}
754755
```
755756

757+
See also [`fn_params_layout`](#fn_params_layout)
758+
756759
## `fn_call_width`
757760

758761
Maximum width of the args of a function call before falling back to vertical formatting.
@@ -765,6 +768,117 @@ By default this option is set as a percentage of [`max_width`](#max_width) provi
765768

766769
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
767770

771+
## `fn_params_layout`
772+
773+
Control the layout of parameters in function signatures.
774+
775+
- **Default value**: `"Tall"`
776+
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
777+
- **Stable**: Yes
778+
779+
#### `"Tall"` (default):
780+
781+
```rust
782+
trait Lorem {
783+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
784+
785+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
786+
// body
787+
}
788+
789+
fn lorem(
790+
ipsum: Ipsum,
791+
dolor: Dolor,
792+
sit: Sit,
793+
amet: Amet,
794+
consectetur: Consectetur,
795+
adipiscing: Adipiscing,
796+
elit: Elit,
797+
);
798+
799+
fn lorem(
800+
ipsum: Ipsum,
801+
dolor: Dolor,
802+
sit: Sit,
803+
amet: Amet,
804+
consectetur: Consectetur,
805+
adipiscing: Adipiscing,
806+
elit: Elit,
807+
) {
808+
// body
809+
}
810+
}
811+
```
812+
813+
#### `"Compressed"`:
814+
815+
```rust
816+
trait Lorem {
817+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);
818+
819+
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
820+
// body
821+
}
822+
823+
fn lorem(
824+
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
825+
adipiscing: Adipiscing, elit: Elit,
826+
);
827+
828+
fn lorem(
829+
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
830+
adipiscing: Adipiscing, elit: Elit,
831+
) {
832+
// body
833+
}
834+
}
835+
```
836+
837+
#### `"Vertical"`:
838+
839+
```rust
840+
trait Lorem {
841+
fn lorem(
842+
ipsum: Ipsum,
843+
dolor: Dolor,
844+
sit: Sit,
845+
amet: Amet,
846+
);
847+
848+
fn lorem(
849+
ipsum: Ipsum,
850+
dolor: Dolor,
851+
sit: Sit,
852+
amet: Amet,
853+
) {
854+
// body
855+
}
856+
857+
fn lorem(
858+
ipsum: Ipsum,
859+
dolor: Dolor,
860+
sit: Sit,
861+
amet: Amet,
862+
consectetur: Consectetur,
863+
adipiscing: Adipiscing,
864+
elit: Elit,
865+
);
866+
867+
fn lorem(
868+
ipsum: Ipsum,
869+
dolor: Dolor,
870+
sit: Sit,
871+
amet: Amet,
872+
consectetur: Consectetur,
873+
adipiscing: Adipiscing,
874+
elit: Elit,
875+
) {
876+
// body
877+
}
878+
}
879+
```
880+
881+
768882
## `fn_single_line`
769883

770884
Put single-expression functions on a single line

src/config/config_type.rs

Lines changed: 23 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,6 +127,7 @@ macro_rules! create_config {
127127
| "array_width"
128128
| "chain_width" => self.0.set_heuristics(),
129129
"merge_imports" => self.0.set_merge_imports(),
130+
"fn_args_layout" => self.0.set_fn_args_layout(),
130131
&_ => (),
131132
}
132133
}
@@ -181,6 +182,7 @@ macro_rules! create_config {
181182
self.set_heuristics();
182183
self.set_ignore(dir);
183184
self.set_merge_imports();
185+
self.set_fn_args_layout();
184186
self
185187
}
186188

@@ -273,14 +275,21 @@ macro_rules! create_config {
273275
| "array_width"
274276
| "chain_width" => self.set_heuristics(),
275277
"merge_imports" => self.set_merge_imports(),
278+
"fn_args_layout" => self.set_fn_args_layout(),
276279
&_ => (),
277280
}
278281
}
279282

280283
#[allow(unreachable_pub)]
281284
pub fn is_hidden_option(name: &str) -> bool {
282-
const HIDE_OPTIONS: [&str; 5] =
283-
["verbose", "verbose_diff", "file_lines", "width_heuristics", "merge_imports"];
285+
const HIDE_OPTIONS: [&str; 6] = [
286+
"verbose",
287+
"verbose_diff",
288+
"file_lines",
289+
"width_heuristics",
290+
"merge_imports",
291+
"fn_args_layout"
292+
];
284293
HIDE_OPTIONS.contains(&name)
285294
}
286295

@@ -430,6 +439,18 @@ macro_rules! create_config {
430439
}
431440
}
432441

442+
fn set_fn_args_layout(&mut self) {
443+
if self.was_set().fn_args_layout() {
444+
eprintln!(
445+
"Warning: the `fn_args_layout` option is deprecated. \
446+
Use `fn_params_layout`. instead"
447+
);
448+
if !self.was_set().fn_params_layout() {
449+
self.fn_params_layout.2 = self.fn_args_layout();
450+
}
451+
}
452+
}
453+
433454
#[allow(unreachable_pub)]
434455
/// Returns `true` if the config key was explicitly set and is the default value.
435456
pub fn is_default(&self, key: &str) -> bool {

src/config/mod.rs

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,9 @@ create_config! {
124124
force_multiline_blocks: bool, false, false,
125125
"Force multiline closure bodies and match arms to be wrapped in a block";
126126
fn_args_layout: Density, Density::Tall, true,
127-
"Control the layout of arguments in a function";
127+
"(deprecated: use fn_params_layout instead)";
128+
fn_params_layout: Density, Density::Tall, true,
129+
"Control the layout of parameters in function signatures.";
128130
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
129131
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
130132
"Brace style for control flow constructs";
@@ -196,6 +198,7 @@ impl PartialConfig {
196198
cloned.width_heuristics = None;
197199
cloned.print_misformatted_file_names = None;
198200
cloned.merge_imports = None;
201+
cloned.fn_args_layout = None;
199202

200203
::toml::to_string(&cloned).map_err(ToTomlError)
201204
}
@@ -442,6 +445,12 @@ mod test {
442445
"Merge imports";
443446
merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";
444447

448+
// fn_args_layout renamed to fn_params_layout
449+
fn_args_layout: Density, Density::Tall, true,
450+
"(deprecated: use fn_params_layout instead)";
451+
fn_params_layout: Density, Density::Tall, true,
452+
"Control the layout of parameters in a function signatures.";
453+
445454
// Width Heuristics
446455
use_small_heuristics: Heuristics, Heuristics::Default, true,
447456
"Whether to use different formatting for items and \
@@ -644,7 +653,7 @@ enum_discrim_align_threshold = 0
644653
match_arm_blocks = true
645654
match_arm_leading_pipes = "Never"
646655
force_multiline_blocks = false
647-
fn_args_layout = "Tall"
656+
fn_params_layout = "Tall"
648657
brace_style = "SameLineWhere"
649658
control_brace_style = "AlwaysSameLine"
650659
trailing_semicolon = true

src/items.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ fn rewrite_params(
26022602
&param_items,
26032603
context
26042604
.config
2605-
.fn_args_layout()
2605+
.fn_params_layout()
26062606
.to_list_tactic(param_items.len()),
26072607
Separator::Comma,
26082608
one_line_budget,

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_layout = "Tall"
6+
fn_params_layout = "Tall"
77
trailing_comma = "Vertical"
88
indent_style = "Block"
99
reorder_imports = false

tests/source/configs/fn_args_layout/compressed.rs renamed to tests/source/configs/fn_params_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_layout: Compressed
1+
// rustfmt-fn_params_layout: Compressed
22
// Function arguments density
33

44
trait Lorem {

tests/source/configs/fn_args_layout/tall.rs renamed to tests/source/configs/fn_params_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_layout: Tall
1+
// rustfmt-fn_params_layout: Tall
22
// Function arguments density
33

44
trait Lorem {

tests/source/configs/fn_args_layout/vertical.rs renamed to tests/source/configs/fn_params_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_layout: Vertical
1+
// rustfmt-fn_params_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_layout: Vertical
2+
// rustfmt-fn_params_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_layout: Compressed
1+
// rustfmt-fn_params_layout: Compressed
22
// Test some of the ways function signatures can be customised.
33

44
// Test compressed layout of args.

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_layout: Vertical
1+
// rustfmt-fn_params_layout: Vertical
22

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

tests/target/configs/fn_args_layout/compressed.rs renamed to tests/target/configs/fn_params_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_layout: Compressed
1+
// rustfmt-fn_params_layout: Compressed
22
// Function arguments density
33

44
trait Lorem {

tests/target/configs/fn_args_layout/tall.rs renamed to tests/target/configs/fn_params_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_layout: Tall
1+
// rustfmt-fn_params_layout: Tall
22
// Function arguments density
33

44
trait Lorem {

tests/target/configs/fn_args_layout/vertical.rs renamed to tests/target/configs/fn_params_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_layout: Vertical
1+
// rustfmt-fn_params_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_layout: Vertical
2+
// rustfmt-fn_params_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_layout: Compressed
1+
// rustfmt-fn_params_layout: Compressed
22
// Test some of the ways function signatures can be customised.
33

44
// Test compressed layout of args.

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_layout: Vertical
1+
// rustfmt-fn_params_layout: Vertical
22

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

tests/target/issue-4791/issue_4928.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// rustfmt-brace_style: SameLineWhere
22
// rustfmt-comment_width: 100
33
// rustfmt-edition: 2018
4-
// rustfmt-fn_args_layout: Compressed
4+
// rustfmt-fn_params_layout: Compressed
55
// rustfmt-hard_tabs: false
66
// rustfmt-match_block_trailing_comma: true
77
// rustfmt-max_width: 100

0 commit comments

Comments
 (0)