Skip to content

Commit d854403

Browse files
committed
Rename fn_args_layout -> fn_params_layout
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 e44380b commit d854403

File tree

18 files changed

+161
-19
lines changed

18 files changed

+161
-19
lines changed

Configurations.md

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

646646
## `fn_args_layout`
647647

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

650650
- **Default value**: `"Tall"`
651651
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
@@ -753,6 +753,8 @@ trait Lorem {
753753
}
754754
```
755755

756+
See also [`fn_params_layout`](#fn_params_layout)
757+
756758
## `fn_call_width`
757759

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

766768
See also [`max_width`](#max_width) and [`use_small_heuristics`](#use_small_heuristics)
767769

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

770883
Put single-expression functions on a single line

src/config/config_type.rs

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,7 @@ macro_rules! create_config {
102102
| "array_width"
103103
| "chain_width" => self.0.set_heuristics(),
104104
"merge_imports" => self.0.set_merge_imports(),
105+
"fn_args_layout" => self.0.set_fn_args_layout(),
105106
&_ => (),
106107
}
107108
}
@@ -161,6 +162,7 @@ macro_rules! create_config {
161162
self.set_heuristics();
162163
self.set_ignore(dir);
163164
self.set_merge_imports();
165+
self.set_fn_args_layout();
164166
self
165167
}
166168

@@ -243,14 +245,21 @@ macro_rules! create_config {
243245
| "array_width"
244246
| "chain_width" => self.set_heuristics(),
245247
"merge_imports" => self.set_merge_imports(),
248+
"fn_args_layout" => self.set_fn_args_layout(),
246249
&_ => (),
247250
}
248251
}
249252

250253
#[allow(unreachable_pub)]
251254
pub fn is_hidden_option(name: &str) -> bool {
252-
const HIDE_OPTIONS: [&str; 5] =
253-
["verbose", "verbose_diff", "file_lines", "width_heuristics", "merge_imports"];
255+
const HIDE_OPTIONS: [&str; 6] = [
256+
"verbose",
257+
"verbose_diff",
258+
"file_lines",
259+
"width_heuristics",
260+
"merge_imports",
261+
"fn_args_layout"
262+
];
254263
HIDE_OPTIONS.contains(&name)
255264
}
256265

@@ -400,6 +409,17 @@ macro_rules! create_config {
400409
}
401410
}
402411

412+
fn set_fn_args_layout(&mut self) {
413+
if self.was_set().fn_args_layout() {
414+
eprintln!(
415+
"Warning: the `fn_args_layout` option was renamed to `fn_params_layout`."
416+
);
417+
if !self.was_set().fn_params_layout() {
418+
self.fn_params_layout.2 = self.fn_args_layout();
419+
}
420+
}
421+
}
422+
403423
#[allow(unreachable_pub)]
404424
/// Returns `true` if the config key was explicitly set and is the default value.
405425
pub fn is_default(&self, key: &str) -> bool {

src/config/mod.rs

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,9 @@ create_config! {
117117
force_multiline_blocks: bool, false, false,
118118
"Force multiline closure bodies and match arms to be wrapped in a block";
119119
fn_args_layout: Density, Density::Tall, true,
120-
"Control the layout of arguments in a function";
120+
"Renamed to `fn_params_layout`. Use `fn_params_layout` instead.";
121+
fn_params_layout: Density, Density::Tall, true,
122+
"Control the layout of parameters in function signatures.";
121123
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
122124
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
123125
"Brace style for control flow constructs";
@@ -425,6 +427,12 @@ mod test {
425427
"Merge imports";
426428
merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";
427429

430+
// fn_args_layout renamed to fn_params_layout
431+
fn_args_layout: Density, Density::Tall, true,
432+
"Renamed to `fn_params_layout`. Use `fn_params_layout` instead.";
433+
fn_params_layout: Density, Density::Tall, true,
434+
"Control the layout of parameters in a function signatures.";
435+
428436
// Width Heuristics
429437
use_small_heuristics: Heuristics, Heuristics::Default, true,
430438
"Whether to use different formatting for items and \
@@ -565,6 +573,7 @@ match_arm_blocks = true
565573
match_arm_leading_pipes = "Never"
566574
force_multiline_blocks = false
567575
fn_args_layout = "Tall"
576+
fn_params_layout = "Tall"
568577
brace_style = "SameLineWhere"
569578
control_brace_style = "AlwaysSameLine"
570579
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)