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
[implied_bounds_in_impls
]: avoid linting on overlapping associated tys
#11881
Conversation
r? @Alexendoo (rustbot has picked a reviewer for you, use r? to override) |
☔ The latest upstream changes (presumably #12269) made this pull request unmergeable. Please resolve the merge conflicts. |
With the refactor I did in #12269 the diff looks much better and should hopefully be easier to review |
It did indeed, thanks! @bors r+ |
[`implied_bounds_in_impls`]: avoid linting on overlapping associated tys Fixes #11880 Before this change, we were simply ignoring associated types (except for suggestion purposes), because of an incorrect assumption (see the comment that I also removed). For something like ```rs trait X { type T; } trait Y: X { type T; } // Can't constrain `X::T` through `Y` fn f() -> impl X<T = i32> + Y<T = u32> { ... } ``` We now avoid linting if the implied bound (`X<T = i32>`) "names" associated types that also exists in the implying trait (`trait Y`). Here that would be the case. But if we only wrote `impl X + Y<T = u32>` then that's ok because `X::T` was never constrained in the first place. I haven't really thought about how this interacts with GATs, but I think it's fine. Fine as in, it might create false negatives, but hopefully no false positives. (The diff is slightly annoying because of formatting things. Really the only thing that changed in the if chain is extracting the `implied_by_def_id` which is needed for getting associated types from the trait, and of course actually checking for overlap) cc `@Jarcho` ? idk if you want to review this or not. I assume you looked into this code a bit to find this bug. changelog: [`implied_bounds_in_impls`]: avoid linting when associated type from supertrait can't be constrained through the implying trait bound
💔 Test failed - checks-action_test |
@bors retry |
maybe now? |
[`implied_bounds_in_impls`]: avoid linting on overlapping associated tys Fixes #11880 Before this change, we were simply ignoring associated types (except for suggestion purposes), because of an incorrect assumption (see the comment that I also removed). For something like ```rs trait X { type T; } trait Y: X { type T; } // Can't constrain `X::T` through `Y` fn f() -> impl X<T = i32> + Y<T = u32> { ... } ``` We now avoid linting if the implied bound (`X<T = i32>`) "names" associated types that also exists in the implying trait (`trait Y`). Here that would be the case. But if we only wrote `impl X + Y<T = u32>` then that's ok because `X::T` was never constrained in the first place. I haven't really thought about how this interacts with GATs, but I think it's fine. Fine as in, it might create false negatives, but hopefully no false positives. (The diff is slightly annoying because of formatting things. Really the only thing that changed in the if chain is extracting the `implied_by_def_id` which is needed for getting associated types from the trait, and of course actually checking for overlap) cc `@Jarcho` ? idk if you want to review this or not. I assume you looked into this code a bit to find this bug. changelog: [`implied_bounds_in_impls`]: avoid linting when associated type from supertrait can't be constrained through the implying trait bound
💔 Test failed - checks-action_test |
🤔 @bors retry |
☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test |
Fixes #11880
Before this change, we were simply ignoring associated types (except for suggestion purposes), because of an incorrect assumption (see the comment that I also removed).
For something like
We now avoid linting if the implied bound (
X<T = i32>
) "names" associated types that also exists in the implying trait (trait Y
). Here that would be the case.But if we only wrote
impl X + Y<T = u32>
then that's ok becauseX::T
was never constrained in the first place.I haven't really thought about how this interacts with GATs, but I think it's fine. Fine as in, it might create false negatives, but hopefully no false positives.
(The diff is slightly annoying because of formatting things. Really the only thing that changed in the if chain is extracting the
implied_by_def_id
which is needed for getting associated types from the trait, and of course actually checking for overlap)cc @Jarcho ? idk if you want to review this or not. I assume you looked into this code a bit to find this bug.
changelog: [
implied_bounds_in_impls
]: avoid linting when associated type from supertrait can't be constrained through the implying trait bound