Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/Extra whitespace in nested pub extern #5529

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/expr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1984,6 +1984,9 @@ pub(crate) fn rewrite_assign_rhs_with<S: Into<String>, R: Rewrite>(
) -> Option<String> {
let lhs = lhs.into();
let rhs = rewrite_assign_rhs_expr(context, &lhs, ex, shape, rhs_kind, rhs_tactics)?;
if context.config.version() == Version::Two && lhs.ends_with(" ") && rhs.starts_with(" ") {
return Some(lhs + &rhs.trim_start());
}
Comment on lines +1987 to +1989
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Although this technically fixes the issue, it doesn't resolve the underlying problem. I believe the trailing space is properly added to the end of "pub extern ", but we shouldn't be adding a space before "C". I think the actual issue is occurring in choose_rhs. @calebcartwright Do you think this is the right approach?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okok. This approach also handles other similar cases. However, it there's a better approach I'm up to take it. I'll wait for confirmation before making any changes to choose_rhs 👍.

Some(lhs + &rhs)
}

Expand Down
9 changes: 9 additions & 0 deletions tests/target/issue-5525.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
// rustfmt-version: Two

pub struct SomeCallback(
pub extern "C" fn(
long_argument_name_to_avoid_wrap: u32,
second_long_argument_name: u32,
third_long_argument_name: u32,
),
);