-
Notifications
You must be signed in to change notification settings - Fork 931
Indentation of secont and following lines in multiline comment #4658
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
Indentation of secont and following lines in multiline comment #4658
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.
Thanks for this! Couple minor things but this looks to be in good order and ready for merging after those are addressed 👍
src/formatting/comment.rs
Outdated
( | ||
blank, | ||
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment), | ||
) | ||
}) | ||
.map(|(b, l)| format!("{}{}", b, l)) |
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.
Good catch! I don't see a need for another map
call though, let's just return the allocated string in the closure in the previous block like was done before
( | |
blank, | |
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment), | |
) | |
}) | |
.map(|(b, l)| format!("{}{}", b, l)) | |
format!( | |
"{}{}", | |
blank, | |
trim_end_unless_two_whitespaces(left_trimmed, is_doc_comment), | |
) | |
}) |
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.
Done
@@ -0,0 +1,46 @@ | |||
// Ensure multiline comments are indented properly, | |||
// incluyding when second line is prefixed by tab or at the beginning of the line |
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.
typo fix 😄 also, can you add a copy of this test case but with the hard_tabs set to true? I wouldn't expect any issues, but good to have for regression regardless
// incluyding when second line is prefixed by tab or at the beginning of the line | |
// including when second line is prefixed by tab or at the beginning of the line |
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.
Fixed and added ...-hard-tabs.rs
test file.
Also, make sure you rebase on |
58149d7
to
0fae9bc
Compare
Done, but I probably didn't do it right, as all/some of the latest master changes are also shown as changes here. What I did is to merge the UPDATE: hopefully fixed the issue by resting the last commit, merging again with master and redoing the changes. Hopefully it is o.k. now. |
0fae9bc
to
0145848
Compare
Thanks! The diff looks okay now. For future reference, I would encourage adding this repo as another upstream in your local copy of your fork https://docs.github.com/en/github/using-git/adding-a-remote git remote add upstream https://github.com/rust-lang/rustfmt.git That way you can continue working with your fork via the same remote (typically git fetch upstream and then you can rebase whatever local branch you are working on against the target upstream branch: git checkout master
git rebase upstream/master
# or
git checkout comment_multiline_indentation
git rebase upstream/master |
I am willing to back-port this PR, but it is not labeled as "1x-backport:pending ". Is it ok to back-port it, or only if/when it will be labeled as "1x-backport:pending "? A more general question - there are some other PRs I submitted for R2 that are labeled as "1x-backport:pending", but not as "help-wanted". Is it o.k. that I will back-port these PRs? |
…t line indentation
Fix an issue in
light_rewrite_comment()
when formatting 2nd (and following) lines that start with*
in a multiline comment. Currently, the function prefix it with the byte preceding the*
, so it will be aligned with the comment opening/*
, assuming this character is a space.The main problem is that if the byte preceding the
*
in the original code is a hard-tab, indentation is to the next tab place and not just by one space. Another issue is when the*
is the first char in the line. In this case, nothing is added before the*
to align it with the/*
.This fix makes sure that the
*
is prefixed by a space character.