Skip to content

Commit e554eba

Browse files
fix: wrap function without a body exceeding 100 characters (#6539)
Co-authored-by: Yacin Tmimi <[email protected]>
1 parent 334670e commit e554eba

File tree

3 files changed

+34
-3
lines changed

3 files changed

+34
-3
lines changed

src/items.rs

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2602,10 +2602,20 @@ fn rewrite_fn_base(
26022602
// the closing parenthesis of the param and the arrow '->' is considered.
26032603
let mut sig_length = result.len() + indent.width() + ret_str_len + 1;
26042604

2605-
// If there is no where-clause, take into account the space after the return type
2606-
// and the brace.
2605+
// If there is no where-clause.
26072606
if where_clause.predicates.is_empty() {
2608-
sig_length += 2;
2607+
if context.config.style_edition() >= StyleEdition::Edition2027 {
2608+
let line_ending_overhead = match fn_brace_style {
2609+
FnBraceStyle::NextLine => 0, // No brace to account for
2610+
FnBraceStyle::SameLine => 2, // Trailing space and brace, e.g. ` {`
2611+
FnBraceStyle::None => 1, // Trailing `;`
2612+
};
2613+
sig_length += line_ending_overhead;
2614+
} else {
2615+
// Take into account the space after the return type and the brace.
2616+
// 2 = ' {'
2617+
sig_length += 2;
2618+
}
26092619
}
26102620

26112621
sig_length > context.config.max_width()
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
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+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
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+
}

0 commit comments

Comments
 (0)