struct_lit_multiline_style -> struct_lit_single_line (and make it a bool)
This commit is contained in:
parent
20805acf42
commit
45d4f7a2dd
@ -246,7 +246,7 @@ let lorem = Lorem { ipsum: dolor,
|
||||
sit: amet, };
|
||||
```
|
||||
|
||||
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
|
||||
See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
|
||||
|
||||
### Where predicates
|
||||
|
||||
@ -1746,20 +1746,20 @@ let lorem: [ usize; 2 ] = [ ipsum, dolor ];
|
||||
|
||||
See also: [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets), [`spaces_within_parens_and_brackets`](#spaces_within_parens_and_brackets).
|
||||
|
||||
## `struct_lit_multiline_style`
|
||||
## `struct_lit_single_line`
|
||||
|
||||
Multiline style on literal structs
|
||||
Put small struct literals on a single line
|
||||
|
||||
- **Default value**: `"PreferSingle"`
|
||||
- **Possible values**: `"ForceMulti"`, `"PreferSingle"`
|
||||
- **Default value**: `true`
|
||||
- **Possible values**: `true`, `false`
|
||||
|
||||
#### `"PreferSingle"` (default):
|
||||
#### `true` (default):
|
||||
|
||||
```rust
|
||||
let lorem = Lorem { ipsum: dolor, sit: amet };
|
||||
```
|
||||
|
||||
#### `"ForceMulti"`:
|
||||
#### `false`:
|
||||
|
||||
```rust
|
||||
let lorem = Lorem {
|
||||
@ -1787,7 +1787,7 @@ let lorem = Lorem { ipsum: dolor, sit: amet };
|
||||
#### Lines longer than `struct_lit_width`:
|
||||
See [`indent_style`](#indent_style).
|
||||
|
||||
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`indent_style`](#indent_style).
|
||||
See also: [`struct_lit_single_line`](#struct_lit_single_line), [`indent_style`](#indent_style).
|
||||
|
||||
## `struct_variant_width`
|
||||
|
||||
|
@ -100,22 +100,6 @@ impl Density {
|
||||
}
|
||||
}
|
||||
|
||||
configuration_option_enum! { MultilineStyle:
|
||||
// Use horizontal layout if it fits in one line, fall back to vertical
|
||||
PreferSingle,
|
||||
// Use vertical layout
|
||||
ForceMulti,
|
||||
}
|
||||
|
||||
impl MultilineStyle {
|
||||
pub fn to_list_tactic(self) -> ListTactic {
|
||||
match self {
|
||||
MultilineStyle::PreferSingle => ListTactic::HorizontalVertical,
|
||||
MultilineStyle::ForceMulti => ListTactic::Vertical,
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
configuration_option_enum! { ReportTactic:
|
||||
Always,
|
||||
Unnumbered,
|
||||
@ -563,8 +547,8 @@ create_config! {
|
||||
where_density: Density, Density::Vertical, false, "Density of a where clause";
|
||||
where_single_line: bool, false, false, "To force single line where layout";
|
||||
where_layout: ListTactic, ListTactic::Vertical, false, "Element layout inside a where clause";
|
||||
struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle, false,
|
||||
"Multiline style on literal structs";
|
||||
struct_lit_single_line: bool, true, false,
|
||||
"Put small struct literals on a single line";
|
||||
report_todo: ReportTactic, ReportTactic::Never, false,
|
||||
"Report all, none or unnumbered occurrences of TODO in source file comments";
|
||||
report_fixme: ReportTactic, ReportTactic::Never, false,
|
||||
|
@ -21,7 +21,7 @@ use closures;
|
||||
use codemap::{LineRangeUtils, SpanUtils};
|
||||
use comment::{combine_strs_with_missing_comments, contains_comment, recover_comment_removed,
|
||||
rewrite_comment, rewrite_missing_comment, FindUncommented};
|
||||
use config::{Config, ControlBraceStyle, IndentStyle, MultilineStyle};
|
||||
use config::{Config, ControlBraceStyle, IndentStyle};
|
||||
use lists::{definitive_tactic, itemize_list, shape_for_tactic, struct_lit_formatting,
|
||||
struct_lit_shape, struct_lit_tactic, write_list, DefinitiveListTactic, ListFormatting,
|
||||
ListItem, ListTactic, Separator, SeparatorPlace, SeparatorTactic};
|
||||
@ -2346,8 +2346,7 @@ pub fn wrap_struct_field(
|
||||
one_line_width: usize,
|
||||
) -> String {
|
||||
if context.config.indent_style() == IndentStyle::Block
|
||||
&& (fields_str.contains('\n')
|
||||
|| context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti
|
||||
&& (fields_str.contains('\n') || !context.config.struct_lit_single_line()
|
||||
|| fields_str.len() > one_line_width)
|
||||
{
|
||||
format!(
|
||||
|
@ -796,7 +796,8 @@ pub fn struct_lit_tactic(
|
||||
if let Some(h_shape) = h_shape {
|
||||
let prelim_tactic = match (context.config.indent_style(), items.len()) {
|
||||
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
|
||||
_ => context.config.struct_lit_multiline_style().to_list_tactic(),
|
||||
_ if context.config.struct_lit_single_line() => ListTactic::HorizontalVertical,
|
||||
_ => ListTactic::Vertical,
|
||||
};
|
||||
definitive_tactic(items, prelim_tactic, Separator::Comma, h_shape.width)
|
||||
} else {
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
// Struct literal multiline-style
|
||||
|
||||
fn main() {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-struct_lit_multiline_style: PreferSingle
|
||||
// rustfmt-struct_lit_single_line: true
|
||||
// rustfmt-struct_lit_width: 100
|
||||
// Struct literal multiline-style
|
||||
|
@ -1,6 +1,6 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
|
||||
// Struct literal expressions.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-indent_style: Visual
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
// rustfmt-error_on_line_overflow: false
|
||||
|
||||
// Struct literal expressions.
|
||||
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
// Struct literal multiline-style
|
||||
|
||||
fn main() {
|
@ -1,4 +1,4 @@
|
||||
// rustfmt-struct_lit_multiline_style: PreferSingle
|
||||
// rustfmt-struct_lit_single_line: true
|
||||
// rustfmt-struct_lit_width: 100
|
||||
// Struct literal multiline-style
|
||||
|
@ -1,6 +1,6 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
|
||||
// Struct literal expressions.
|
||||
|
||||
|
@ -1,7 +1,7 @@
|
||||
// rustfmt-normalize_comments: true
|
||||
// rustfmt-wrap_comments: true
|
||||
// rustfmt-indent_style: Visual
|
||||
// rustfmt-struct_lit_multiline_style: ForceMulti
|
||||
// rustfmt-struct_lit_single_line: false
|
||||
// rustfmt-error_on_line_overflow: false
|
||||
|
||||
// Struct literal expressions.
|
||||
|
Loading…
x
Reference in New Issue
Block a user