You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Rollup merge of #140684 - compiler-errors:unnecessary-assoc, r=lcnr
Only include `dyn Trait<Assoc = ...>` associated type bounds for `Self: Sized` associated types if they are provided
Since #136458, we began filtering out associated types with `Self: Sized` bounds when constructing the list of associated type bounds to put into our `dyn Trait` types. For example, given:
```rust
trait Trait {
type Assoc where Self: Sized;
}
```
After #136458, even if a user writes `dyn Trait<Assoc = ()>`, the lowered ty would have an empty projection list, and thus be equivalent to `dyn Trait`. However, this has the side effect of no longer constraining any types in the RHS of `Assoc = ...`, not implying any WF implied bounds, and not requiring that they hold when unsizing.
After this PR, we include these bounds, but (still) do not require that they are provided. If the are not provided, they are skipped from the projections list.
This results in `dyn Trait` types that have differing numbers of projection bounds. This will lead to re-introducing type mismatches e.g. between `dyn Trait` and `dyn Trait<Assoc = ()>`. However, this is expected and doesn't suffer from any of the deduplication unsoundness from before #136458.
We may want to begin to ignore thse bounds in the future by bumping `unused_associated_type_bounds` to an FCW. I don't want to tangle that up into the fix that was originally intended in #136458, so I'm doing a "fix-forward" in this PR and deferring thinking about this for the future.
Fixes#140645
r? lcnr
warning: unnecessary associated type bound for dyn-incompatible associated type
2
+
--> $DIR/constrain-via-unnecessary-bound.rs:17:26
3
+
|
4
+
LL | impl Other for dyn Trait<Assoc = ()> {}
5
+
| ^^^^^^^^^^ help: remove this bound
6
+
|
7
+
= note: this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized`
8
+
= note: `#[warn(unused_associated_type_bounds)]` on by default
9
+
10
+
warning: unnecessary associated type bound for dyn-incompatible associated type
11
+
--> $DIR/constrain-via-unnecessary-bound.rs:21:19
12
+
|
13
+
LL | impl<T> dyn Trait<Assoc = T> {}
14
+
| ^^^^^^^^^ help: remove this bound
15
+
|
16
+
= note: this associated type has a `where Self: Sized` bound, and while the associated type can be specified, it cannot be used because trait objects are never `Sized`
0 commit comments