Skip to content

Rename config options related to indent #2116

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

Merged
merged 5 commits into from
Nov 5, 2017
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
30 changes: 15 additions & 15 deletions Configurations.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ Rustfmt is designed to be very configurable. You can create a TOML file called `
A possible content of `rustfmt.toml` or `.rustfmt.toml` might look like this:

```toml
array_layout = "Block"
array_indent = "Block"
array_width = 80
reorder_imported_names = true
```
Expand All @@ -22,7 +22,7 @@ Use this option to prevent a huge array from being vertically formatted.
- **Default value**: `0`
- **Possible values**: any positive integer

**Note:** A value of `0` results in [`array_layout`](#array_layout) being applied regardless of a line's width.
**Note:** A value of `0` results in [`array_indent`](#array_indent) being applied regardless of a line's width.

#### `0` (default):

Expand Down Expand Up @@ -50,7 +50,7 @@ let a = vec![
];
```

## `array_layout`
## `array_indent`

Indent on arrays

Expand Down Expand Up @@ -90,15 +90,15 @@ Maximum width of an array literal before falling back to vertical formatting
- **Default value**: `60`
- **Possible values**: any positive integer

**Note:** A value of `0` results in [`array_layout`](#array_layout) being applied regardless of a line's width.
**Note:** A value of `0` results in [`array_indent`](#array_indent) being applied regardless of a line's width.

#### Lines shorter than `array_width`:
```rust
let lorem = vec!["ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "elit"];
```

#### Lines longer than `array_width`:
See [`array_layout`](#array_layout).
See [`array_indent`](#array_indent).

## `attributes_on_same_line_as_field`

Expand Down Expand Up @@ -298,7 +298,7 @@ lorem_ipsum(|| {
});
```

**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
**Note**: This option only takes effect when `fn_call_indent` is set to `"Visual"`.

## `combine_control_expr`

Expand Down Expand Up @@ -614,7 +614,7 @@ trait Lorem {
}
```

## `fn_args_layout`
## `fn_args_indent`

Layout of function arguments and tuple structs

Expand Down Expand Up @@ -758,7 +758,7 @@ where
}
```

## `fn_call_style`
## `fn_call_indent`

Indentation for function calls, etc.

Expand Down Expand Up @@ -809,7 +809,7 @@ lorem("lorem", "ipsum", "dolor", "sit", "amet", "consectetur", "adipiscing", "el

#### Function call longer than `fn_call_width`:

See [`fn_call_style`](#fn_call_style).
See [`fn_call_indent`](#fn_call_indent).

## `fn_empty_single_line`

Expand Down Expand Up @@ -874,7 +874,7 @@ fn lorem(ipsum: Ipsum,

```

**Note**: This option only takes effect when `fn_call_style` is set to `"Visual"`.
**Note**: This option only takes effect when `fn_call_indent` is set to `"Visual"`.

## `fn_single_line`

Expand Down Expand Up @@ -1868,9 +1868,9 @@ let lorem = Lorem {
};
```

See also: [`struct_lit_style`](#struct_lit_style), [`struct_lit_width`](#struct_lit_width).
See also: [`struct_lit_indent`](#struct_lit_indent), [`struct_lit_width`](#struct_lit_width).

## `struct_lit_style`
## `struct_lit_indent`

Style of struct definition

Expand All @@ -1893,7 +1893,7 @@ let lorem = Lorem { ipsum: dolor,
sit: amet, };
```

See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_indent`](#struct_lit_indent).

## `struct_lit_width`

Expand All @@ -1910,9 +1910,9 @@ let lorem = Lorem { ipsum: dolor, sit: amet };
```

#### Lines longer than `struct_lit_width`:
See [`struct_lit_style`](#struct_lit_style).
See [`struct_lit_indent`](#struct_lit_indent).

See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_style`](#struct_lit_style).
See also: [`struct_lit_multiline_style`](#struct_lit_multiline_style), [`struct_lit_indent`](#struct_lit_indent).

## `struct_variant_width`

Expand Down
6 changes: 3 additions & 3 deletions legacy-rustfmt.toml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
fn_args_layout = "Visual"
array_layout = "Visual"
fn_args_indent = "Visual"
array_indent = "Visual"
control_style = "Legacy"
where_style = "Legacy"
generics_indent = "Visual"
fn_call_style = "Visual"
fn_call_indent = "Visual"
combine_control_expr = false
fn_args_paren_newline = true
8 changes: 4 additions & 4 deletions src/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -559,9 +559,9 @@ create_config! {
"Location of return type in function declaration";
fn_args_paren_newline: bool, false, false, "If function argument parenthesis goes on a newline";
fn_args_density: Density, Density::Tall, false, "Argument density in functions";
fn_args_layout: IndentStyle, IndentStyle::Block, false,
fn_args_indent: IndentStyle, IndentStyle::Block, false,
"Layout of function arguments and tuple structs";
array_layout: IndentStyle, IndentStyle::Block, false, "Indent on arrays";
array_indent: IndentStyle, IndentStyle::Block, false, "Indent on arrays";
array_width: usize, 60, false,
"Maximum width of an array literal before falling back to vertical formatting";
array_horizontal_layout_threshold: usize, 0, false,
Expand All @@ -578,10 +578,10 @@ create_config! {
where_pred_indent: IndentStyle, IndentStyle::Visual, false,
"Indentation style of a where predicate";
generics_indent: IndentStyle, IndentStyle::Block, false, "Indentation of generics";
struct_lit_style: IndentStyle, IndentStyle::Block, false, "Style of struct definition";
struct_lit_indent: IndentStyle, IndentStyle::Block, false, "Style of struct definition";
struct_lit_multiline_style: MultilineStyle, MultilineStyle::PreferSingle, false,
"Multiline style on literal structs";
fn_call_style: IndentStyle, IndentStyle::Block, false, "Indentation for function calls, etc.";
fn_call_indent: IndentStyle, IndentStyle::Block, false, "Indentation for function calls, etc.";
report_todo: ReportTactic, ReportTactic::Never, false,
"Report all, none or unnumbered occurrences of TODO in source file comments";
report_fixme: ReportTactic, ReportTactic::Never, false,
Expand Down
22 changes: 11 additions & 11 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -419,7 +419,7 @@ where
1 // "["
};

let nested_shape = match context.config.array_layout() {
let nested_shape = match context.config.array_indent() {
IndentStyle::Block => shape
.block()
.block_indent(context.config.tab_spaces())
Expand Down Expand Up @@ -454,7 +454,7 @@ where
.iter()
.any(|li| li.item.as_ref().map(|s| s.len() > 10).unwrap_or(false));

let mut tactic = match context.config.array_layout() {
let mut tactic = match context.config.array_indent() {
IndentStyle::Block => {
// FIXME wrong shape in one-line case
match shape.width.checked_sub(2 * bracket_size) {
Expand All @@ -477,7 +477,7 @@ where
DefinitiveListTactic::Mixed
},
};
let ends_with_newline = tactic.ends_with_newline(context.config.array_layout());
let ends_with_newline = tactic.ends_with_newline(context.config.array_indent());
if context.config.array_horizontal_layout_threshold() > 0
&& items.len() > context.config.array_horizontal_layout_threshold()
{
Expand All @@ -489,7 +489,7 @@ where
separator: ",",
trailing_separator: if trailing_comma {
SeparatorTactic::Always
} else if context.inside_macro || context.config.array_layout() == IndentStyle::Visual {
} else if context.inside_macro || context.config.array_indent() == IndentStyle::Visual {
SeparatorTactic::Never
} else {
SeparatorTactic::Vertical
Expand All @@ -502,7 +502,7 @@ where
};
let list_str = write_list(&items, &fmt)?;

let result = if context.config.array_layout() == IndentStyle::Visual
let result = if context.config.array_indent() == IndentStyle::Visual
|| tactic == DefinitiveListTactic::Horizontal
{
if context.config.spaces_within_square_brackets() && !list_str.is_empty() {
Expand Down Expand Up @@ -2033,7 +2033,7 @@ where
let used_width = extra_offset(callee_str, shape);
let one_line_width = shape.width.checked_sub(used_width + 2 * paren_overhead)?;

let nested_shape = shape_from_fn_call_style(
let nested_shape = shape_from_fn_call_indent(
context,
shape,
used_width + 2 * paren_overhead,
Expand Down Expand Up @@ -2379,7 +2379,7 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
match expr.node {
ast::ExprKind::Match(..) => {
(context.use_block_indent() && args_len == 1)
|| (context.config.fn_call_style() == IndentStyle::Visual && args_len > 1)
|| (context.config.fn_call_indent() == IndentStyle::Visual && args_len > 1)
}
ast::ExprKind::If(..) |
ast::ExprKind::IfLet(..) |
Expand All @@ -2391,7 +2391,7 @@ pub fn can_be_overflowed_expr(context: &RewriteContext, expr: &ast::Expr, args_l
}
ast::ExprKind::Block(..) | ast::ExprKind::Closure(..) => {
context.use_block_indent()
|| context.config.fn_call_style() == IndentStyle::Visual && args_len > 1
|| context.config.fn_call_indent() == IndentStyle::Visual && args_len > 1
}
ast::ExprKind::Array(..) |
ast::ExprKind::Call(..) |
Expand Down Expand Up @@ -2640,7 +2640,7 @@ fn rewrite_struct_lit<'a>(
let fields_str = wrap_struct_field(context, &fields_str, shape, v_shape, one_line_width);
Some(format!("{} {{{}}}", path_str, fields_str))

// FIXME if context.config.struct_lit_style() == Visual, but we run out
// FIXME if context.config.struct_lit_indent() == Visual, but we run out
// of space, we should fall back to BlockIndent.
}

Expand All @@ -2651,7 +2651,7 @@ pub fn wrap_struct_field(
nested_shape: Shape,
one_line_width: usize,
) -> String {
if context.config.struct_lit_style() == IndentStyle::Block
if context.config.struct_lit_indent() == IndentStyle::Block
&& (fields_str.contains('\n')
|| context.config.struct_lit_multiline_style() == MultilineStyle::ForceMulti
|| fields_str.len() > one_line_width)
Expand Down Expand Up @@ -2722,7 +2722,7 @@ pub fn rewrite_field(
}
}

fn shape_from_fn_call_style(
fn shape_from_fn_call_indent(
context: &RewriteContext,
shape: Shape,
overhead: usize,
Expand Down
20 changes: 10 additions & 10 deletions src/items.rs
Original file line number Diff line number Diff line change
Expand Up @@ -933,8 +933,8 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
let has_body = !trait_items.is_empty();

let where_density = if (context.config.where_density() == Density::Compressed
&& (!result.contains('\n') || context.config.fn_args_layout() == IndentStyle::Block))
|| (context.config.fn_args_layout() == IndentStyle::Block && result.is_empty())
&& (!result.contains('\n') || context.config.fn_args_indent() == IndentStyle::Block))
|| (context.config.fn_args_indent() == IndentStyle::Block && result.is_empty())
|| (context.config.where_density() == Density::CompressedIfEmpty && !has_body
&& !result.contains('\n'))
{
Expand Down Expand Up @@ -1746,13 +1746,13 @@ fn rewrite_fn_base(
} else if context.config.fn_args_paren_newline() {
result.push('\n');
result.push_str(&arg_indent.to_string(context.config));
if context.config.fn_args_layout() == IndentStyle::Visual {
if context.config.fn_args_indent() == IndentStyle::Visual {
arg_indent = arg_indent + 1; // extra space for `(`
}
result.push('(');
} else {
result.push_str("(");
if context.config.fn_args_layout() == IndentStyle::Visual {
if context.config.fn_args_indent() == IndentStyle::Visual {
result.push('\n');
result.push_str(&arg_indent.to_string(context.config));
}
Expand Down Expand Up @@ -1805,7 +1805,7 @@ fn rewrite_fn_base(
generics_str.contains('\n'),
)?;

let put_args_in_block = match context.config.fn_args_layout() {
let put_args_in_block = match context.config.fn_args_indent() {
IndentStyle::Block => arg_str.contains('\n') || arg_str.len() > one_line_budget,
_ => false,
} && !fd.inputs.is_empty();
Expand Down Expand Up @@ -1846,7 +1846,7 @@ fn rewrite_fn_base(

// Return type.
if let ast::FunctionRetTy::Ty(..) = fd.output {
let ret_should_indent = match context.config.fn_args_layout() {
let ret_should_indent = match context.config.fn_args_indent() {
// If our args are block layout then we surely must have space.
IndentStyle::Block if put_args_in_block || fd.inputs.is_empty() => false,
_ if args_last_line_contains_comment => false,
Expand Down Expand Up @@ -2131,7 +2131,7 @@ fn rewrite_args(
.and_then(|item| item.post_comment.as_ref())
.map_or(false, |s| s.trim().starts_with("//"));

let (indent, trailing_comma) = match context.config.fn_args_layout() {
let (indent, trailing_comma) = match context.config.fn_args_indent() {
IndentStyle::Block if fits_in_one_line => {
(indent.block_indent(context.config), SeparatorTactic::Never)
}
Expand Down Expand Up @@ -2168,7 +2168,7 @@ fn rewrite_args(
},
separator_place: SeparatorPlace::Back,
shape: Shape::legacy(budget, indent),
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_layout()),
ends_with_newline: tactic.ends_with_newline(context.config.fn_args_indent()),
preserve_newline: true,
config: context.config,
};
Expand Down Expand Up @@ -2218,7 +2218,7 @@ fn compute_budgets_for_args(

if one_line_budget > 0 {
// 4 = "() {".len()
let (indent, multi_line_budget) = match context.config.fn_args_layout() {
let (indent, multi_line_budget) = match context.config.fn_args_indent() {
IndentStyle::Block => {
let indent = indent.block_indent(context.config);
(indent, context.budget(indent.width() + 1))
Expand All @@ -2236,7 +2236,7 @@ fn compute_budgets_for_args(

// Didn't work. we must force vertical layout and put args on a newline.
let new_indent = indent.block_indent(context.config);
let used_space = match context.config.fn_args_layout() {
let used_space = match context.config.fn_args_indent() {
// 1 = `,`
IndentStyle::Block => new_indent.width() + 1,
// Account for `)` and possibly ` {`.
Expand Down
6 changes: 3 additions & 3 deletions src/lists.rs
Original file line number Diff line number Diff line change
Expand Up @@ -737,7 +737,7 @@ pub fn struct_lit_shape(
prefix_width: usize,
suffix_width: usize,
) -> Option<(Option<Shape>, Shape)> {
let v_shape = match context.config.struct_lit_style() {
let v_shape = match context.config.struct_lit_indent() {
IndentStyle::Visual => shape
.visual_indent(0)
.shrink_left(prefix_width)?
Expand Down Expand Up @@ -766,7 +766,7 @@ pub fn struct_lit_tactic(
items: &[ListItem],
) -> DefinitiveListTactic {
if let Some(h_shape) = h_shape {
let prelim_tactic = match (context.config.struct_lit_style(), items.len()) {
let prelim_tactic = match (context.config.struct_lit_indent(), items.len()) {
(IndentStyle::Visual, 1) => ListTactic::HorizontalVertical,
_ => context.config.struct_lit_multiline_style().to_list_tactic(),
};
Expand Down Expand Up @@ -797,7 +797,7 @@ pub fn struct_lit_formatting<'a>(
context: &'a RewriteContext,
force_no_trailing_comma: bool,
) -> ListFormatting<'a> {
let ends_with_newline = context.config.struct_lit_style() != IndentStyle::Visual
let ends_with_newline = context.config.struct_lit_indent() != IndentStyle::Visual
&& tactic == DefinitiveListTactic::Vertical;
ListFormatting {
tactic: tactic,
Expand Down
2 changes: 1 addition & 1 deletion src/rewrite.rs
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ impl<'a> RewriteContext<'a> {

/// Return true if we should use block indent style for rewriting function call.
pub fn use_block_indent(&self) -> bool {
self.config.fn_call_style() == IndentStyle::Block || self.use_block
self.config.fn_call_indent() == IndentStyle::Block || self.use_block
}

pub fn budget(&self, used_width: usize) -> usize {
Expand Down
Loading