Skip to content
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

Pretty-printer inserts an extra newline after multiline trailing comments #37201

Closed
petrochenkov opened this issue Oct 16, 2016 · 2 comments · Fixed by #87098
Closed

Pretty-printer inserts an extra newline after multiline trailing comments #37201

petrochenkov opened this issue Oct 16, 2016 · 2 comments · Fixed by #87098
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.

Comments

@petrochenkov
Copy link
Contributor

Example:

fn main() {
    let a = 10; // Comment 1
                // Comment 2
}

=>

fn main() {
    let a =
        10; // Comment 1
            // Comment 2

}

Affected tests:
[pretty] pretty\issue-20427.rs
[pretty] pretty\issue-22992.rs
[pretty] pretty\issue-23338-ensure-param-drop-order.rs
[pretty] pretty\issue-27401-dropflag-reinit.rs

The issue disappears if comments are not packed into ibox (see try!(self.ibox(0)) and self.end() in pprust.rs/fn print_comment/comments::Trailing), but formatting become worse and other tests fail.
I spent whole day investigating how these boxes work and reading Derek C. Oppen's "Pretty Printing" but still have no idea why this extra newline appears.

eddyb added a commit to eddyb/rust that referenced this issue Oct 19, 2016
Fix some pretty printing tests

Many pretty-printing tests are un-ignored.
Some issues in classification of comments (trailing/isolated) and blank line counting are fixed.
Some comments are printed more carefully.
Some minor refactoring in pprust.rs
`no-pretty-expanded` annotations are removed because this is the default now.
`pretty-expanded` annotations are removed from compile-fail tests, they are not tested with pretty-printer.

Closes rust-lang#23623 in favor of more specific rust-lang#37201 and rust-lang#37199
r? @nrc
eddyb added a commit to eddyb/rust that referenced this issue Oct 19, 2016
Fix some pretty printing tests

Many pretty-printing tests are un-ignored.
Some issues in classification of comments (trailing/isolated) and blank line counting are fixed.
Some comments are printed more carefully.
Some minor refactoring in pprust.rs
`no-pretty-expanded` annotations are removed because this is the default now.
`pretty-expanded` annotations are removed from compile-fail tests, they are not tested with pretty-printer.

Closes rust-lang#23623 in favor of more specific rust-lang#37201 and rust-lang#37199
r? @nrc
@sanxiyn sanxiyn added the A-pretty Area: Pretty printing (including `-Z unpretty`) label Oct 29, 2016
@Mark-Simulacrum Mark-Simulacrum added the C-bug Category: This is a bug. label Jul 26, 2017
@jyn514
Copy link
Member

jyn514 commented Jul 7, 2021

Triage: the output looks a little odd because it doesn't keep the alignment, but the bug reported here is now fixed:

$  rustc --pretty=normal pretty.rs  -Zunstable-options
fn main() {
    let a = 10; // Comment 1
    // Comment 2
}

@jyn514 jyn514 closed this as completed Jul 7, 2021
@petrochenkov
Copy link
Contributor Author

If this is fixed, then the tests need to be un-ignored, reopening until that is done.

@petrochenkov petrochenkov reopened this Jul 7, 2021
@petrochenkov petrochenkov added E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added. and removed C-bug Category: This is a bug. labels Jul 7, 2021
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 13, 2021
…trochenkov

Unignore some pretty printing tests

Closes rust-lang#37201
r? `@petrochenkov`
GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this issue Jul 13, 2021
…trochenkov

Unignore some pretty printing tests

Closes rust-lang#37201
r? ``@petrochenkov``
JohnTitor added a commit to JohnTitor/rust that referenced this issue Jul 13, 2021
…trochenkov

Unignore some pretty printing tests

Closes rust-lang#37201
r? ```@petrochenkov```
@bors bors closed this as completed in d5e0426 Jul 14, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`) E-easy Call for participation: Easy difficulty. Experience needed to fix: Not much. Good first issue. E-needs-test Call for participation: An issue has been fixed and does not reproduce, but no test has been added.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants