fix(fmt): break chain after overlong named call argument#15825
Conversation
7aedf4d to
aa6a82f
Compare
…nt-1784539000 # Conflicts: # crates/fmt/src/state/sol.rs
| let ast::ExprKind::Call(callee, args) = &expr.kind else { return None }; | ||
| let ast::CallArgsKind::Named(args) = &args.kind else { return None }; | ||
| let args_size = args.iter().try_fold(0usize, |size, arg| { | ||
| Some(size + arg.name.as_str().len() + 2 + self.estimate_call_chain_size(arg.value)?) |
There was a problem hiding this comment.
At line_length = 120, overlong named calls with boolean or arithmetic values leave the following chain link attached as ).update(), while calls with the same callee and named-argument names but identifier values place .update() on a new line. estimate_call_chain_size returns None for boolean literals and binary expressions, so estimate_named_call_size cannot detect that these calls are overlong. Could these value kinds participate in the width check as well?
There was a problem hiding this comment.
Fixed in 9bf59ea: boolean literals and binary expressions now participate in the flat-width estimate, with regression cases for both argument value kinds.
| innerFactory().anExtremelyLongMethodNameThatForcesTheNestedCalleeToWrap({ | ||
| firstExtremelyLongArgumentName: true | ||
| }) | ||
| ) |
There was a problem hiding this comment.
This snapshot currently fails: the formatter emits ).update();. This nested call is only 111 characters, so it does not trigger the > 120 rule.
| self.estimate_call_chain_size(lhs)? | ||
| + op.to_string().len() | ||
| + self.estimate_call_chain_size(rhs)? | ||
| + 2, |
There was a problem hiding this comment.
This always counts two operator spaces, but pow_no_space = true emits ** without spaces.
| + args_size | ||
| + args.len().saturating_sub(1) * 2 | ||
| + 4, | ||
| ) |
There was a problem hiding this comment.
Should we include configured brace spacing in the estimate?
When a call-chain link takes an overlong named-argument call as a positional argument, place the following chain link on its own line.
The break is limited to arguments whose canonical formatted width exceeds the configured line length; a short nested named call remains inline. This avoids the unconditional
hardbreak()behavior previously included in #15824.Checks:
cargo +nightly fmt --all -- --checkgit diff --checkPrompted by: @DaniPopes