Skip to content

Commit 8b0b213

Browse files
ytmimicalebcartwright
authored andcommitted
Prevent adding trailing whitespace when rewriting ast::Param
Fixes 5125 Previously, a newline was always added, even if the parameter name was not preceded by any param attrs. Now a newline is only added if there were param attrs.
1 parent b4a4bf0 commit 8b0b213

5 files changed

+50
-1
lines changed

src/items.rs

+7-1
Original file line numberDiff line numberDiff line change
@@ -2018,9 +2018,15 @@ impl Rewrite for ast::Param {
20182018
{
20192019
result.push_str(&ty_str);
20202020
} else {
2021+
let prev_str = if param_attrs_result.is_empty() {
2022+
param_attrs_result
2023+
} else {
2024+
param_attrs_result + &shape.to_string_with_newline(context.config)
2025+
};
2026+
20212027
result = combine_strs_with_missing_comments(
20222028
context,
2023-
&(param_attrs_result + &shape.to_string_with_newline(context.config)),
2029+
&prev_str,
20242030
param_name,
20252031
span,
20262032
shape,
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo(
2+
#[unused] a: <u16 as intercom::type_system::ExternType<
3+
intercom::type_system::AutomationTypeSystem,
4+
>>::ForeignType,
5+
) {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
fn middle(
2+
a: usize,
3+
b: <u16 as intercom::type_system::ExternType<
4+
intercom::type_system::AutomationTypeSystem,
5+
>>::ForeignType,
6+
c: bool,
7+
) {
8+
}
9+
10+
fn last(
11+
a: usize,
12+
b: <u16 as intercom::type_system::ExternType<
13+
intercom::type_system::AutomationTypeSystem,
14+
>>::ForeignType,
15+
) {
16+
}
17+
18+
fn first(
19+
a: <u16 as intercom::type_system::ExternType<
20+
intercom::type_system::AutomationTypeSystem,
21+
>>::ForeignType,
22+
b: usize,
23+
) {
24+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
fn foo(
2+
a: <u16 as intercom::type_system::ExternType<
3+
intercom::type_system::AutomationTypeSystem,
4+
>>::ForeignType,
5+
) {
6+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
fn foo(
2+
// Pre Comment
3+
a: <u16 as intercom::type_system::ExternType<
4+
intercom::type_system::AutomationTypeSystem,
5+
>>::ForeignType, // Inline comment
6+
) {
7+
}

0 commit comments

Comments
 (0)