Skip to content

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

Merged
merged 4 commits into from
Nov 8, 2019
Merged

Conversation

rchaser53
Copy link
Contributor

fix: #3904

Copy link
Contributor

@topecongiro topecongiro left a 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();
Copy link
Contributor

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

Copy link
Contributor Author

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.

Copy link
Contributor

Choose a reason for hiding this comment

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

👍

@rchaser53 rchaser53 requested a review from topecongiro November 6, 2019 14:53
@topecongiro topecongiro merged commit 532973c into rust-lang:master Nov 8, 2019
Copy link
Contributor

@topecongiro topecongiro left a 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!

@rchaser53 rchaser53 deleted the issue-3904 branch November 8, 2019 01:25
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

error[internal]: left behind trailing whitespace
3 participants