Skip to content

Double quotes in specific positions cause string formatting errors #6315

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
waruto210 opened this issue Sep 7, 2024 · 7 comments
Closed
Labels
a-strings String literals bug Panic, non-idempotency, invalid code, etc. duplicate only-with-option requires a non-default option value to reproduce

Comments

@waruto210
Copy link

waruto210 commented Sep 7, 2024

If we set max_width = 100, and a double quote in the string appears at Col 100 during the formatting process, this double quote will be moved to the next line, causing a syntax error.

fn main() {
    let value = 1;

    let ret = format!("a.string.have.double.quote.paddinggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\"{}\"", value);
}

After formatting, the code becomes:

fn main() {
    let value = 1;

    let ret = format!(
        "a.string.have.double.quote.\
         paddinggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggggg\\
         "{}\"",
        value
    );
}
@waruto210
Copy link
Author

@ytmimi PTAL

@ytmimi
Copy link
Contributor

ytmimi commented Sep 9, 2024

PTAL?

@waruto210
Copy link
Author

PTAL?

I mean that can you please take a look?

@ytmimi
Copy link
Contributor

ytmimi commented Sep 9, 2024

@waruto210 what version of rustfmt are you using, and what configuration options are you setting?

@waruto210
Copy link
Author

@waruto210 what version of rustfmt are you using, and what configuration options are you setting?

To reproduce:
rust-toolchain.toml

channel = "nightly-2024-08-25"

rust-fmttoml

max_width = 100
format_strings = true

I have also changed the toolchain to some earlier versions,such as nightly-2024-06-25, but got the same error.

@ytmimi
Copy link
Contributor

ytmimi commented Sep 9, 2024

You shouldn't need to update the toolchain version. rustfmt is pinned to specific nightly toolchain. The issue is most likely a bug with format_strings There's been a similar issue about not properly handling escapes posted before. I'll try to look for it later and see if they're related or if this is a duplicate.

@ytmimi ytmimi added bug Panic, non-idempotency, invalid code, etc. only-with-option requires a non-default option value to reproduce a-strings String literals labels Sep 9, 2024
@ytmimi
Copy link
Contributor

ytmimi commented Sep 12, 2024

Did some digging. This is a duplicate of #5138

@ytmimi ytmimi closed this as not planned Won't fix, can't repro, duplicate, stale Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
a-strings String literals bug Panic, non-idempotency, invalid code, etc. duplicate only-with-option requires a non-default option value to reproduce
Projects
None yet
Development

No branches or pull requests

2 participants