Open
Description
Code like this:
fn put_telescope_synctocoordinates(
PutTelescopeSynctocoordinatesPathParams {
device_number,
}: PutTelescopeSynctocoordinatesPathParams,
) {
}
triggers "left behind trailing whitespace".
I suppose it's because rustfmt tries to put entire param - both pattern and type - on the same line, fails in doing so as that exceeds the max width, and gives up. Instead, it should probably fallback to something like
fn put_telescope_synctocoordinates(
PutTelescopeSynctocoordinatesPathParams {
device_number,
}: PutTelescopeSynctocoordinatesPathParams,
) {
}
Metadata
Metadata
Assignees
Type
Projects
Milestone
Relationships
Development
No branches or pull requests
Activity
ytmimi commentedon Oct 4, 2022
Thanks for the report!.
I believe your assessment is correct and we're trying to put the pattern and the type on the same line. After looking into it I think what's happening is there's enough space to write the pattern on a single line so we format it on one line, but there isn't enough space to put both the pattern and the type on one line so rewriting fails, which leads to returning the span unchanged. I did some digging to try and pin that down:
starting at
rewrite_fn_base
, we eventually callrewrite_params
rustfmt/src/items.rs
Lines 2287 to 2296 in ef91154
rewrite_params
then calls theRewrite
impl forast::Param
, and if it fails to format the param we just return the original span unchanged, which explains theleft behind trailing whitespace
issue.rustfmt/src/items.rs
Lines 2595 to 2597 in ef91154
For anyone interested in taking this on I'd start looking at the
is_named_param
if-else block in theast::Param
Rewrite impl
.rustfmt/src/items.rs
Lines 2035 to 2088 in ef91154
I'd assume we'll also need to make some changes to
rewrite_struct_pat
, which gets called as a result of rewriting a struct pattern (the self.pat.rewrite call above Line 2036).rustfmt/src/patterns.rs
Lines 258 to 260 in ef91154
sammysheep commentedon Oct 11, 2022
calebcartwright commentedon Oct 12, 2022
YpeKingma commentedon Nov 6, 2022
YpeKingma commentedon Nov 6, 2022
ytmimi commentedon Nov 7, 2022
let
into tuple #5812