Consider Imports Reorder config when merging Use Trees #5621
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.
While evaluating enhancements to PR #5612, I found that merging use-trees does not take into account the
imports_reorder
setting and it is considered to set astrue
. Assuming this is an issue, this PR is an attempt to fix it. This is done by adding theimports_reorder
config value as a parameter to the use-trees merge related functions.Note that because of the added parameter, many internal test cases in
imports.rs
were changed. For the existing tests I addedtrue
as theimports_reorder
value, and I added a version of the tests withfalse
value.One case that is not handled by this PR, and that was raised in a PR #5612 comment is the formatting of the following code, when
imports_granularity=Preserve
andreorder_imports=true
:In this case, because of the
Preserve
, it is expected that the output will beuse a::b::c::{d::e}
, but it isuse a::b::c::d::e
.For the record, following is a possible fix for this issue (if it is an issue). I didn't add this fix because it affects some existing test cases. The possible fix is to UseTree::normalize():
imports_granularity
argument to the function (usually the passed value iscontext.config.imports_granularity()
).rustfmt/src/imports.rs
Lines 590 to 595 in ee2bed9
To: