Skip to content

Rustfmt doesn't work in for_each blocks with long strings literals #3416

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
tafia opened this issue Feb 25, 2019 · 2 comments
Closed

Rustfmt doesn't work in for_each blocks with long strings literals #3416

tafia opened this issue Feb 25, 2019 · 2 comments

Comments

@tafia
Copy link

tafia commented Feb 25, 2019

Rustfmt fails to format for_each blocks when there is a long str literal.

  • example before running rustfmt:
fn main() {
    // this block will be properly formatted
    {
        let a = 1;
    let b=2;
    let c = " very very very very very very very very very very very very very very very very very very long string in a block";
    }

    let v = vec![1, 2];

    // this block won't be formatted
    v.iter().for_each(|_| {
        let a = 1;
    let b=2;
    let c = " very very very very very very very very very very very very very very very very very very long string in a block";
    });

    // this block with shorter str will be properly formatted
    v.iter().for_each(|_| {
        let a = 1;
    let b=2;
    let c = " less very very long string in a block";
    });
}
  • after running rustfmt
fn main() {
    // this block will be properly formatted
    {
        let a = 1;
        let b = 2;
        let c = " very very very very very very very very very very very very very very very very very very long string in a block";
    }

    let v = vec![1, 2];

    // this block won't be formatted
    v.iter().for_each(|_| {
        let a = 1;
    let b=2;
    let c = " very very very very very very very very very very very very very very very very very very long string in a block";
    });

    // this block with shorter str will be properly formatted
    v.iter().for_each(|_| {
        let a = 1;
        let b = 2;
        let c = " less very very long string in a block";
    });
}

Not sure if this is a known bug or not ...

EDIT: added example with short &str in for_each block.

@scampi
Copy link
Contributor

scampi commented Feb 26, 2019

There are some other similar issues, e.g., #3206 and #3135 . From what I remember with these other issues, there is a call to wrap_str that is cancelling any attempts to format that closure.
If you can use the format_strings option, then that block can be formatted.

@calebcartwright
Copy link
Member

calebcartwright commented Jul 22, 2022

closing as duplicate of #3863 (realize this is older, but the other issue has more active discussion and plans for next steps so would prefer to consolidate things there)

@calebcartwright calebcartwright closed this as not planned Won't fix, can't repro, duplicate, stale Jul 22, 2022
@calebcartwright calebcartwright removed this from the 3.0.0 milestone Jul 22, 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

4 participants