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

rustfmt dies on this line of code #4073

Closed
sanbox-irl opened this issue Mar 5, 2020 · 5 comments
Closed

rustfmt dies on this line of code #4073

sanbox-irl opened this issue Mar 5, 2020 · 5 comments

Comments

@sanbox-irl
Copy link

Hello!

    let mut staff_card = foo.staff_card_hand.pick_out_card(&staff_card_name).ok_or_else(|| 
        format_err!("We didn't have a valid card, or the card we tried to play is something the player doesn't have!")
    );

Please especially note the after the ||. Without that, this formats just fine.

Additionally, my rustfmt.toml is:

max_width = 110
edition = "2018"

Changing almost any part of the above sample causes it to format correctly. I cannot narrow it down any further -- it seems to have something to do with line length, or maybe even the shape of the call?

@calebcartwright
Copy link
Member

When you say that rustfmt "dies", does that mean that rustfmt is giving you an error, or simply that the formatting is left unchanged?

@sanbox-irl
Copy link
Author

Ah sorry for not being clearer -- It fails to format the entire file if that line is there

@sanbox-irl
Copy link
Author

It does not hard crash or anything like that.

@calebcartwright
Copy link
Member

There's a known existing issue in rustfmt wherein if the formatted result of any single chain element exceeds the value of max_width then rustfmt will fail to format the entire chain, maintaining the original snippet for the chain.

However, that only applies to that individual chain, and the rest of the file should be formatted.

Separately, I would've thought rustfmt would emit an error as a result of the empty trailing space in that case 🤔

Are you able to share the broader file or example that shows rustfmt failing to format other items in the file?

With something like this, rustfmt will indeed ignore the chain (due to the issue discussed above) but the foo function formatting is still updated

fn main() {
    let mut staff_card = foo.staff_card_hand.pick_out_card(&staff_card_name).ok_or_else(|| 
        format_err!("We didn't have a valid card, or the card we tried to play is something the player doesn't have!")
    );
}

fn foo (  ) {  }

@calebcartwright
Copy link
Member

Closing in favor of #3863

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

3 participants