You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
// Tested with 1.5.1-nightly (2022-11-01 11ebe65)implRebasePlanBuilder{fnmake_rebase_plan_for_current_commit(){if acc.any(|| {matches!(foo,Merge{
commit_oid,replacement_commit_oid: _, new_parents:_ }if commit_oid == current_commit)}){// No formatting in the above `matches!`, which is maybe understandable.// But formatting inside this block seems to be inhibited too?foo{bar}}}fnmake_rebase_plan_for_current_commit(){if || {matches!(foo,Merge{
commit_oid,replacement_commit_oid: _, new_parents:_ }if commit_oid == current_commit)}{// Okayfoo{ bar }}}fnmake_rebase_plan_for_current_commit(){if acc.any(|| {matches!(foo,Merge{
commit_oid,replacement_commit_oid: _, new_parents }if commit_oid == current_commit)}){// Okayfoo{ bar }}}}
In the first fn, the body of the if-statement is not formatted. Actual behavior: stays as foo{bar}. Expected behavior: becomes foo { bar }. But by removing the acc.any() call around the condition, the body starts being formatted again. The complexity (or presence of macros) in the if-condition shouldn't affect whether the body is formatted.
The text was updated successfully, but these errors were encountered:
There are two issues at play here. First rustfmt doesn't handle matches! macros all that well when there's a guard clause (#5547). Failing to format the matches! leads to the line with if commit_oid == current_commit exceeding the max_width of 100, which then triggers #3863. Failing to format the chained method call acc.any() leads to rustfmt being unable to format the if-block.
This boils down to a max_width issue, and if you'd like some immediate relief you can bump up the max_width e.g. max_width=110
For some additional info rustfmt operates on the AST nodes of your program and when it can't format part of that node it fails to format the entire node and leaves the code unchanged. In this case an ast::Expr node with a kind field of ast::ExprKind::If is the node in question, and because we fail to format the conditional expression for the reasons mentioned above we fail to format the if-block.
@ytmimi is there a way to get rustfmt to emit a warning when a node fails to be formatted due to max_width? I suspected as much, but I couldn't find an obvious way to confirm.
Repro case: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=ad64f0e25dfb5ae14d9693020ed0ff07
Code
In the first
fn
, the body of theif
-statement is not formatted. Actual behavior: stays asfoo{bar}
. Expected behavior: becomesfoo { bar }
. But by removing theacc.any()
call around the condition, the body starts being formatted again. The complexity (or presence of macros) in theif
-condition shouldn't affect whether the body is formatted.The text was updated successfully, but these errors were encountered: