fix(formatter): account lambda beginning when formatting method call#7857
Merged
fix(formatter): account lambda beginning when formatting method call#7857
Conversation
Contributor
There was a problem hiding this comment.
⚠️ Performance Alert ⚠️
Possible performance regression was detected for benchmark 'Test Suite Duration'.
Benchmark result of this commit is worse than the previous benchmark result exceeding threshold 1.20.
| Benchmark suite | Current: 10a4cd9 | Previous: 053ac2b | Ratio |
|---|---|---|---|
olehmisar_noir_webauthn_ |
2 s |
1 s |
2 |
This comment was automatically generated by workflow using github-action-benchmark.
CC: @TomAFrench
jfecher
approved these changes
Mar 31, 2025
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Problem
Resolves #7407
Summary
The formatter is pretty complex when it comes to deciding how to format method calls, call chains and lambdas but I think the fix here is the "correct" one. The explanation for this change is a bit on line 642-664 of chunks.rs, then on 674-680.
The code in the issue:
now gets formatted like this:
Note how the method call was split into multiple lines. Before this change it would check what's the width of this line:
It's 96, so less than 100, so it would put all of that on one line then proceed to format the lambda. However, there's still "|m| {" in that line... it could be moved to a separate line but it would look strange. So, this PR is changed to take that piece of code into account when determining whether that first part of the call fits into a single line. In this case it doesn't anymore, so the call chain is split into multiple lines.
rustfmt formats the code in the same way (maybe they use a similar logic).
Additional Context
I also added a couple of
Displayimplementations because they are useful when debugging these things.Documentation
Check one:
PR Checklist
cargo fmton default settings.