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

[implied_bounds_in_impls]: avoid linting on overlapping associated tys #11881

Merged
merged 1 commit into from Feb 13, 2024

Conversation

y21
Copy link
Member

@y21 y21 commented Nov 27, 2023

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

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

@rustbot
Copy link
Collaborator

rustbot commented Nov 27, 2023

r? @Alexendoo

(rustbot has picked a reviewer for you, use r? to override)

@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties label Nov 27, 2023
@bors
Copy link
Collaborator

bors commented Feb 11, 2024

☔ The latest upstream changes (presumably #12269) made this pull request unmergeable. Please resolve the merge conflicts.

@y21
Copy link
Member Author

y21 commented Feb 11, 2024

With the refactor I did in #12269 the diff looks much better and should hopefully be easier to review

@Alexendoo
Copy link
Member

It did indeed, thanks!

@bors r+

@bors
Copy link
Collaborator

bors commented Feb 13, 2024

📌 Commit 92616c0 has been approved by Alexendoo

It is now in the queue for this repository.

bors added a commit that referenced this pull request Feb 13, 2024
[`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
@bors
Copy link
Collaborator

bors commented Feb 13, 2024

⌛ Testing commit 92616c0 with merge b78c157...

@bors
Copy link
Collaborator

bors commented Feb 13, 2024

💔 Test failed - checks-action_test

@Alexendoo
Copy link
Member

@bors retry

@y21
Copy link
Member Author

y21 commented Feb 13, 2024

maybe now?
@bors retry

@bors
Copy link
Collaborator

bors commented Feb 13, 2024

⌛ Testing commit 92616c0 with merge a931de1...

bors added a commit that referenced this pull request Feb 13, 2024
[`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
@bors
Copy link
Collaborator

bors commented Feb 13, 2024

💔 Test failed - checks-action_test

@Alexendoo
Copy link
Member

🤔

@bors retry

@bors
Copy link
Collaborator

bors commented Feb 13, 2024

⌛ Testing commit 92616c0 with merge 3e264ba...

@bors
Copy link
Collaborator

bors commented Feb 13, 2024

☀️ Test successful - checks-action_dev_test, checks-action_remark_test, checks-action_test
Approved by: Alexendoo
Pushing 3e264ba to master...

@bors bors merged commit 3e264ba into rust-lang:master Feb 13, 2024
5 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties
Projects
None yet
Development

Successfully merging this pull request may close these issues.

implied_bounds_in_impls lints on overlapping associated type names
4 participants