Skip to content

Backport PR #4658 and Fix issue #4551 - multilines comment indentation #5480

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

davidBar-On
Copy link
Contributor

Fixes #4551

Backport #4658 and suggested fix for #4551. The backport and the suggested fix are submitted in one PR, since fixing #4551 requires both, and if only one will be merged, then the issue will not be fixed.

The backport of #4658 handles the case when in the per-formatted code a tab precedes the * at the beginning of a second and following lines of a comment. Copying the tab into the target code sometimes cased wrong indentation, so the tab is replaced with space.

The additional fix for #4551 is for version Two to properly handle the indentation of the second and following lines of a multiline comment, when the first comment line is in the same line of the previous statement. In version Two, these lines were indented according to the statement indentation and the fix indents them to the first line.

@ytmimi
Copy link
Contributor

ytmimi commented Aug 8, 2022

As mentioned in the Comments page of the rust reference we can have nested block comments. For example:

fn main() {
let x = 0; /* start of outer comment
/* start of nested comment
 * end of nested comment
 */
* end of outer comment
*/
}

Out of curiosity I was wondering if this would also be aligned by this PR?

@davidBar-On
Copy link
Contributor Author

No. the PR doesn't handle nested comments. The current code only check for * at the beginning of a (trimmed) line inside a comment, and adds one space before the *. Therefore this code is formatted as (note the the opening of the nested comment is not indented by a space since it does not start with *):

fn main() {
    let x = 0; /* start of outer comment
               /* start of nested comment
                * end of nested comment
                */
                * end of outer comment
                */
}

I assume that the desired formatting to indent the internal comment by two spaces instead of one, i.e.:

fn main() {
    let x = 0; /* start of outer comment
                /* start of nested comment
                 * end of nested comment
                 */
                * end of outer comment
                */
}

If this is correct, I can try to enhance the code to take the /* and */ into account.

@ytmimi
Copy link
Contributor

ytmimi commented Aug 8, 2022

I assume that the desired formatting to indent the internal comment by two spaces instead of one

That sounds good, but It's tough to say because the Comment section of the style guide doesn't give any prescription for how to handle nested block comments.

I was just curiosity that made me ask if this PR also handled nested comments. I'd say nested comments are out of scope for the backport so we should ignore nested comments for now, and revisit them if anyone runs into an issue with nested comments in the future.

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.

Second comment line is not indented correctly
2 participants