-
Notifications
You must be signed in to change notification settings - Fork 889
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
remove trailing whitespace from multi-line tuple struct field prefix #5708
base: master
Are you sure you want to change the base?
Conversation
Here are the relevant differences between the struct MyTuple(
#[cfg(unix)] // some comment
- pub u64,
- #[cfg(not(unix))] /*block comment */ pub(crate) u32,
+ pub u64,
+ #[cfg(not(unix))] /*block comment */ pub(crate) u32,
);
struct MyTuple(
/// Doc Comments
/* TODO note to add more to Doc Comments */
- pub u32,
+ pub u32,
/// Doc Comments
// TODO note
- pub(crate) u64,
+ pub(crate) u64,
); |
Just ran the Diff Check Job, and everything looks good ✅ |
src/items.rs
Outdated
while context.config.version() == Version::Two && prefix.ends_with(char::is_whitespace) { | ||
// Remove any additional whitespace at the end of the prefix. | ||
// For example if there is a space after a visibility modifier. | ||
prefix.pop(); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think this is more straightforward:
while context.config.version() == Version::Two && prefix.ends_with(char::is_whitespace) { | |
// Remove any additional whitespace at the end of the prefix. | |
// For example if there is a space after a visibility modifier. | |
prefix.pop(); | |
} | |
if context.config.version() == Version::Two { | |
// Remove trailing whitespace after the prefix, such as a visibility modifier. | |
prefix.truncate(prefix.trim_end().len()); | |
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for helping to simplify the implementation
I'd be content merging this as-is because it cleanly fixes an obvious and annoying issue (and I'll add I hate we have to gate this, but agree that we unfortunately must). However, it's typically a smell for me when we have to remove whitespace that we previously added farther back in the call stack. Do you think it would be feasible to apply a different fix that only adds the whitespace conditionally when necessary? And if so, is that something you think we could turn around quickly or would it be better to move forward with this fix and add a tracking issue and/or fixme comment to try that alternative approach? |
I'll have to revisit this. I can take a look to see what's going on in |
@calebcartwright check out the latest commit. It removes the trailing whitespace when using |
// format_visibility doesn't have a trailing space in Version::Two | ||
result.push_str(&visibility); | ||
} else { | ||
result.push_str(visibility.trim()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It turns out that there were other places in the codebase that already dealt with trimming the trailing space coming back from format_visibility
.
Fixes 5703, Fixes 5525 visibility modifiers always contain a trailing space after them. If the formatted tuple field needs to be written over multiple lines then the extra space will cause issues. In the best case the space will offset the type name by an extra space and in the worst case it will lead to a "left behind trailing whitespace" error.
Fixes #5703, Fixes #5525, Fixes #5997
visibility modifiers always contain a trailing space after them. If the formatted tuple field needs to be written over multiple lines then the extra space will cause issues.
In the best case the space will offset the type name by an extra space and in the worst case it will lead to a
"left behind trailing whitespace"
error.These changes were version gated because they cause breaking formatting changes with existing tests.
r? @calebcartwright