Skip to content

Commit e7eece3

Browse files
committed
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 2403f82 commit e7eece3

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
@@ -120,6 +120,7 @@ macro_rules! create_config {
120120
| "array_width"
121121
| "chain_width" => self.0.set_heuristics(),
122122
"merge_imports" => self.0.set_merge_imports(),
123+
"fn_args_layout" => self.0.set_fn_args_layout(),
123124
&_ => (),
124125
}
125126
}
@@ -174,6 +175,7 @@ macro_rules! create_config {
174175
self.set_heuristics();
175176
self.set_ignore(dir);
176177
self.set_merge_imports();
178+
self.set_fn_args_layout();
177179
self
178180
}
179181

@@ -266,14 +268,21 @@ macro_rules! create_config {
266268
| "array_width"
267269
| "chain_width" => self.set_heuristics(),
268270
"merge_imports" => self.set_merge_imports(),
271+
"fn_args_layout" => self.set_fn_args_layout(),
269272
&_ => (),
270273
}
271274
}
272275

273276
#[allow(unreachable_pub)]
274277
pub fn is_hidden_option(name: &str) -> bool {
275-
const HIDE_OPTIONS: [&str; 5] =
276-
["verbose", "verbose_diff", "file_lines", "width_heuristics", "merge_imports"];
278+
const HIDE_OPTIONS: [&str; 6] = [
279+
"verbose",
280+
"verbose_diff",
281+
"file_lines",
282+
"width_heuristics",
283+
"merge_imports",
284+
"fn_args_layout"
285+
];
277286
HIDE_OPTIONS.contains(&name)
278287
}
279288

@@ -423,6 +432,18 @@ macro_rules! create_config {
423432
}
424433
}
425434

435+
fn set_fn_args_layout(&mut self) {
436+
if self.was_set().fn_args_layout() {
437+
eprintln!(
438+
"Warning: the `fn_args_layout` option is deprecated. \
439+
Use `fn_params_layout`. instead"
440+
);
441+
if !self.was_set().fn_params_layout() {
442+
self.fn_params_layout.2 = self.fn_args_layout();
443+
}
444+
}
445+
}
446+
426447
#[allow(unreachable_pub)]
427448
/// Returns `true` if the config key was explicitly set and is the default value.
428449
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
@@ -119,7 +119,9 @@ create_config! {
119119
force_multiline_blocks: bool, false, false,
120120
"Force multiline closure bodies and match arms to be wrapped in a block";
121121
fn_args_layout: Density, Density::Tall, true,
122-
"Control the layout of arguments in a function";
122+
"(deprecated: use fn_params_layout instead)";
123+
fn_params_layout: Density, Density::Tall, true,
124+
"Control the layout of parameters in function signatures.";
123125
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
124126
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
125127
"Brace style for control flow constructs";
@@ -191,6 +193,7 @@ impl PartialConfig {
191193
cloned.width_heuristics = None;
192194
cloned.print_misformatted_file_names = None;
193195
cloned.merge_imports = None;
196+
cloned.fn_args_layout = None;
194197

195198
::toml::to_string(&cloned).map_err(ToTomlError)
196199
}
@@ -436,6 +439,12 @@ mod test {
436439
"Merge imports";
437440
merge_imports: bool, false, false, "(deprecated: use imports_granularity instead)";
438441

442+
// fn_args_layout renamed to fn_params_layout
443+
fn_args_layout: Density, Density::Tall, true,
444+
"(deprecated: use fn_params_layout instead)";
445+
fn_params_layout: Density, Density::Tall, true,
446+
"Control the layout of parameters in a function signatures.";
447+
439448
// Width Heuristics
440449
use_small_heuristics: Heuristics, Heuristics::Default, true,
441450
"Whether to use different formatting for items and \
@@ -637,7 +646,7 @@ enum_discrim_align_threshold = 0
637646
match_arm_blocks = true
638647
match_arm_leading_pipes = "Never"
639648
force_multiline_blocks = false
640-
fn_args_layout = "Tall"
649+
fn_params_layout = "Tall"
641650
brace_style = "SameLineWhere"
642651
control_brace_style = "AlwaysSameLine"
643652
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)