Rustfmt silently fails to work

I've run into some possible edge case with rustfmt - it fails to format my code, either via editor action (from Rust Analyzer) or from cargo fmt. This happens with some deeply nested code, like this:

pub struct Foo;

impl Foo {
    fn foo() {
        {
            self.bar(|| async move {
            {
                {
                    {
                        {
                                    {
                                        if let Err(_) = res {
                                        } else {
                                            log::info!(
                                                "Logging relatively long info message, with included ID={}",
                                                id
                                            );
                                        }
                                    }
                        }
                    }
                }
            }
        });
        }
    }
}

Playground - the behavior is reproduced there (with Tools - Rustfmt). This seems to be a fairly minimal example - removing anything from this code allows rustfmt to work again.

Should I file an issue on the repo, or is there anything I can do with configuration?

This is sort of intentional by rustfmt. If its reformatting cannot get the code under the line length limit (often due to a long string literal), it will leave the existing formatting untouched, for the entire statement or item.

Unfortunately, it doesn't produce any warning that this happened.

1 Like

Thanks, will know.

This topic was automatically closed 90 days after the last reply. We invite you to open a new topic if you have further questions or comments.