Skip to content

Commit 86007e7

Browse files
committed
Remove where_density and where_layout options
There is a choice between block and visual indent for where clauses, plus the single line option. I think these two are too fine-grained to be useful.
1 parent abfa4a1 commit 86007e7

26 files changed

+19
-462
lines changed

Configurations.md

Lines changed: 0 additions & 159 deletions
Original file line numberDiff line numberDiff line change
@@ -241,8 +241,6 @@ fn lorem<Ipsum, Dolor, Sit, Amet>() -> T
241241
}
242242
```
243243

244-
See also: [`where_density`](#where_density), [`where_layout`](#where_layout).
245-
246244

247245
## `same_line_attributes`
248246

@@ -1869,163 +1867,6 @@ let lorem = try!(ipsum.map(|dolor|dolor.sit()));
18691867
let lorem = ipsum.map(|dolor| dolor.sit())?;
18701868
```
18711869

1872-
## `where_density`
1873-
1874-
Density of a where clause.
1875-
1876-
- **Default value**: `"Vertical"`
1877-
- **Possible values**: `"Compressed"`, `"CompressedIfEmpty"`, `"Tall"`, `"Vertical"`
1878-
1879-
#### `"Vertical"` (default):
1880-
1881-
```rust
1882-
trait Lorem {
1883-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1884-
where
1885-
Dolor: Eq;
1886-
1887-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1888-
where
1889-
Dolor: Eq,
1890-
{
1891-
// body
1892-
}
1893-
}
1894-
```
1895-
1896-
**Note:** `where_density = "Vertical"` currently produces the same output as `where_density = "Tall"`.
1897-
1898-
#### `"CompressedIfEmpty"`:
1899-
1900-
```rust
1901-
trait Lorem {
1902-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1903-
where Dolor: Eq;
1904-
1905-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1906-
where
1907-
Dolor: Eq,
1908-
{
1909-
// body
1910-
}
1911-
}
1912-
```
1913-
1914-
#### `"Compressed"`:
1915-
1916-
```rust
1917-
trait Lorem {
1918-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1919-
where Dolor: Eq;
1920-
1921-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1922-
where Dolor: Eq {
1923-
// body
1924-
}
1925-
}
1926-
```
1927-
1928-
#### `"Tall"`:
1929-
1930-
```rust
1931-
trait Lorem {
1932-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1933-
where
1934-
Dolor: Eq;
1935-
1936-
fn ipsum<Dolor>(dolor: Dolor) -> Sit
1937-
where
1938-
Dolor: Eq,
1939-
{
1940-
// body
1941-
}
1942-
}
1943-
```
1944-
1945-
**Note:** `where_density = "Tall"` currently produces the same output as `where_density = "Vertical"`.
1946-
1947-
See also: [`where_layout`](#where_layout), [`indent_style`](#indent_style).
1948-
1949-
## `where_layout`
1950-
1951-
Element layout inside a where clause
1952-
1953-
- **Default value**: `"Vertical"`
1954-
- **Possible values**: `"Horizontal"`, `"HorizontalVertical"`, `"Mixed"`, `"Vertical"`
1955-
1956-
#### `"Vertical"` (default):
1957-
1958-
```rust
1959-
fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1960-
where Ipsum: IpsumDolorSitAmet,
1961-
Dolor: DolorSitAmetConsectetur
1962-
{
1963-
// body
1964-
}
1965-
1966-
fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1967-
where Ipsum: IpsumDolorSitAmet,
1968-
Dolor: DolorSitAmetConsectetur,
1969-
Sit: SitAmetConsecteturAdipiscing,
1970-
Amet: AmetConsecteturAdipiscingElit
1971-
{
1972-
// body
1973-
}
1974-
```
1975-
1976-
#### `"Horizontal"`:
1977-
1978-
```rust
1979-
fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1980-
where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
1981-
{
1982-
// body
1983-
}
1984-
1985-
fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
1986-
where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur, Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
1987-
{
1988-
// body
1989-
}
1990-
```
1991-
1992-
#### `"HorizontalVertical"`:
1993-
1994-
```rust
1995-
fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
1996-
where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
1997-
{
1998-
// body
1999-
}
2000-
2001-
fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
2002-
where Ipsum: IpsumDolorSitAmet,
2003-
Dolor: DolorSitAmetConsectetur,
2004-
Sit: SitAmetConsecteturAdipiscing,
2005-
Amet: AmetConsecteturAdipiscingElit
2006-
{
2007-
// body
2008-
}
2009-
```
2010-
2011-
#### `"Mixed"`:
2012-
2013-
```rust
2014-
fn lorem<Ipsum, Dolor>(ipsum: Ipsum, dolor: Dolor)
2015-
where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur
2016-
{
2017-
// body
2018-
}
2019-
2020-
fn lorem<Ipsum, Dolor, Sit, Amet>(ipsum: Ipsum, dolor: Dolor, sit: Sit, amet: Amet)
2021-
where Ipsum: IpsumDolorSitAmet, Dolor: DolorSitAmetConsectetur,
2022-
Sit: SitAmetConsecteturAdipiscing, Amet: AmetConsecteturAdipiscingElit
2023-
{
2024-
// body
2025-
}
2026-
```
2027-
2028-
See also: [`where_density`](#where_density), [`indent_style`](#indent_style).
20291870

20301871
## `wrap_comments`
20311872

src/config.rs

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -604,15 +604,7 @@ create_config! {
604604
impl_empty_single_line: bool, true, false, "Put empty-body implementations on a single line";
605605
fn_empty_single_line: bool, true, false, "Put empty-body functions on a single line";
606606
fn_single_line: bool, false, false, "Put single-expression functions on a single line";
607-
608-
// Where clauses
609-
// TODO:
610-
// 1. Should we at least try to put the where clause on the same line as the rest of the
611-
// function decl?
612-
// 2. Currently options `Tall` and `Vertical` produce the same output.
613-
where_density: Density, Density::Vertical, false, "Density of a where clause";
614607
where_single_line: bool, false, false, "To force single line where layout";
615-
where_layout: ListTactic, ListTactic::Vertical, false, "Element layout inside a where clause";
616608

617609
// Imports
618610
imports_indent: IndentStyle, IndentStyle::Visual, false, "Indent of imports";

src/items.rs

Lines changed: 16 additions & 68 deletions
Original file line numberDiff line numberDiff line change
@@ -302,10 +302,7 @@ impl<'a> FmtVisitor<'a> {
302302
) -> Option<String> {
303303
let context = self.get_context();
304304

305-
let has_body =
306-
!is_empty_block(block, self.codemap) || !context.config.fn_empty_single_line();
307-
let mut newline_brace =
308-
newline_for_brace(self.config, &fn_sig.generics.where_clause, has_body);
305+
let mut newline_brace = newline_for_brace(self.config, &fn_sig.generics.where_clause);
309306

310307
let (mut result, force_newline_brace) =
311308
rewrite_fn_base(&context, indent, ident, fn_sig, span, newline_brace, true)?;
@@ -604,7 +601,7 @@ pub fn format_impl(
604601
&generics.where_clause,
605602
context.config.brace_style(),
606603
Shape::legacy(where_budget, offset.block_only()),
607-
context.config.where_density(),
604+
Density::Vertical,
608605
"{",
609606
where_span_end,
610607
self_ty.span.hi(),
@@ -978,18 +975,12 @@ pub fn format_trait(context: &RewriteContext, item: &ast::Item, offset: Indent)
978975
}
979976
result.push_str(&trait_bound_str);
980977

981-
let has_body = !trait_items.is_empty();
982-
983-
let where_density = if (context.config.where_density() == Density::Compressed
984-
&& (!result.contains('\n') || context.config.indent_style() == IndentStyle::Block))
985-
|| (context.config.indent_style() == IndentStyle::Block && result.is_empty())
986-
|| (context.config.where_density() == Density::CompressedIfEmpty && !has_body
987-
&& !result.contains('\n'))
988-
{
989-
Density::Compressed
990-
} else {
991-
Density::Tall
992-
};
978+
let where_density =
979+
if context.config.indent_style() == IndentStyle::Block && result.is_empty() {
980+
Density::Compressed
981+
} else {
982+
Density::Tall
983+
};
993984

994985
let where_budget = context.budget(last_line_width(&result));
995986
let pos_before_where = if type_param_bounds.is_empty() {
@@ -1373,7 +1364,7 @@ pub fn rewrite_type_alias(
13731364
&generics.where_clause,
13741365
context.config.brace_style(),
13751366
Shape::legacy(where_budget, indent),
1376-
context.config.where_density(),
1367+
Density::Vertical,
13771368
"=",
13781369
Some(span.hi()),
13791370
generics.span.hi(),
@@ -2027,39 +2018,13 @@ fn rewrite_fn_base(
20272018
}
20282019
}
20292020

2030-
let should_compress_where = match context.config.where_density() {
2031-
Density::Compressed => !result.contains('\n'),
2032-
Density::CompressedIfEmpty => !has_body && !result.contains('\n'),
2033-
_ => false,
2034-
};
2035-
20362021
let pos_before_where = match fd.output {
20372022
ast::FunctionRetTy::Default(..) => args_span.hi(),
20382023
ast::FunctionRetTy::Ty(ref ty) => ty.span.hi(),
20392024
};
20402025

20412026
let is_args_multi_lined = arg_str.contains('\n');
20422027

2043-
if where_clause.predicates.len() == 1 && should_compress_where {
2044-
let budget = context.budget(last_line_used_width(&result, indent.width()));
2045-
if let Some(where_clause_str) = rewrite_where_clause(
2046-
context,
2047-
where_clause,
2048-
context.config.brace_style(),
2049-
Shape::legacy(budget, indent),
2050-
Density::Compressed,
2051-
"{",
2052-
Some(span.hi()),
2053-
pos_before_where,
2054-
WhereClauseOption::compressed(),
2055-
is_args_multi_lined,
2056-
) {
2057-
result.push_str(&where_clause_str);
2058-
force_new_line_for_brace |= last_line_contains_single_line_comment(&result);
2059-
return Some((result, force_new_line_for_brace));
2060-
}
2061-
}
2062-
20632028
let option = WhereClauseOption::new(!has_body, put_args_in_block && ret_str.is_empty());
20642029
let where_clause_str = rewrite_where_clause(
20652030
context,
@@ -2115,14 +2080,6 @@ impl WhereClauseOption {
21152080
}
21162081
}
21172082

2118-
pub fn compressed() -> WhereClauseOption {
2119-
WhereClauseOption {
2120-
suppress_comma: true,
2121-
snuggle: false,
2122-
compress_where: true,
2123-
}
2124-
}
2125-
21262083
pub fn snuggled(current: &str) -> WhereClauseOption {
21272084
WhereClauseOption {
21282085
suppress_comma: false,
@@ -2355,19 +2312,16 @@ fn compute_budgets_for_args(
23552312
Some((0, context.budget(used_space), new_indent))
23562313
}
23572314

2358-
fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause, has_body: bool) -> bool {
2315+
fn newline_for_brace(config: &Config, where_clause: &ast::WhereClause) -> bool {
23592316
let predicate_count = where_clause.predicates.len();
23602317

23612318
if config.where_single_line() && predicate_count == 1 {
23622319
return false;
23632320
}
2364-
match (config.brace_style(), config.where_density()) {
2365-
(BraceStyle::AlwaysNextLine, _) => true,
2366-
(_, Density::Compressed) if predicate_count == 1 => false,
2367-
(_, Density::CompressedIfEmpty) if predicate_count == 1 && !has_body => false,
2368-
(BraceStyle::SameLineWhere, _) if predicate_count > 0 => true,
2369-
_ => false,
2370-
}
2321+
let brace_style = config.brace_style();
2322+
2323+
brace_style == BraceStyle::AlwaysNextLine
2324+
|| (brace_style == BraceStyle::SameLineWhere && predicate_count > 0)
23712325
}
23722326

23732327
fn rewrite_generics(
@@ -2694,14 +2648,8 @@ fn rewrite_where_clause(
26942648
false,
26952649
);
26962650
let item_vec = items.collect::<Vec<_>>();
2697-
// FIXME: we don't need to collect here if the where_layout isn't
2698-
// HorizontalVertical.
2699-
let tactic = definitive_tactic(
2700-
&item_vec,
2701-
context.config.where_layout(),
2702-
Separator::Comma,
2703-
budget,
2704-
);
2651+
// FIXME: we don't need to collect here
2652+
let tactic = definitive_tactic(&item_vec, ListTactic::Vertical, Separator::Comma, budget);
27052653

27062654
let mut comma_tactic = context.config.trailing_comma();
27072655
// Kind of a hack because we don't usually have trailing commas in where clauses.

tests/config/small_tabs.toml

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,6 @@ tab_spaces = 2
44
newline_style = "Unix"
55
brace_style = "SameLineWhere"
66
fn_args_density = "Tall"
7-
where_density = "Tall"
8-
where_layout = "Vertical"
97
trailing_comma = "Vertical"
108
indent_style = "Block"
119
report_todo = "Always"

tests/source/configs-where_density-compressed.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/source/configs-where_density-compressed_if_empty.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/source/configs-where_density-tall.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

tests/source/configs-where_density-vertical.rs

Lines changed: 0 additions & 10 deletions
This file was deleted.

0 commit comments

Comments
 (0)