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.
This commit is contained in:
Yacin Tmimi 2021-12-09 23:17:43 -05:00 committed by Caleb Cartwright
parent b4a4bf0bf8
commit 8b0b213cdd
5 changed files with 50 additions and 1 deletions

View File

@ -2018,9 +2018,15 @@ impl Rewrite for ast::Param {
{
result.push_str(&ty_str);
} else {
let prev_str = if param_attrs_result.is_empty() {
param_attrs_result
} else {
param_attrs_result + &shape.to_string_with_newline(context.config)
};
result = combine_strs_with_missing_comments(
context,
&(param_attrs_result + &shape.to_string_with_newline(context.config)),
&prev_str,
param_name,
span,
shape,

View File

@ -0,0 +1,6 @@
fn foo(
#[unused] a: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType,
) {
}

View File

@ -0,0 +1,24 @@
fn middle(
a: usize,
b: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType,
c: bool,
) {
}
fn last(
a: usize,
b: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType,
) {
}
fn first(
a: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType,
b: usize,
) {
}

View File

@ -0,0 +1,6 @@
fn foo(
a: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType,
) {
}

View File

@ -0,0 +1,7 @@
fn foo(
// Pre Comment
a: <u16 as intercom::type_system::ExternType<
intercom::type_system::AutomationTypeSystem,
>>::ForeignType, // Inline comment
) {
}