Skip to content

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

Closed
@pnkfelix

Description

@pnkfelix
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);
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-prettyArea: Pretty printing (including `-Z unpretty`)

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions