Skip to content

Code with usual string not formatted #4331

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

Closed
fanatid opened this issue Jul 16, 2020 · 5 comments
Closed

Code with usual string not formatted #4331

fanatid opened this issue Jul 16, 2020 · 5 comments

Comments

@fanatid
Copy link

fanatid commented Jul 16, 2020

Code from https://github.com/timberio/vector/blob/ff1884062e09956a7696a644f80c401e593d3e6f/src/sinks/statsd.rs but with small changes.

Code on playground not formatted: https://play.rust-lang.org/?version=nightly&mode=debug&edition=2018&gist=f18a74b89c3b1d2a1c894c0f056bc03e

But if comment line 178, code will be formatted.

Line 178:

Bytes::from("vector.counter:1.5|c|#empty_tag:,normal_tag:value,true_tag\nvector.histogram:2|h|@0.01")

I tried cargo-fmt and rustfmt directly.

@fanatid fanatid added the bug Panic, non-idempotency, invalid code, etc. label Jul 16, 2020
@ayazhafiz
Copy link
Contributor

Simpler repro:

fn test_send_to_statsd() {
    rt.block_on_std(async move {
let sink = StatsdSvc::new(config, Acker::Null).unwrap();
        let messages = collect_n(rx, 1).compat().await.ok().unwrap();
        assert_eq(
            messages[0],
            Bytes::from("vector.counter:1.5|c|#empty_tag:,normal_tag:value,true_tag\nvector.histogram:2|h|@0.01")
        );
    });
}

@topecongiro topecongiro added a-strings String literals poor-formatting and removed bug Panic, non-idempotency, invalid code, etc. labels Jul 21, 2020
@hbina

This comment has been minimized.

@calebcartwright

This comment has been minimized.

@ytmimi
Copy link
Contributor

ytmimi commented Jul 20, 2022

Confirming that I can reproduce the issue with rustfmt 1.5.1-nightly (f2c31ba0 2022-07-19). The issue is the long string. The options to fix this issue are to increase the max_width or set format_strings=true. Note: because of the async block we need to set edition=2018.

Input

fn test_send_to_statsd() {
    rt.block_on_std(async move {
let sink = StatsdSvc::new(config, Acker::Null).unwrap();
        let messages = collect_n(rx, 1).compat().await.ok().unwrap();
        assert_eq(
            messages[0],
            Bytes::from("vector.counter:1.5|c|#empty_tag:,normal_tag:value,true_tag\nvector.histogram:2|h|@0.01")
        );
    });
}

output rustfmt --edition=2018 --config=max_width=105 (the min width I found to get it to format)

fn test_send_to_statsd() {
    rt.block_on_std(async move {
        let sink = StatsdSvc::new(config, Acker::Null).unwrap();
        let messages = collect_n(rx, 1).compat().await.ok().unwrap();
        assert_eq(
            messages[0],
            Bytes::from(
                "vector.counter:1.5|c|#empty_tag:,normal_tag:value,true_tag\nvector.histogram:2|h|@0.01",
            ),
        );
    });
}

output rustfmt --edition=2018 --config=format_strings=true

fn test_send_to_statsd() {
    rt.block_on_std(async move {
        let sink = StatsdSvc::new(config, Acker::Null).unwrap();
        let messages = collect_n(rx, 1).compat().await.ok().unwrap();
        assert_eq(
            messages[0],
            Bytes::from(
                "vector.counter:1.5|c|#empty_tag:,normal_tag:value,true_tag\nvector.histogram:\
                 2|h|@0.01",
            ),
        );
    });
}

@calebcartwright I don't think there's anything we can do at this time and I would recommend closing this

@calebcartwright
Copy link
Member

Correct, it's another duplicate of #3863

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Jul 20, 2022
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

6 participants