Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix MergingBehaviour::Last creating unintuitive import trees #6102

Merged
merged 1 commit into from
Sep 30, 2020

Conversation

Veykril
Copy link
Member

@Veykril Veykril commented Sep 30, 2020

The way this behaviour currently works is actually a bit weird. Imagine the following three imports get requested for insertion in the given order:

  • winapi::um::d3d11::ID3D11Device
  • winapi::shared::dxgiformat::DXGI_FORMAT
  • winapi::um::d3d11::D3D11_FILTER

After the first two you will have the following tree:

use winapi::{shared::dxgiformat::DXGI_FORMAT, um::d3d11::ID3D11Device};

which is to be expected as they arent nested this kind of merging is allowed, but now importing the third one will result in:

use winapi::{shared::dxgiformat::DXGI_FORMAT, um::d3d11::ID3D11Device, um::d3d11::D3D11_FILTER};

which is still fine according to the rules, but it looks weird(at least in my eyes) due to the long paths that are quite similar. The changes in this PR will change the criteria for when to reject Last merging, it still disallows multiple nesting but it also only allows single segment paths inside of the UseTreeList. With this change you get the following tree after the first two imports:

use winapi::um::d3d11::ID3D11Device;
use winapi::shared::dxgiformat::DXGI_FORMAT;

and after the third:

use winapi::shared::dxgiformat::DXGI_FORMAT;
use winapi::um::d3d11::{ID3D11Device, D3D11_FILTER};

Which I believe looks more like what you would expect.

@jonas-schievink
Copy link
Contributor

Perfect, I noticed these odd-looking imports showing up

bors r+

@bors
Copy link
Contributor

bors bot commented Sep 30, 2020

@bors bors bot merged commit 43253c5 into rust-lang:master Sep 30, 2020
bors bot added a commit that referenced this pull request Oct 2, 2020
6105: Fix path comparison not comparing paths correctly with unequal lengths r=matklad a=Veykril

~~This PR includes the commit from #6102 there as I found a bug while writing that(so either merging this or both in order works) so I included a test there already which was just ignored.~~ This PR fixes that, basically inserting imports didn't consider path length for equality, so depending on the order it might insert the path before or after another import if they only differ in segment length.

~~Diff without the commit of #6102 2d90d3937d71f9a00f3d44c15b20679215311637~~



Co-authored-by: Lukas Wirth <lukastw97@gmail.com>
@Veykril Veykril deleted the fix-mblast branch December 2, 2021 00:49
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants