Skip to content

Commit 27932f2

Browse files
fix: skip brace style for where clause in compute_budgets_for_params + tests for issue 6539
1 parent e554eba commit 27932f2

File tree

9 files changed

+156
-22
lines changed

9 files changed

+156
-22
lines changed

src/items.rs

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2500,6 +2500,7 @@ fn rewrite_fn_base(
25002500
ret_str_len,
25012501
fn_brace_style,
25022502
multi_line_ret_str,
2503+
where_clause,
25032504
);
25042505

25052506
debug!(
@@ -2899,6 +2900,7 @@ fn compute_budgets_for_params(
28992900
ret_str_len: usize,
29002901
fn_brace_style: FnBraceStyle,
29012902
force_vertical_layout: bool,
2903+
where_clause: &ast::WhereClause,
29022904
) -> (usize, usize, Indent) {
29032905
debug!(
29042906
"compute_budgets_for_params {} {:?}, {}, {:?}",
@@ -2913,7 +2915,15 @@ fn compute_budgets_for_params(
29132915
let overhead = if ret_str_len == 0 { 2 } else { 3 };
29142916
let mut used_space = indent.width() + result.len() + ret_str_len + overhead;
29152917
match fn_brace_style {
2916-
FnBraceStyle::None => used_space += 1, // 1 = `;`
2918+
_ if context.config.style_edition() >= StyleEdition::Edition2027
2919+
&& where_clause.predicates.len() > 0 =>
2920+
{
2921+
// Don't add anything to `used_space` if we have a where clause.
2922+
// For all `FnBraceStyle` values if we have a where cluase that can't fit
2923+
// on the current line it'll be written to the next line.
2924+
// Therefore, we don't need to account for a trailing `;` or `{}`
2925+
}
2926+
FnBraceStyle::None => used_space += 1, // 1 = `;`
29172927
FnBraceStyle::SameLine => used_space += 2, // 2 = `{}`
29182928
FnBraceStyle::NextLine => (),
29192929
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-brace_style: AlwaysNextLine
3+
// rustfmt-where_single_line: false
4+
5+
pub trait Trait
6+
{
7+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
8+
9+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64 where T: Debug;
10+
11+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(&self, aaa: T, bbb: f64) -> f64 where T: Debug;
12+
13+
fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {}
14+
15+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64 where T: Debug {}
16+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-brace_style: AlwaysNextLine
3+
// rustfmt-where_single_line: true
4+
5+
pub trait Trait
6+
{
7+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
8+
9+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64 where T: Debug;
10+
11+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(&self, aaa: T, bbb: f64) -> f64 where T: Debug;
12+
13+
fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {}
14+
15+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64 where T: Debug {}
16+
}

tests/source/issue-6539/default.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
// rustfmt-style_edition: 2027
2+
3+
pub trait Trait {
4+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
5+
6+
fn a_one_hundred_one_column_fn_decl_no_body(self, a: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
7+
8+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64 where T: Debug;
9+
10+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(&self, aaa: T, bbb: f64) -> f64 where T: Debug;
11+
12+
fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {}
13+
14+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64 where T: Debug {}
15+
}

tests/source/issue-6539/issue_example.rs

Lines changed: 0 additions & 7 deletions
This file was deleted.
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-brace_style: AlwaysNextLine
3+
// rustfmt-where_single_line: false
4+
5+
pub trait Trait
6+
{
7+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
8+
9+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64
10+
where
11+
T: Debug;
12+
13+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(
14+
&self,
15+
aaa: T,
16+
bbb: f64,
17+
) -> f64
18+
where
19+
T: Debug;
20+
21+
fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64
22+
{
23+
}
24+
25+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64
26+
where
27+
T: Debug,
28+
{
29+
}
30+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
// rustfmt-style_edition: 2027
2+
// rustfmt-brace_style: AlwaysNextLine
3+
// rustfmt-where_single_line: true
4+
5+
pub trait Trait
6+
{
7+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
8+
9+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64
10+
where T: Debug;
11+
12+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(
13+
&self,
14+
aaa: T,
15+
bbb: f64,
16+
) -> f64
17+
where
18+
T: Debug;
19+
20+
fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64
21+
{
22+
}
23+
24+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64
25+
where T: Debug
26+
{
27+
}
28+
}

tests/target/issue-6539/default.rs

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// rustfmt-style_edition: 2027
2+
3+
pub trait Trait {
4+
fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64;
5+
6+
fn a_one_hundred_one_column_fn_decl_no_body(
7+
self,
8+
a: f64,
9+
b: f64,
10+
c: f64,
11+
d: f64,
12+
e: f64,
13+
) -> f64;
14+
15+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause<T>(&self, a: T, bb: f64) -> f64
16+
where
17+
T: Debug;
18+
19+
fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2<T>(
20+
&self,
21+
aaa: T,
22+
bbb: f64,
23+
) -> f64
24+
where
25+
T: Debug;
26+
27+
fn an_over_one_hundred_column_fn_decl_with_body(
28+
&self,
29+
aaaaa: f64,
30+
bbbbb: f64,
31+
ccc: f64,
32+
) -> f64 {
33+
}
34+
35+
fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause<T>(&self, aaaaa: f64) -> f64
36+
where
37+
T: Debug,
38+
{
39+
}
40+
}

tests/target/issue-6539/issue_example.rs

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

0 commit comments

Comments
 (0)