Skip to content

Commit 309e371

Browse files
Ignore Self in bounds check for associated types with Self:Sized
1 parent 608e228 commit 309e371

File tree

2 files changed

+17
-0
lines changed

2 files changed

+17
-0
lines changed

compiler/rustc_trait_selection/src/traits/dyn_compatibility.rs

+3
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,10 @@ fn predicates_reference_self(
187187
fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span; 1]> {
188188
tcx.associated_items(trait_def_id)
189189
.in_definition_order()
190+
// We're only looking at associated type bounds
190191
.filter(|item| item.kind == ty::AssocKind::Type)
192+
// Ignore GATs with `Self: Sized`
193+
.filter(|item| !tcx.generics_require_sized_self(item.def_id))
191194
.flat_map(|item| tcx.explicit_item_bounds(item.def_id).iter_identity_copied())
192195
.filter_map(|(clause, sp)| {
193196
// Item bounds *can* have self projections, since they never get
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
// Ensure that we properly ignore the `B<Self>` associated type bound on `A::T`
2+
// since that associated type requires `Self: Sized`.
3+
4+
//@ check-pass
5+
6+
struct X(&'static dyn A);
7+
8+
trait A {
9+
type T: B<Self> where Self: Sized;
10+
}
11+
12+
trait B<T> {}
13+
14+
fn main() {}

0 commit comments

Comments
 (0)