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

Best effort on long lines #3697

Open
dtolnay opened this issue Jul 18, 2019 · 2 comments
Open

Best effort on long lines #3697

dtolnay opened this issue Jul 18, 2019 · 2 comments

Comments

@dtolnay
Copy link
Member

dtolnay commented Jul 18, 2019

Input file:

fn main() {
    aaaaaaaaaaaaaaaaaaaaa :: bbbbbbbbbbbbbbbbbb :: ccccccccccccccccccccccccccccccccccccccc :: dddddddddddddddddddd ( eeeeeeeeeeeeeeeeeeee :: ffffffffffffffffffff ( ggggggggg ( hhhhhhhhhhhhhhhh ) , iiiiiiiii ( jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj ) ) );
}

As of current master (c0e616b), cargo run --manifest-path path/to/rustfmt/Cargo.toml --release --bin rustfmt <main.rs leaves the long line in this file unchanged.

Shortening the input line such that it can fit within rustfmt's default max_width produces good formatting, as expected:

fn main() {
    bbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccccccccccccccc::dddddddddddddddddddd(
        eeeeeeeeeeeeeeeeeeee::ffffffffffffffffffff(
            ggggggggg(hhhhhhhhhhhhhhhh),
            iiiiiiiii(jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj),
        ),
    );
}

If I configure max_width = 1000, I get correct but very wide formatting, as expected:

fn main() {
    aaaaaaaaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccccccccccccccc::dddddddddddddddddddd(eeeeeeeeeeeeeeeeeeee::ffffffffffffffffffff(ggggggggg(hhhhhhhhhhhhhhhh), iiiiiiiii(jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj)));
}

Is there anything I can set to end up with best-effort formatting, even for content wider than max_width, rather than leaving long lines totally unformatted? Here is what I would want:

fn main() {
    aaaaaaaaaaaaaaaaaaaaa::bbbbbbbbbbbbbbbbbb::ccccccccccccccccccccccccccccccccccccccc::dddddddddddddddddddd(
        eeeeeeeeeeeeeeeeeeee::ffffffffffffffffffff(
            ggggggggg(hhhhhhhhhhhhhhhh),
            iiiiiiiii(jjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj),
        ),
    );
}
@topecongiro
Copy link
Contributor

Unfortunately there is no configuration available to fix this, though I think that rustfmt should be able to handle extremely long idents by default.

@YaLTeR
Copy link
Contributor

YaLTeR commented Aug 15, 2019

Related / duplicate of #2970?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants