}
```
-See also: [`where_density`](#where_density), [`where_layout`](#where_layout).
-
## `same_line_attributes`
let lorem = ipsum.map(|dolor| dolor.sit())?;
```
-## `where_density`
-
-Density of a where clause.
-
-- **Default value**: `"Vertical"`
-- **Possible values**: `"Compressed"`, `"CompressedIfEmpty"`, `"Tall"`, `"Vertical"`
-
-#### `"Vertical"` (default):
-
-```rust
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
-```
-
-**Note:** `where_density = "Vertical"` currently produces the same output as `where_density = "Tall"`.
-
-#### `"CompressedIfEmpty"`:
-
-```rust
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
-```
-
-#### `"Compressed"`:
-
-```rust
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq {
- // body
- }
-}
-```
-
-#### `"Tall"`:
-
-```rust
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
-```
-
-**Note:** `where_density = "Tall"` currently produces the same output as `where_density = "Vertical"`.
-
-See also: [`where_layout`](#where_layout), [`indent_style`](#indent_style).
-
-## `where_layout`
-
-Element layout inside a where clause
-
-- **Default value**: `"Vertical"`
-- **Possible values**: `"Horizontal"`, `"HorizontalVertical"`, `"Mixed"`, `"Vertical"`
-
-#### `"Vertical"` (default):
-
-```rust
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
- where Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
- where Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit
-{
- // body
-}
-```
-
-#### `"Horizontal"`:
-
-```rust
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
- where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
- where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
-{
- // body
-}
-```
-
-#### `"HorizontalVertical"`:
-
-```rust
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
- where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
- where Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit
-{
- // body
-}
-```
-
-#### `"Mixed"`:
-
-```rust
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
- where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
- where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
-{
- // body
-}
-```
-
-See also: [`where_density`](#where_density), [`indent_style`](#indent_style).
## `wrap_comments`
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
-
- // Where clauses
- // TODO:
- // 1. Should we at least try to put the where clause on the same line as the rest of the
- // function decl?
- // 2. Currently options `Tall` and `Vertical` produce the same output.
- 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";
// Imports
imports_indent: IndentStyle, IndentStyle::Visual, false, "Indent of imports";
) -> Option<String> {
let context = self.get_context();
- let has_body =
- !is_empty_block(block, self.codemap) || !context.config.fn_empty_single_line();
- let mut newline_brace =
- newline_for_brace(self.config, &fn_sig.generics.where_clause, has_body);
+ let mut newline_brace = newline_for_brace(self.config, &fn_sig.generics.where_clause);
let (mut result, force_newline_brace) =
rewrite_fn_base(&context, indent, ident, fn_sig, span, newline_brace, true)?;
&generics.where_clause,
context.config.brace_style(),
Shape::legacy(where_budget, offset.block_only()),
- context.config.where_density(),
+ Density::Vertical,
"{",
where_span_end,
self_ty.span.hi(),
}
result.push_str(&trait_bound_str);
- let has_body = !trait_items.is_empty();
-
- let where_density = if (context.config.where_density() == Density::Compressed
- && (!result.contains('\n') || context.config.indent_style() == IndentStyle::Block))
- || (context.config.indent_style() == IndentStyle::Block && result.is_empty())
- || (context.config.where_density() == Density::CompressedIfEmpty && !has_body
- && !result.contains('\n'))
- {
- Density::Compressed
- } else {
- Density::Tall
- };
+ let where_density =
+ if context.config.indent_style() == IndentStyle::Block && result.is_empty() {
+ Density::Compressed
+ } else {
+ Density::Tall
+ };
let where_budget = context.budget(last_line_width(&result));
let pos_before_where = if type_param_bounds.is_empty() {
&generics.where_clause,
context.config.brace_style(),
Shape::legacy(where_budget, indent),
- context.config.where_density(),
+ Density::Vertical,
"=",
Some(span.hi()),
generics.span.hi(),
}
}
- let should_compress_where = match context.config.where_density() {
- Density::Compressed => !result.contains('\n'),
- Density::CompressedIfEmpty => !has_body && !result.contains('\n'),
- _ => false,
- };
-
let pos_before_where = match fd.output {
ast::FunctionRetTy::Default(..) => args_span.hi(),
ast::FunctionRetTy::Ty(ref ty) => ty.span.hi(),
let is_args_multi_lined = arg_str.contains('\n');
- if where_clause.predicates.len() == 1 && should_compress_where {
- let budget = context.budget(last_line_used_width(&result, indent.width()));
- if let Some(where_clause_str) = rewrite_where_clause(
- context,
- where_clause,
- context.config.brace_style(),
- Shape::legacy(budget, indent),
- Density::Compressed,
- "{",
- Some(span.hi()),
- pos_before_where,
- WhereClauseOption::compressed(),
- is_args_multi_lined,
- ) {
- result.push_str(&where_clause_str);
- force_new_line_for_brace |= last_line_contains_single_line_comment(&result);
- return Some((result, force_new_line_for_brace));
- }
- }
-
let option = WhereClauseOption::new(!has_body, put_args_in_block && ret_str.is_empty());
let where_clause_str = rewrite_where_clause(
context,
}
}
- pub fn compressed() -> WhereClauseOption {
- WhereClauseOption {
- suppress_comma: true,
- snuggle: false,
- compress_where: true,
- }
- }
-
pub fn snuggled(current: &str) -> WhereClauseOption {
WhereClauseOption {
suppress_comma: false,
Some((0, context.budget(used_space), new_indent))
}
-fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause, has_body: bool) -> bool {
+fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause) -> bool {
let predicate_count = where_clause.predicates.len();
if config.where_single_line() && predicate_count == 1 {
return false;
}
- match (config.brace_style(), config.where_density()) {
- (BraceStyle::AlwaysNextLine, _) => true,
- (_, Density::Compressed) if predicate_count == 1 => false,
- (_, Density::CompressedIfEmpty) if predicate_count == 1 && !has_body => false,
- (BraceStyle::SameLineWhere, _) if predicate_count > 0 => true,
- _ => false,
- }
+ let brace_style = config.brace_style();
+
+ brace_style == BraceStyle::AlwaysNextLine
+ || (brace_style == BraceStyle::SameLineWhere && predicate_count > 0)
}
fn rewrite_generics(
false,
);
let item_vec = items.collect::<Vec<_>>();
- // FIXME: we don't need to collect here if the where_layout isn't
- // HorizontalVertical.
- let tactic = definitive_tactic(
- &item_vec,
- context.config.where_layout(),
- Separator::Comma,
- budget,
- );
+ // FIXME: we don't need to collect here
+ let tactic = definitive_tactic(&item_vec, ListTactic::Vertical, Separator::Comma, budget);
let mut comma_tactic = context.config.trailing_comma();
// Kind of a hack because we don't usually have trailing commas in where clauses.
newline_style = "Unix"
brace_style = "SameLineWhere"
fn_args_density = "Tall"
-where_density = "Tall"
-where_layout = "Vertical"
trailing_comma = "Vertical"
indent_style = "Block"
report_todo = "Always"
+++ /dev/null
-// rustfmt-where_density: Compressed
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: CompressedIfEmpty
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: Tall
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: Vertical
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit where Dolor: Eq {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_layout: Horizontal
-// rustfmt-error_on_line_overflow: false
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur {
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit {
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: HorizontalVertical
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur {
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit {
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: Mixed
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur {
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit {
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: Vertical
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur {
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet) where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit {
- // body
-}
// rustfmt-indent_style: Block
-// rustfmt-where_layout: Mixed
// Test different indents.
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
// rustfmt-indent_style: Block
-// rustfmt-where_layout: HorizontalVertical
// Test different indents.
fn foo(a: Aaaaaaaaaaaaaaa, b: Bbbbbbbbbbbbbbbb, c: Ccccccccccccccccc, d: Ddddddddddddddddddddddddd, e: Eeeeeeeeeeeeeeeeeee) {
// rustfmt-indent_style: Block
-// rustfmt-where_density: Compressed
// Test different indents.
fn qux() where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT, X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT {
+++ /dev/null
-// rustfmt-where_density: Compressed
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: CompressedIfEmpty
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: Tall
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_density: Vertical
-// Where density
-
-trait Lorem {
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq;
-
- fn ipsum<Dolor>(dolor: Dolor) -> Sit
- where
- Dolor: Eq,
- {
- // body
- }
-}
+++ /dev/null
-// rustfmt-where_layout: Horizontal
-// rustfmt-error_on_line_overflow: false
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit,
-{
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: HorizontalVertical
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit,
-{
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: Mixed
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit,
-{
- // body
-}
+++ /dev/null
-// rustfmt-where_layout: Vertical
-// Where layout
-
-fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
-{
- // body
-}
-
-fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
-where
- Ipsum: IpsumDolorSitAmet,
- Dolor: DolorSitAmetConsectetur,
- Sit: SitAmetConsecteturAdipiscing,
- Amet: AmetConsecteturAdipiscingElit,
-{
- // body
-}
// rustfmt-indent_style: Block
-// rustfmt-where_layout: Mixed
// Test different indents.
fn foo(
// rustfmt-indent_style: Block
-// rustfmt-where_layout: HorizontalVertical
// Test different indents.
fn foo(
// rustfmt-indent_style: Block
-// rustfmt-where_density: Compressed
// Test different indents.
fn qux()
}
fn qux()
-where X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT {
+where
+ X: TTTTTTTTTTTTTTTTTTTTTTTTTTTT,
+{
baz();
}