Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rename fn_args_layout -> fn_params_layout #5387

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
116 changes: 115 additions & 1 deletion Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -645,7 +645,8 @@ trailing whitespaces.

## `fn_args_layout`

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

- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
Expand Down Expand Up @@ -753,6 +754,8 @@ trait Lorem {
}
```

See also [`fn_params_layout`](#fn_params_layout)

## `fn_call_width`

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

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

## `fn_params_layout`

Control the layout of parameters in function signatures.

- **Default value**: `"Tall"`
- **Possible values**: `"Compressed"`, `"Tall"`, `"Vertical"`
- **Stable**: Yes

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

```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);

fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```

#### `"Compressed"`:

```rust
trait Lorem {
fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet);

fn lorem(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) {
// body
}

fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
);

fn lorem(
ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet, consectetur: Consectetur,
adipiscing: Adipiscing, elit: Elit,
) {
// body
}
}
```

#### `"Vertical"`:

```rust
trait Lorem {
fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
) {
// body
}

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
);

fn lorem(
ipsum: Ipsum,
dolor: Dolor,
sit: Sit,
amet: Amet,
consectetur: Consectetur,
adipiscing: Adipiscing,
elit: Elit,
) {
// body
}
}
```


## `fn_single_line`

Put single-expression functions on a single line
Expand Down
25 changes: 23 additions & 2 deletions src/config/config_type.rs
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ macro_rules! create_config {
| "array_width"
| "chain_width" => self.0.set_heuristics(),
"merge_imports" => self.0.set_merge_imports(),
"fn_args_layout" => self.0.set_fn_args_layout(),
&_ => (),
}
}
Expand Down Expand Up @@ -174,6 +175,7 @@ macro_rules! create_config {
self.set_heuristics();
self.set_ignore(dir);
self.set_merge_imports();
self.set_fn_args_layout();
self
}

Expand Down Expand Up @@ -266,14 +268,21 @@ macro_rules! create_config {
| "array_width"
| "chain_width" => self.set_heuristics(),
"merge_imports" => self.set_merge_imports(),
"fn_args_layout" => self.set_fn_args_layout(),
&_ => (),
}
}

#[allow(unreachable_pub)]
pub fn is_hidden_option(name: &str) -> bool {
const HIDE_OPTIONS: [&str; 5] =
["verbose", "verbose_diff", "file_lines", "width_heuristics", "merge_imports"];
const HIDE_OPTIONS: [&str; 6] = [
"verbose",
"verbose_diff",
"file_lines",
"width_heuristics",
"merge_imports",
"fn_args_layout"
];
HIDE_OPTIONS.contains(&name)
}

Expand Down Expand Up @@ -423,6 +432,18 @@ macro_rules! create_config {
}
}

fn set_fn_args_layout(&mut self) {
if self.was_set().fn_args_layout() {
eprintln!(
"Warning: the `fn_args_layout` option is deprecated. \
Use `fn_params_layout`. instead"
);
if !self.was_set().fn_params_layout() {
self.fn_params_layout.2 = self.fn_args_layout();
}
}
}

#[allow(unreachable_pub)]
/// Returns `true` if the config key was explicitly set and is the default value.
pub fn is_default(&self, key: &str) -> bool {
Expand Down
13 changes: 11 additions & 2 deletions src/config/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,9 @@ create_config! {
force_multiline_blocks: bool, false, false,
"Force multiline closure bodies and match arms to be wrapped in a block";
fn_args_layout: Density, Density::Tall, true,
"Control the layout of arguments in a function";
"(deprecated: use fn_params_layout instead)";
fn_params_layout: Density, Density::Tall, true,
"Control the layout of parameters in function signatures.";
brace_style: BraceStyle, BraceStyle::SameLineWhere, false, "Brace style for items";
control_brace_style: ControlBraceStyle, ControlBraceStyle::AlwaysSameLine, false,
"Brace style for control flow constructs";
Expand Down Expand Up @@ -191,6 +193,7 @@ impl PartialConfig {
cloned.width_heuristics = None;
cloned.print_misformatted_file_names = None;
cloned.merge_imports = None;
cloned.fn_args_layout = None;

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

// fn_args_layout renamed to fn_params_layout
fn_args_layout: Density, Density::Tall, true,
"(deprecated: use fn_params_layout instead)";
fn_params_layout: Density, Density::Tall, true,
"Control the layout of parameters in a function signatures.";

// Width Heuristics
use_small_heuristics: Heuristics, Heuristics::Default, true,
"Whether to use different formatting for items and \
Expand Down Expand Up @@ -637,7 +646,7 @@ enum_discrim_align_threshold = 0
match_arm_blocks = true
match_arm_leading_pipes = "Never"
force_multiline_blocks = false
fn_args_layout = "Tall"
fn_params_layout = "Tall"
brace_style = "SameLineWhere"
control_brace_style = "AlwaysSameLine"
trailing_semicolon = true
Expand Down
2 changes: 1 addition & 1 deletion src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2602,7 +2602,7 @@ fn rewrite_params(
&param_items,
context
.config
.fn_args_layout()
.fn_params_layout()
.to_list_tactic(param_items.len()),
Separator::Comma,
one_line_budget,
Expand Down
2 changes: 1 addition & 1 deletion tests/config/small_tabs.toml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ comment_width = 80
tab_spaces = 2
newline_style = "Unix"
brace_style = "SameLineWhere"
fn_args_layout = "Tall"
fn_params_layout = "Tall"
trailing_comma = "Vertical"
indent_style = "Block"
reorder_imports = false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Compressed
// rustfmt-fn_params_layout: Compressed
// Function arguments density

trait Lorem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Tall
// rustfmt-fn_params_layout: Tall
// Function arguments density

trait Lorem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical
// Function arguments density

trait Lorem {
Expand Down
2 changes: 1 addition & 1 deletion tests/source/fn-custom-7.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical
// rustfmt-brace_style: AlwaysNextLine

// Case with only one variable.
Expand Down
2 changes: 1 addition & 1 deletion tests/source/fn-custom.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Compressed
// rustfmt-fn_params_layout: Compressed
// Test some of the ways function signatures can be customised.

// Test compressed layout of args.
Expand Down
2 changes: 1 addition & 1 deletion tests/source/fn_args_layout-vertical.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical

// Empty list should stay on one line.
fn do_bar(
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Compressed
// rustfmt-fn_params_layout: Compressed
// Function arguments density

trait Lorem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Tall
// rustfmt-fn_params_layout: Tall
// Function arguments density

trait Lorem {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical
// Function arguments density

trait Lorem {
Expand Down
2 changes: 1 addition & 1 deletion tests/target/fn-custom-7.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
// rustfmt-normalize_comments: true
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical
// rustfmt-brace_style: AlwaysNextLine

// Case with only one variable.
Expand Down
2 changes: 1 addition & 1 deletion tests/target/fn-custom.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Compressed
// rustfmt-fn_params_layout: Compressed
// Test some of the ways function signatures can be customised.

// Test compressed layout of args.
Expand Down
2 changes: 1 addition & 1 deletion tests/target/fn_args_layout-vertical.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// rustfmt-fn_args_layout: Vertical
// rustfmt-fn_params_layout: Vertical

// Empty list should stay on one line.
fn do_bar() -> u8 {
Expand Down
2 changes: 1 addition & 1 deletion tests/target/issue-4791/issue_4928.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// rustfmt-brace_style: SameLineWhere
// rustfmt-comment_width: 100
// rustfmt-edition: 2018
// rustfmt-fn_args_layout: Compressed
// rustfmt-fn_params_layout: Compressed
// rustfmt-hard_tabs: false
// rustfmt-match_block_trailing_comma: true
// rustfmt-max_width: 100
Expand Down