-
Notifications
You must be signed in to change notification settings - Fork 926
add trim to avoid internal error #3905
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
Conversation
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.
Thank you for the PR!
src/visitor.rs
Outdated
@@ -248,6 +248,7 @@ impl<'b, 'a: 'b> FmtVisitor<'a> { | |||
|
|||
for (kind, offset, sub_slice) in CommentCodeSlices::new(self.snippet(span)) { | |||
let sub_slice = transform_missing_snippet(config, sub_slice); | |||
let sub_slice = sub_slice.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.
I cannot come up with an example, though I am afraid that this could potentially break the code by trimming newlines from the subslice
. E.g., we call sub_slice.find("\n")
below to figure out whether the code should sit on the same line or the next line.
The safer approach would be to not call rewrite_comment
when the other_lines.trim()
is an empty string.
https://github.com/rust-lang/rustfmt/pull/3905/files#diff-85974d8eb6610bd6ea773d375ad8c6d2R283-R290
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.
Thank you for the review. I fixed it. I also added the trim for version one logic.
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.
👍
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.
Thank you for the update!
fix: #3904