diff options
| author | Michael Goulet <michael@errs.io> | 2025-02-15 20:38:08 +0000 |
|---|---|---|
| committer | Michael Goulet <michael@errs.io> | 2025-02-15 20:38:14 +0000 |
| commit | 309e371f7b062865199c38cfebe00173698c0aad (patch) | |
| tree | 85fb1c93916dcf36e6dddd11bf85c3e957788256 | |
| parent | 608e228ca9a1e57336ca5c16e5722a8ac8284d8d (diff) | |
| download | rust-309e371f7b062865199c38cfebe00173698c0aad.tar.gz rust-309e371f7b062865199c38cfebe00173698c0aad.zip | |
Ignore Self in bounds check for associated types with Self:Sized
| -rw-r--r-- | compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs | 3 | ||||
| -rw-r--r-- | tests/ui/dyn-compatibility/associated_type_bound_mentions_self.rs | 14 |
2 files changed, 17 insertions, 0 deletions
diff --git a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs index 617bc87a9d2..a0df74835bc 100644 --- a/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs +++ b/compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs @@ -187,7 +187,10 @@ fn predicates_reference_self( fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> { tcx.associated_items(trait_def_id) .in_definition_order() + // We're only looking at associated type bounds .filter(|item| item.kind == ty::AssocKind::Type) + // Ignore GATs with `Self: Sized` + .filter(|item| !tcx.generics_require_sized_self(item.def_id)) .flat_map(|item| tcx.explicit_item_bounds(item.def_id).iter_identity_copied()) .filter_map(|(clause, sp)| { // Item bounds *can* have self projections, since they never get diff --git a/tests/ui/dyn-compatibility/associated_type_bound_mentions_self.rs b/tests/ui/dyn-compatibility/associated_type_bound_mentions_self.rs new file mode 100644 index 00000000000..0be5fa27b4c --- /dev/null +++ b/tests/ui/dyn-compatibility/associated_type_bound_mentions_self.rs @@ -0,0 +1,14 @@ +// Ensure that we properly ignore the `B<Self>` associated type bound on `A::T` +// since that associated type requires `Self: Sized`. + +//@ check-pass + +struct X(&'static dyn A); + +trait A { + type T: B<Self> where Self: Sized; +} + +trait B<T> {} + +fn main() {} |
