From e554ebadc9146f270f938e6d0cd72e1760743f3d Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Sun, 15 Jun 2025 12:14:23 -0500 Subject: [PATCH 1/4] fix: wrap function without a body exceeding 100 characters (#6539) Co-authored-by: Yacin Tmimi --- src/items.rs | 16 +++++++++++++--- tests/source/issue-6539/issue_example.rs | 7 +++++++ tests/target/issue-6539/issue_example.rs | 14 ++++++++++++++ 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 tests/source/issue-6539/issue_example.rs create mode 100644 tests/target/issue-6539/issue_example.rs diff --git a/src/items.rs b/src/items.rs index 0e814644304..be01a2af3ab 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2602,10 +2602,20 @@ fn rewrite_fn_base( // the closing parenthesis of the param and the arrow '->' is considered. let mut sig_length = result.len() + indent.width() + ret_str_len + 1; - // If there is no where-clause, take into account the space after the return type - // and the brace. + // If there is no where-clause. if where_clause.predicates.is_empty() { - sig_length += 2; + if context.config.style_edition() >= StyleEdition::Edition2027 { + let line_ending_overhead = match fn_brace_style { + FnBraceStyle::NextLine => 0, // No brace to account for + FnBraceStyle::SameLine => 2, // Trailing space and brace, e.g. ` {` + FnBraceStyle::None => 1, // Trailing `;` + }; + sig_length += line_ending_overhead; + } else { + // Take into account the space after the return type and the brace. + // 2 = ' {' + sig_length += 2; + } } sig_length > context.config.max_width() diff --git a/tests/source/issue-6539/issue_example.rs b/tests/source/issue-6539/issue_example.rs new file mode 100644 index 00000000000..f386901684a --- /dev/null +++ b/tests/source/issue-6539/issue_example.rs @@ -0,0 +1,7 @@ +// rustfmt-style_edition: 2027 + +pub trait Trait { + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn a_one_hundred_one_column_fn_decl_no_body(self, a: f64, b: f64, c: f64, d: f64, e: f64) -> f64; +} diff --git a/tests/target/issue-6539/issue_example.rs b/tests/target/issue-6539/issue_example.rs new file mode 100644 index 00000000000..e061fe5c8a5 --- /dev/null +++ b/tests/target/issue-6539/issue_example.rs @@ -0,0 +1,14 @@ +// rustfmt-style_edition: 2027 + +pub trait Trait { + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn a_one_hundred_one_column_fn_decl_no_body( + self, + a: f64, + b: f64, + c: f64, + d: f64, + e: f64, + ) -> f64; +} From 14b815dccb4deba0f58b03dcede5964382b49e59 Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Sun, 15 Jun 2025 12:14:23 -0500 Subject: [PATCH 2/4] fix: skip brace style for `where` clause in compute_budgets_for_params + tests for issue 6539 Co-authored-by: Yacin Tmimi --- src/items.rs | 12 +++++- tests/source/issue-6539/brace_next_line.rs | 16 ++++++++ .../brace_next_line_where_single_line.rs | 16 ++++++++ tests/source/issue-6539/default.rs | 15 +++++++ tests/source/issue-6539/issue_example.rs | 7 ---- tests/target/issue-6539/brace_next_line.rs | 30 ++++++++++++++ .../brace_next_line_where_single_line.rs | 28 +++++++++++++ tests/target/issue-6539/default.rs | 40 +++++++++++++++++++ tests/target/issue-6539/issue_example.rs | 14 ------- 9 files changed, 156 insertions(+), 22 deletions(-) create mode 100644 tests/source/issue-6539/brace_next_line.rs create mode 100644 tests/source/issue-6539/brace_next_line_where_single_line.rs create mode 100644 tests/source/issue-6539/default.rs delete mode 100644 tests/source/issue-6539/issue_example.rs create mode 100644 tests/target/issue-6539/brace_next_line.rs create mode 100644 tests/target/issue-6539/brace_next_line_where_single_line.rs create mode 100644 tests/target/issue-6539/default.rs delete mode 100644 tests/target/issue-6539/issue_example.rs diff --git a/src/items.rs b/src/items.rs index be01a2af3ab..65b990be18b 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2500,6 +2500,7 @@ fn rewrite_fn_base( ret_str_len, fn_brace_style, multi_line_ret_str, + where_clause, ); debug!( @@ -2899,6 +2900,7 @@ fn compute_budgets_for_params( ret_str_len: usize, fn_brace_style: FnBraceStyle, force_vertical_layout: bool, + where_clause: &ast::WhereClause, ) -> (usize, usize, Indent) { debug!( "compute_budgets_for_params {} {:?}, {}, {:?}", @@ -2913,7 +2915,15 @@ fn compute_budgets_for_params( let overhead = if ret_str_len == 0 { 2 } else { 3 }; let mut used_space = indent.width() + result.len() + ret_str_len + overhead; match fn_brace_style { - FnBraceStyle::None => used_space += 1, // 1 = `;` + _ if context.config.style_edition() >= StyleEdition::Edition2027 + && where_clause.predicates.len() > 0 => + { + // Don't add anything to `used_space` if we have a where clause. + // For all `FnBraceStyle` values if we have a where cluase that can't fit + // on the current line it'll be written to the next line. + // Therefore, we don't need to account for a trailing `;` or `{}` + } + FnBraceStyle::None => used_space += 1, // 1 = `;` FnBraceStyle::SameLine => used_space += 2, // 2 = `{}` FnBraceStyle::NextLine => (), } diff --git a/tests/source/issue-6539/brace_next_line.rs b/tests/source/issue-6539/brace_next_line.rs new file mode 100644 index 00000000000..04dbc84f4e4 --- /dev/null +++ b/tests/source/issue-6539/brace_next_line.rs @@ -0,0 +1,16 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-where_single_line: false + +pub trait Trait +{ + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} +} diff --git a/tests/source/issue-6539/brace_next_line_where_single_line.rs b/tests/source/issue-6539/brace_next_line_where_single_line.rs new file mode 100644 index 00000000000..feb75359939 --- /dev/null +++ b/tests/source/issue-6539/brace_next_line_where_single_line.rs @@ -0,0 +1,16 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-where_single_line: true + +pub trait Trait +{ + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} +} diff --git a/tests/source/issue-6539/default.rs b/tests/source/issue-6539/default.rs new file mode 100644 index 00000000000..568ced6a2fd --- /dev/null +++ b/tests/source/issue-6539/default.rs @@ -0,0 +1,15 @@ +// rustfmt-style_edition: 2027 + +pub trait Trait { + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn a_one_hundred_one_column_fn_decl_no_body(self, a: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} +} diff --git a/tests/source/issue-6539/issue_example.rs b/tests/source/issue-6539/issue_example.rs deleted file mode 100644 index f386901684a..00000000000 --- a/tests/source/issue-6539/issue_example.rs +++ /dev/null @@ -1,7 +0,0 @@ -// rustfmt-style_edition: 2027 - -pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; - - fn a_one_hundred_one_column_fn_decl_no_body(self, a: f64, b: f64, c: f64, d: f64, e: f64) -> f64; -} diff --git a/tests/target/issue-6539/brace_next_line.rs b/tests/target/issue-6539/brace_next_line.rs new file mode 100644 index 00000000000..35cb57fa6ca --- /dev/null +++ b/tests/target/issue-6539/brace_next_line.rs @@ -0,0 +1,30 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-where_single_line: false + +pub trait Trait +{ + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 + where + T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( + &self, + aaa: T, + bbb: f64, + ) -> f64 + where + T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 + { + } + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 + where + T: Debug, + { + } +} diff --git a/tests/target/issue-6539/brace_next_line_where_single_line.rs b/tests/target/issue-6539/brace_next_line_where_single_line.rs new file mode 100644 index 00000000000..bdf7cdd9c02 --- /dev/null +++ b/tests/target/issue-6539/brace_next_line_where_single_line.rs @@ -0,0 +1,28 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: AlwaysNextLine +// rustfmt-where_single_line: true + +pub trait Trait +{ + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 + where T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( + &self, + aaa: T, + bbb: f64, + ) -> f64 + where + T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 + { + } + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 + where T: Debug + { + } +} diff --git a/tests/target/issue-6539/default.rs b/tests/target/issue-6539/default.rs new file mode 100644 index 00000000000..2392a52cf08 --- /dev/null +++ b/tests/target/issue-6539/default.rs @@ -0,0 +1,40 @@ +// rustfmt-style_edition: 2027 + +pub trait Trait { + fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + + fn a_one_hundred_one_column_fn_decl_no_body( + self, + a: f64, + b: f64, + c: f64, + d: f64, + e: f64, + ) -> f64; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 + where + T: Debug; + + fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( + &self, + aaa: T, + bbb: f64, + ) -> f64 + where + T: Debug; + + fn an_over_one_hundred_column_fn_decl_with_body( + &self, + aaaaa: f64, + bbbbb: f64, + ccc: f64, + ) -> f64 { + } + + fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 + where + T: Debug, + { + } +} diff --git a/tests/target/issue-6539/issue_example.rs b/tests/target/issue-6539/issue_example.rs deleted file mode 100644 index e061fe5c8a5..00000000000 --- a/tests/target/issue-6539/issue_example.rs +++ /dev/null @@ -1,14 +0,0 @@ -// rustfmt-style_edition: 2027 - -pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; - - fn a_one_hundred_one_column_fn_decl_no_body( - self, - a: f64, - b: f64, - c: f64, - d: f64, - e: f64, - ) -> f64; -} From 94a1c9de74e7ee5738871da20b0e0683b776444a Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Sun, 22 Jun 2025 17:54:01 -0500 Subject: [PATCH 3/4] fix: PreferSameLine and WhereSingleLine had conflicting brace rules for fn declarations + tests When I added these tests I noticed that in target/prefer_same_line_where_single_line.rs line 98 that the brace was on the same line as the second where predicate `U`, while in the same file at line 114, a very similar function declaration was incorrectly formatting the brace onto the next line. Now if the brace style is PreferSameLine, then the opening brace on function declarations with multi-lined parameters remains on the same line as the last where clause predicate. --- src/items.rs | 9 +- tests/source/issue-6539/brace_next_line.rs | 71 +++++- .../brace_next_line_where_single_line.rs | 71 +++++- tests/source/issue-6539/default.rs | 15 -- tests/source/issue-6539/prefer_same_line.rs | 73 ++++++ .../prefer_same_line_where_single_line.rs | 73 ++++++ tests/source/issue-6539/same_line_where.rs | 73 ++++++ .../issue-6539/same_line_where_single_line.rs | 73 ++++++ tests/target/issue-6539/brace_next_line.rs | 230 ++++++++++++++++- .../brace_next_line_where_single_line.rs | 224 ++++++++++++++++- tests/target/issue-6539/default.rs | 40 --- tests/target/issue-6539/idempotent.rs | 49 ++++ tests/target/issue-6539/prefer_same_line.rs | 229 +++++++++++++++++ .../prefer_same_line_where_single_line.rs | 221 ++++++++++++++++ tests/target/issue-6539/same_line_where.rs | 237 ++++++++++++++++++ .../issue-6539/same_line_where_single_line.rs | 225 +++++++++++++++++ 16 files changed, 1824 insertions(+), 89 deletions(-) delete mode 100644 tests/source/issue-6539/default.rs create mode 100644 tests/source/issue-6539/prefer_same_line.rs create mode 100644 tests/source/issue-6539/prefer_same_line_where_single_line.rs create mode 100644 tests/source/issue-6539/same_line_where.rs create mode 100644 tests/source/issue-6539/same_line_where_single_line.rs delete mode 100644 tests/target/issue-6539/default.rs create mode 100644 tests/target/issue-6539/idempotent.rs create mode 100644 tests/target/issue-6539/prefer_same_line.rs create mode 100644 tests/target/issue-6539/prefer_same_line_where_single_line.rs create mode 100644 tests/target/issue-6539/same_line_where.rs create mode 100644 tests/target/issue-6539/same_line_where_single_line.rs diff --git a/src/items.rs b/src/items.rs index 65b990be18b..30e95fff58a 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2758,8 +2758,13 @@ fn rewrite_fn_base( let ends_with_comment = last_line_contains_single_line_comment(&result); force_new_line_for_brace |= ends_with_comment; - force_new_line_for_brace |= - is_params_multi_lined && context.config.where_single_line() && !where_clause_str.is_empty(); + + // PreferSameLine should keep the brace on the same line as the last where predicate. + force_new_line_for_brace |= !where_clause_str.is_empty() + && context.config.where_single_line() + && is_params_multi_lined + && context.config.brace_style() != BraceStyle::PreferSameLine; + Ok((result, ends_with_comment, force_new_line_for_brace)) } diff --git a/tests/source/issue-6539/brace_next_line.rs b/tests/source/issue-6539/brace_next_line.rs index 04dbc84f4e4..3c177ada6ac 100644 --- a/tests/source/issue-6539/brace_next_line.rs +++ b/tests/source/issue-6539/brace_next_line.rs @@ -2,15 +2,72 @@ // rustfmt-brace_style: AlwaysNextLine // rustfmt-where_single_line: false -pub trait Trait -{ - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; +// Top-level functions - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; +// Short function +fn short_fn(a: f64, b: f64) -> f64; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; - fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} } diff --git a/tests/source/issue-6539/brace_next_line_where_single_line.rs b/tests/source/issue-6539/brace_next_line_where_single_line.rs index feb75359939..c2c6d5460c2 100644 --- a/tests/source/issue-6539/brace_next_line_where_single_line.rs +++ b/tests/source/issue-6539/brace_next_line_where_single_line.rs @@ -2,15 +2,72 @@ // rustfmt-brace_style: AlwaysNextLine // rustfmt-where_single_line: true -pub trait Trait -{ - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; +// Top-level functions - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; +// Short function +fn short_fn(a: f64, b: f64) -> f64; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; - fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} } diff --git a/tests/source/issue-6539/default.rs b/tests/source/issue-6539/default.rs deleted file mode 100644 index 568ced6a2fd..00000000000 --- a/tests/source/issue-6539/default.rs +++ /dev/null @@ -1,15 +0,0 @@ -// rustfmt-style_edition: 2027 - -pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; - - fn a_one_hundred_one_column_fn_decl_no_body(self, a: f64, b: f64, c: f64, d: f64, e: f64) -> f64; - - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 where T: Debug; - - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2(&self, aaa: T, bbb: f64) -> f64 where T: Debug; - - fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 {} - - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 where T: Debug {} -} diff --git a/tests/source/issue-6539/prefer_same_line.rs b/tests/source/issue-6539/prefer_same_line.rs new file mode 100644 index 00000000000..b4700252893 --- /dev/null +++ b/tests/source/issue-6539/prefer_same_line.rs @@ -0,0 +1,73 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: PreferSameLine +// rustfmt-where_single_line: false + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} +} diff --git a/tests/source/issue-6539/prefer_same_line_where_single_line.rs b/tests/source/issue-6539/prefer_same_line_where_single_line.rs new file mode 100644 index 00000000000..e90288b86f8 --- /dev/null +++ b/tests/source/issue-6539/prefer_same_line_where_single_line.rs @@ -0,0 +1,73 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: PreferSameLine +// rustfmt-where_single_line: true + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} +} diff --git a/tests/source/issue-6539/same_line_where.rs b/tests/source/issue-6539/same_line_where.rs new file mode 100644 index 00000000000..9406ba3dc0f --- /dev/null +++ b/tests/source/issue-6539/same_line_where.rs @@ -0,0 +1,73 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: SameLineWhere +// rustfmt-where_single_line: false + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} +} diff --git a/tests/source/issue-6539/same_line_where_single_line.rs b/tests/source/issue-6539/same_line_where_single_line.rs new file mode 100644 index 00000000000..bd4ff0ddf36 --- /dev/null +++ b/tests/source/issue-6539/same_line_where_single_line.rs @@ -0,0 +1,73 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: SameLineWhere +// rustfmt-where_single_line: true + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type(a: f64) -> Result>, Box>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64, eeee: f64) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body(a: f64) -> Result>, Box> {} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 where T: Debug {} + +fn fn_with_wrapping_return_type_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64, ee: f64) -> f64 {} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug {} + +fn fn_with_long_return_and_where_and_body(a: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +fn fn_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64, ffff: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return(&self) -> Result>, Box>; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; + + fn method_with_wrapping_return_type(self, aaa: f64, bbb: T, ccc: f64, ddd: f64, ee: f64) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; + + fn method_with_long_return_and_where(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + fn method_with_everything_long(&self, aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body(&self) -> Result>, Box> {} + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 where T: Debug {} + + fn method_with_wrapping_return_type_and_body(aaaa: f64, bb: T, cc: f64, d: f64, e: f64) -> f64 {} + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug {} + + fn method_with_long_return_and_where_and_body(self) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} + + fn method_with_everything_long_and_body(aaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> Result>, Box> where T: Debug + Display + Clone + Send + Sync + 'static, U: Iterator + ExactSizeIterator {} +} diff --git a/tests/target/issue-6539/brace_next_line.rs b/tests/target/issue-6539/brace_next_line.rs index 35cb57fa6ca..da1a5bf1269 100644 --- a/tests/target/issue-6539/brace_next_line.rs +++ b/tests/target/issue-6539/brace_next_line.rs @@ -2,29 +2,241 @@ // rustfmt-brace_style: AlwaysNextLine // rustfmt-where_single_line: false +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where + T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where + T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +{ +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where + T: Debug, +{ +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 +{ +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where + T: Debug, +{ +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +// Trait methods pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( - &self, - aaa: T, - bbb: f64, - ) -> f64 + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 where T: Debug; - fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( + &self, + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > + { + } + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where + T: Debug, { } - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 + { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug, { } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } } diff --git a/tests/target/issue-6539/brace_next_line_where_single_line.rs b/tests/target/issue-6539/brace_next_line_where_single_line.rs index bdf7cdd9c02..06b074dde73 100644 --- a/tests/target/issue-6539/brace_next_line_where_single_line.rs +++ b/tests/target/issue-6539/brace_next_line_where_single_line.rs @@ -2,27 +2,233 @@ // rustfmt-brace_style: AlwaysNextLine // rustfmt-where_single_line: true +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +{ +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where T: Debug +{ +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 +{ +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where T: Debug +{ +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +// Trait methods pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; + fn short_method(a: f64, b: f64) -> f64; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 where T: Debug; - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 + where T: Debug; + + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( &self, - aaa: T, - bbb: f64, - ) -> f64 + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > where - T: Debug; + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > + { + } - fn an_over_one_hundred_column_fn_decl_with_body(&self, aaaaa: f64, bbbbb: f64, ccc: f64) -> f64 + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where T: Debug { } - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 + { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 where T: Debug { } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } } diff --git a/tests/target/issue-6539/default.rs b/tests/target/issue-6539/default.rs deleted file mode 100644 index 2392a52cf08..00000000000 --- a/tests/target/issue-6539/default.rs +++ /dev/null @@ -1,40 +0,0 @@ -// rustfmt-style_edition: 2027 - -pub trait Trait { - fn a_one_hundred_column_fn_decl_no_body(&self, aaa: f64, b: f64, c: f64, d: f64, e: f64) -> f64; - - fn a_one_hundred_one_column_fn_decl_no_body( - self, - a: f64, - b: f64, - c: f64, - d: f64, - e: f64, - ) -> f64; - - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause(&self, a: T, bb: f64) -> f64 - where - T: Debug; - - fn an_over_one_hundred_column_fn_decl_no_body_and_where_clause2( - &self, - aaa: T, - bbb: f64, - ) -> f64 - where - T: Debug; - - fn an_over_one_hundred_column_fn_decl_with_body( - &self, - aaaaa: f64, - bbbbb: f64, - ccc: f64, - ) -> f64 { - } - - fn an_over_one_hundred_column_fn_decl_with_body_and_where_clause(&self, aaaaa: f64) -> f64 - where - T: Debug, - { - } -} diff --git a/tests/target/issue-6539/idempotent.rs b/tests/target/issue-6539/idempotent.rs new file mode 100644 index 00000000000..47fa7ac84d4 --- /dev/null +++ b/tests/target/issue-6539/idempotent.rs @@ -0,0 +1,49 @@ +// rustfmt-style_edition: 2027 + +// Function with the maximum length before wrapping (100 characters) +fn a_one_hundred_column_fn_decl(aaaaaaaaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> f64; + +fn a_one_hundred_column_fn_decl_with_body(aaaaa: f64, bbb: f64, cc: f64, dd: f64, ee: f64) -> f64 {} + +fn a_ninety_nine_column_fn_decl(aaaaaaaaa: f64, bbbb: f64, cccc: f64, dddd: f64, eeee: f64) -> f64; + +fn a_ninety_nine_column_fn_decl_with_body(aaaaa: f64, bb: f64, cc: f64, dd: f64, ee: f64) -> f64 {} + +fn a_one_hundred_one_column_fn_decl( + aaaaaaaaaaa: f64, + bbb: f64, + ccc: f64, + ddd: f64, + eee: f64, +) -> f64; + +fn a_one_hundred_one_column_fn_decl_with_body(aaaaaa: f64, bb: f64, c: f64, d: f64, e: f64) -> f64 { +} + +pub trait Trait { + fn a_one_hundred_column_fn_decl(&self, aaaaaaa: f64, bb: f64, cc: f64, dd: f64, ee: f64) -> f64; + + fn a_one_hundred_column_fn_decl_with_body(&self, aaaa: f64, bb: f64, cc: f64, dd: f64) -> f64 {} + + fn a_ninety_nine_column_fn_decl(&self, aaaaaa: f64, bb: f64, cc: f64, dd: f64, ee: f64) -> f64; + + fn a_ninety_nine_column_fn_decl_with_body(&self, aaa: f64, bb: f64, cc: f64, dd: f64) -> f64 {} + + fn a_one_hundred_one_column_fn_decl( + &self, + aaaaaaaa: f64, + b: f64, + c: f64, + d: f64, + e: f64, + ) -> f64; + + fn a_one_hundred_one_column_fn_decl_with_body( + &self, + aaaaa: f64, + b: f64, + c: f64, + d: f64, + ) -> f64 { + } +} diff --git a/tests/target/issue-6539/prefer_same_line.rs b/tests/target/issue-6539/prefer_same_line.rs new file mode 100644 index 00000000000..69ac7c5c0d4 --- /dev/null +++ b/tests/target/issue-6539/prefer_same_line.rs @@ -0,0 +1,229 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: PreferSameLine +// rustfmt-where_single_line: false + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where + T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where + T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> { +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where + T: Debug, { +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 { +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where + T: Debug, { +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { +} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 + where + T: Debug; + + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 + where + T: Debug; + + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( + &self, + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > { + } + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where + T: Debug, { + } + + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 + where + T: Debug, { + } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { + } +} diff --git a/tests/target/issue-6539/prefer_same_line_where_single_line.rs b/tests/target/issue-6539/prefer_same_line_where_single_line.rs new file mode 100644 index 00000000000..71d756823c8 --- /dev/null +++ b/tests/target/issue-6539/prefer_same_line_where_single_line.rs @@ -0,0 +1,221 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: PreferSameLine +// rustfmt-where_single_line: true + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> { +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where T: Debug { +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 { +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where T: Debug { +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { +} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 + where T: Debug; + + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 + where T: Debug; + + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( + &self, + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > { + } + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where T: Debug { + } + + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 + where T: Debug { + } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, { + } +} diff --git a/tests/target/issue-6539/same_line_where.rs b/tests/target/issue-6539/same_line_where.rs new file mode 100644 index 00000000000..140c41af5d6 --- /dev/null +++ b/tests/target/issue-6539/same_line_where.rs @@ -0,0 +1,237 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: SameLineWhere +// rustfmt-where_single_line: false + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where + T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where + T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> { +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where + T: Debug, +{ +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 { +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where + T: Debug, +{ +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 + where + T: Debug; + + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 + where + T: Debug; + + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( + &self, + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > { + } + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where + T: Debug, + { + } + + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 + where + T: Debug, + { + } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } +} diff --git a/tests/target/issue-6539/same_line_where_single_line.rs b/tests/target/issue-6539/same_line_where_single_line.rs new file mode 100644 index 00000000000..a48af70af48 --- /dev/null +++ b/tests/target/issue-6539/same_line_where_single_line.rs @@ -0,0 +1,225 @@ +// rustfmt-style_edition: 2027 +// rustfmt-brace_style: SameLineWhere +// rustfmt-where_single_line: true + +// Top-level functions + +// Short function +fn short_fn(a: f64, b: f64) -> f64; + +// Function with wrapping return type and no where clause +fn fn_with_long_return_type( + a: f64, +) -> Result< + HashMap>, + Box, +>; + +// Function with non-wrapping return type and where clause +fn fn_with_short_where(a: f64, b: T) -> f64 +where T: Debug; + +// Function that wraps at a simple return type +fn fn_with_wrapping_return_type( + aaaaaa: f64, + bbbbbb: T, + cccccc: f64, + dddddd: f64, + eeee: f64, +) -> f64; + +// Function that wraps at the where clause +fn fn_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, cccccc: f64, dddddd: f64) -> f64 +where T: Debug; + +// Function with both wrapping return type and wrapping where clause +fn fn_with_long_return_and_where( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Function with wrapping arguments, return type, and where clause +fn fn_with_everything_long( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + +// Same variations with bodies +fn short_fn_with_body(a: f64, b: f64) -> f64 {} + +fn fn_with_long_return_type_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> { +} + +fn fn_with_short_where_and_body(a: f64, b: T) -> f64 +where T: Debug { +} + +fn fn_with_wrapping_return_type_and_body( + aaaaaa: f64, + bbbbbb: T, + ccc: f64, + ddd: f64, + ee: f64, +) -> f64 { +} + +fn fn_with_wrapping_where_clause_and_body(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 +where T: Debug { +} + +fn fn_with_long_return_and_where_and_body( + a: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +fn fn_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ffff: f64, +) -> Result< + HashMap>, + Box, +> +where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, +{ +} + +// Trait methods +pub trait Trait { + fn short_method(a: f64, b: f64) -> f64; + + fn method_with_long_return( + &self, + ) -> Result< + HashMap>, + Box, + >; + + fn method_with_short_where(&self, a: f64, b: T) -> f64 + where T: Debug; + + fn method_with_wrapping_return_type( + self, + aaa: f64, + bbb: T, + ccc: f64, + ddd: f64, + ee: f64, + ) -> f64; + + fn method_with_wrapping_where_clause(aaaaaa: f64, bbbbbb: T, ccc: f64, ddd: f64) -> f64 + where T: Debug; + + fn method_with_long_return_and_where( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + fn method_with_everything_long( + &self, + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator; + + // Same variations with bodies + fn short_method_with_body(a: f64, b: f64) -> f64 {} + + fn method_with_long_return_and_body( + &self, + ) -> Result< + HashMap>, + Box, + > { + } + + fn method_with_short_where_and_body(&self, a: f64, b: T) -> f64 + where T: Debug { + } + + fn method_with_wrapping_return_type_and_body( + aaaa: f64, + bb: T, + cc: f64, + d: f64, + e: f64, + ) -> f64 { + } + + fn method_with_wrapping_where_clause_and_body(aaa: f64, bb: T, cc: f64, d: f64) -> f64 + where T: Debug { + } + + fn method_with_long_return_and_where_and_body( + self, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } + + fn method_with_everything_long_and_body( + aaaa: f64, + bbbb: f64, + cccc: f64, + dddd: f64, + eeee: f64, + ) -> Result< + HashMap>, + Box, + > + where + T: Debug + Display + Clone + Send + Sync + 'static, + U: Iterator + ExactSizeIterator, + { + } +} From b43eefc04738fa432fb51f23635d6ca80beefe77 Mon Sep 17 00:00:00 2001 From: Luke Wilson Date: Mon, 23 Jun 2025 09:31:55 -0500 Subject: [PATCH 4/4] revert previous fix --- src/items.rs | 8 ++------ .../issue-6539/prefer_same_line_where_single_line.rs | 6 ++++-- 2 files changed, 6 insertions(+), 8 deletions(-) diff --git a/src/items.rs b/src/items.rs index 30e95fff58a..d449e4ad984 100644 --- a/src/items.rs +++ b/src/items.rs @@ -2758,12 +2758,8 @@ fn rewrite_fn_base( let ends_with_comment = last_line_contains_single_line_comment(&result); force_new_line_for_brace |= ends_with_comment; - - // PreferSameLine should keep the brace on the same line as the last where predicate. - force_new_line_for_brace |= !where_clause_str.is_empty() - && context.config.where_single_line() - && is_params_multi_lined - && context.config.brace_style() != BraceStyle::PreferSameLine; + force_new_line_for_brace |= + is_params_multi_lined && context.config.where_single_line() && !where_clause_str.is_empty(); Ok((result, ends_with_comment, force_new_line_for_brace)) } diff --git a/tests/target/issue-6539/prefer_same_line_where_single_line.rs b/tests/target/issue-6539/prefer_same_line_where_single_line.rs index 71d756823c8..f45413b3f55 100644 --- a/tests/target/issue-6539/prefer_same_line_where_single_line.rs +++ b/tests/target/issue-6539/prefer_same_line_where_single_line.rs @@ -111,7 +111,8 @@ fn fn_with_everything_long_and_body( > where T: Debug + Display + Clone + Send + Sync + 'static, - U: Iterator + ExactSizeIterator, { + U: Iterator + ExactSizeIterator, +{ } // Trait methods @@ -216,6 +217,7 @@ pub trait Trait { > where T: Debug + Display + Clone + Send + Sync + 'static, - U: Iterator + ExactSizeIterator, { + U: Iterator + ExactSizeIterator, + { } }