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:
parent
b4a4bf0bf8
commit
8b0b213cdd
@ -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,
|
||||
|
@ -0,0 +1,6 @@
|
||||
fn foo(
|
||||
#[unused] a: <u16 as intercom::type_system::ExternType<
|
||||
intercom::type_system::AutomationTypeSystem,
|
||||
>>::ForeignType,
|
||||
) {
|
||||
}
|
@ -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,
|
||||
) {
|
||||
}
|
6
tests/target/issue-5125/minimum_example.rs
Normal file
6
tests/target/issue-5125/minimum_example.rs
Normal file
@ -0,0 +1,6 @@
|
||||
fn foo(
|
||||
a: <u16 as intercom::type_system::ExternType<
|
||||
intercom::type_system::AutomationTypeSystem,
|
||||
>>::ForeignType,
|
||||
) {
|
||||
}
|
@ -0,0 +1,7 @@
|
||||
fn foo(
|
||||
// Pre Comment
|
||||
a: <u16 as intercom::type_system::ExternType<
|
||||
intercom::type_system::AutomationTypeSystem,
|
||||
>>::ForeignType, // Inline comment
|
||||
) {
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user