Skip to content

Commit 461e7b1

Browse files
committed
fix: properly wrap long impl trait function parameters
Before we weren't taking the length of `impl ` into account so the trait thought it had more room than it actually did to format itself on a single line.
1 parent 53e39cc commit 461e7b1

File tree

4 files changed

+40
-0
lines changed

4 files changed

+40
-0
lines changed

src/types.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1016,9 +1016,14 @@ impl Rewrite for ast::Ty {
10161016
}
10171017
let rw = if context.config.style_edition() <= StyleEdition::Edition2021 {
10181018
it.rewrite_result(context, shape)
1019+
} else if context.config.style_edition() == StyleEdition::Edition2024 {
1020+
join_bounds(context, shape, it, false)
10191021
} else {
1022+
let offset = "impl ".len();
1023+
let shape = shape.offset_left(offset, self.span())?;
10201024
join_bounds(context, shape, it, false)
10211025
};
1026+
10221027
rw.map(|it_str| {
10231028
let space = if it_str.is_empty() { "" } else { " " };
10241029
format!("impl{}{}", space, it_str)
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rustfmt-style_edition: 2027
2+
3+
fn my_function_no_wrap_at_exactly_100_characters_wide(
4+
my_long_impl_trait_parameter: impl Into<LongTypeNameThatMakesThisWholeLineExactly100Chars_____>,
5+
) {
6+
}
7+
8+
fn my_function_wraps_at_at_exactly_101_characters_wide(
9+
my_long_impl_trait_parameter: impl Into<LongTypeNameThatMakesThisWholeLineExactly101Chars______>,
10+
) {
11+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
// rustfmt-style_edition: 2024
2+
3+
fn my_function_no_wrap_at_exactly_100_characters_wide(
4+
my_long_impl_trait_parameter: impl Into<LongTypeNameThatMakesThisWholeLineExactly100Chars_____>,
5+
) {
6+
}
7+
8+
fn my_function_wraps_at_at_exactly_101_characters_wide(
9+
my_long_impl_trait_parameter: impl Into<LongTypeNameThatMakesThisWholeLineExactly101Chars______>,
10+
) {
11+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
// rustfmt-style_edition: 2027
2+
3+
fn my_function_no_wrap_at_exactly_100_characters_wide(
4+
my_long_impl_trait_parameter: impl Into<LongTypeNameThatMakesThisWholeLineExactly100Chars_____>,
5+
) {
6+
}
7+
8+
fn my_function_wraps_at_at_exactly_101_characters_wide(
9+
my_long_impl_trait_parameter: impl Into<
10+
LongTypeNameThatMakesThisWholeLineExactly101Chars______,
11+
>,
12+
) {
13+
}

0 commit comments

Comments
 (0)