-
Notifications
You must be signed in to change notification settings - Fork 927
Second comment line is not indented correctly #4551
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
Comments
I'm having difficulty reproducing this on master. Do you have any non-default config options set? |
Sorry, my mistake. Somehow I wrongly formatted the input example in GitHub. No special option is set. A right input with tab size 4 is: fn main() {
/* Comment1 line 1
* Comment1 line 2 */
let y1 = 6;/* Comment2 line 1
* Comment2 line 2 */
} In this example, both input comments start with one |
Just to clarify, are you saying that in order to reproduce that the comment itself needs to contain a hard tab? |
Yes, for the problem to happen a non-first line of a comment in the input should have a hard tab just before the |
I haven't checked if this is still an issue with the fn main() {
let x = 111; /* First Comment line 1
* First Comment line 2 */
let x = 222; /* Second Comment line 1
* Second Comment line 2 */
} |
Back-porting of PR #4658 (which I will submit soon) resolves the original issue of the second comment line indentation when it is preceded by a tab.
This is a The question is which of the following formatting should be the output of version 2 - Current version One formatting: fn main() {
let x = 111; /* First Comment line 1
* First Comment line 2
* First Comment line 3
*/
// Following first comment
} Or current version Two formatting: fn main() {
let x = 111; /* First Comment line 1
* First Comment line 2
* First Comment line 3
*/
// Following first comment
} |
The version One formatting seems right to me. I think we should align block comments. Do multi-line, adjacent line comments also get aligned in version One? |
If I understood correctly what is meant by "multi-line, adjacent line comments", following is version One output (no tabs): fn main() {
let x = 222; /* Second Comment line 1
* Second Comment line 2
* Second Comment line 3
*/
/* Following second comment line 1
* Following second comment line 2
* Following second comment line 3
*/
} |
Sorry, yeah, that's a super confusing sentence now that I'm reading it back to myself. What I meant was do we indent line comments ( fn main() {
let x = 222; /* Second Comment line 1
* Second Comment line 2
* Second Comment line 3
*/
let y = 333; // Following second comment line 1
// Following second comment line 2
// Following second comment line 3
} |
Yes, this is the output of version one. In version Two the output is: fn main() {
let x = 222; /* Second Comment line 1
* Second Comment line 2
* Second Comment line 3
*/
let y = 333; // Following second comment line 1
// Following second comment line 2
// Following second comment line 3
} My understanding is that the formatting of the consecutive one line indentation is the correct indentation (by design) for version Two, and the question is whether the multi-line indentation is correct also, or should it be as for version One. (By the way, I assume the version Two indentation of the one line comments is the desired indentation, since in many cases the second (and on) comments will be to the next statemen.) |
…t line indentation
Submitted PR #5480 with a suggested fix for this issue. In version Two it indents the multiline comments according to the first line. |
Input
Output
Expected output
The issue is the extra indentation of line 2 of the Second comment. The reason is that the
*
in that line is preceded by atab
and not by aspace
, and that light_rewrite_comment() is copying this preceding character from the original code.If this is regarded as a bug that I can submit a PR with a fix from PR #4518 (simple fix - forcing the character preceding the
*
to be aspace
).Meta
rustfmt 2.0.0-rc.2-nightly (30bda450 2020-11-18)
The text was updated successfully, but these errors were encountered: