Skip to content

Pretty-printer moves comments in do- and for-loop above (and outside) loop #7485

New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

Closed
pnkfelix opened this issue Jun 29, 2013 · 4 comments
Closed
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`)

Comments

@pnkfelix
Copy link
Member

fn foo() {
    for x {
        docomments(appear, above(or, below));
        well(lets, find, out);
        heres(an, irrelevant, call, to, the, function);
        how(about, now);
        to(drive, home, point);

        code(establishing, precondition, of, how, II);
        // this comment is pointing out some precondition specifically
        // about `how(..)` at this point in control-flow; yikes
        how(about, now);
        // this comment is about `how`'s post-condition; (another yikes)
        code(requiring, postcondition, of, how, II);
    }
}

check out this magic trick that rustc --pretty pulls:

% x86_64-apple-darwin/stage2/bin/rustc  --version
x86_64-apple-darwin/stage2/bin/rustc 0.7-pre (935882b 2013-06-29 05:43:33 +0200)
host: x86_64-apple-darwin
% x86_64-apple-darwin/stage2/bin/rustc  --pretty normal /tmp/foo.rs
fn foo() {

    // this comment is pointing out some precondition specifically
    // about `how(..)` at this point in control-flow; yikes
    // this comment is about `how`'s post-condition; (another yikes)
    for x || {
        docomments(appear, above(or, below));
        well(lets, find, out);
        heres(an, irrelevant, call, to, the, function);
        how(about, now);
        to(drive, home, point);
        code(establishing, precondition, of, how, II);
        how(about, now);
        code(requiring, postcondition, of, how, II);
    }
}
@catamorphism
Copy link
Contributor

Metabug: #3195

@huonw
Copy link
Member

huonw commented Jan 12, 2014

This appears to be fixed. I'll submit a patch with a test.

@huonw
Copy link
Member

huonw commented Jan 12, 2014

Oh, there's already pretty/for-comment.rs. Closing.

@huonw huonw closed this as completed Jan 12, 2014
@pnkfelix
Copy link
Member Author

Indeed, the best I can determine is that it was fixed by 30fca57, though I am not sufficiently familiar with the interaction of spans and the pretty printer to say that with 100% confidence. I don't see an issue number for the change to spans.

The for-comment.rs test was added in reaction to that change, in 376d5d6 which in turn was part of a rollup PR: #7598

flip1995 pushed a commit to flip1995/rust that referenced this issue Jul 29, 2021
Add to test third party crates list

changelog: none
# for free to join this conversation on GitHub. Already have an account? # to comment
Labels
A-pretty Area: Pretty printing (including `-Z unpretty`)
Projects
None yet
Development

No branches or pull requests

3 participants