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
If I have a long list of trait bounds in a generic params list, I'd expect to be able to use the --file-lines option to format part of that list without affecting other parts of the function signature (or whatever the surrounding context is). But right now if any attempt to partially format the bounds list will cause the entire list to be reformatted, potentially pulling it all onto one line, modifying unselected lines in the process.
Summary
Consider the following code, where there's a long list of trait bounds and a couple of them are misaligned:
I would like to use --file-lines to format just lines 6-7 to pull the two misaligned trait bounds in line with the rest, but not otherwise reformat the list.
Note that because of #6868 the entire function signature is getting reformatted to one line. If that issue were fixed, the output here would look more like the following, where just the bounds list gets reformatted:
That highlights the more fundamental issue here, that the logic for laying out the trait bounds list doesn't account for --file-lines and so can pull everything onto one line, modifying unselected lines in the process.
The relevant code is in join_bounds_inner, which currently doesn't check the --file-lines configuration at all.
There's a few related issues here due to --file-lines not being fully implemented:
Right now any attempt to partially format a function signature will reformat the whole thing (tracked by file-lines can't partially format function signatures #6868), so in the example above we see the entire function get rewritten to a single line.
Part of file-lines can't partially format where clauses #6872, which tracks partial formatting of where clauses. Fixing this issue is a requirement for fixing that one, since a where clause is made up of a list of trait bounds lists, but I think this is worth splitting off into its own issue because trait bounds lists can show up outside of where clauses.
This might need to be added as a blocker for [unstable option] file_lines #3397, though I think there's some room to discuss what the actual desired behavior is here, and that may mean this doesn't need to block stabilization.
If I have a long list of trait bounds in a generic params list, I'd expect to be able to use the
--file-linesoption to format part of that list without affecting other parts of the function signature (or whatever the surrounding context is). But right now if any attempt to partially format the bounds list will cause the entire list to be reformatted, potentially pulling it all onto one line, modifying unselected lines in the process.Summary
Consider the following code, where there's a long list of trait bounds and a couple of them are misaligned:
I would like to use
--file-linesto format just lines 6-7 to pull the two misaligned trait bounds in line with the rest, but not otherwise reformat the list.Expected behavior
Actual behavior
Note that because of #6868 the entire function signature is getting reformatted to one line. If that issue were fixed, the output here would look more like the following, where just the bounds list gets reformatted:
That highlights the more fundamental issue here, that the logic for laying out the trait bounds list doesn't account for
--file-linesand so can pull everything onto one line, modifying unselected lines in the process.Configuration
rustfmtcli options used:rustfmt --unstable-features --file-lines '[{"file":"test.rs","range":[6,7]}]' test.rsMeta
The relevant code is in
join_bounds_inner, which currently doesn't check the--file-linesconfiguration at all.There's a few related issues here due to
--file-linesnot being fully implemented:whereclauses. Fixing this issue is a requirement for fixing that one, since awhereclause is made up of a list of trait bounds lists, but I think this is worth splitting off into its own issue because trait bounds lists can show up outside ofwhereclauses.