Compare trait references in trait_duplication_in_bounds
correctly
#13493
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.
Fixes #13476
Fixes #11067
Fixes #9915
Fixes #9626
Currently, the
trait_duplication_in_bounds
lints has a helper type for a trait reference that can be used for comparison and hashing, represented as{trait: Res, generic_args: Vec<Res>}
. However, there are a lot of issues with this. For one, aRes
can't represent e.g. references, slices, or lots of other types, as well as const generics and associated type equality. In those cases, the lint simply ignores them and has no way of checking if they're actually the same.So, instead of using
Res
for this, useSpanlessEq
andSpanlessHash
for comparisons with the trait path for checking if there are duplicates.However, using
SpanlessEq
as is alone lead to a false negative in the test.std::clone::Clone
+foo::Clone
wasn't recognized as a duplicate, because it has different segments. So this also adds a new "mode" to SpanlessEq which compares by final resolution. (I've been wondering if this can't just be the default but it's quite a large scale change as it affects a lot of lints and I haven't yet looked at all uses of it to see if there are lints that really do care about having exactly the same path segments).Maybe an alternative would be to turn the hir types/consts into middle types/consts and compare them instead but I'm not sure there's really a good way to do that
changelog: none