Skip to content

Commit bec7193

Browse files
Don't use implied trait predicates in gather_explicit_predicates_of
1 parent 8ea71f2 commit bec7193

22 files changed

+319
-79
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
9696
| ItemKind::Struct(_, generics)
9797
| ItemKind::Union(_, generics) => generics,
9898

99-
ItemKind::Trait(_, _, generics, ..) | ItemKind::TraitAlias(generics, _) => {
100-
is_trait = Some(ty::TraitRef::identity(tcx, def_id.to_def_id()));
99+
ItemKind::Trait(_, _, generics, self_bounds, ..)
100+
| ItemKind::TraitAlias(generics, self_bounds) => {
101+
is_trait = Some(self_bounds);
101102
generics
102103
}
103104
ItemKind::OpaqueTy(OpaqueTy { generics, .. }) => generics,
@@ -119,10 +120,14 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
119120

120121
// Below we'll consider the bounds on the type parameters (including `Self`)
121122
// and the explicit where-clauses, but to get the full set of predicates
122-
// on a trait we need to add in the supertrait bounds and bounds found on
123-
// associated types.
124-
if let Some(_trait_ref) = is_trait {
125-
predicates.extend(tcx.implied_predicates_of(def_id).predicates.iter().cloned());
123+
// on a trait we must also consider the bounds that follow the trait's name,
124+
// like `trait Foo: A + B + C`.
125+
if let Some(self_bounds) = is_trait {
126+
predicates.extend(
127+
icx.astconv()
128+
.compute_bounds(tcx.types.self_param, self_bounds, OnlySelfBounds(false))
129+
.predicates(),
130+
);
126131
}
127132

128133
// In default impls, we can assume that the self type implements

tests/rustdoc-ui/issues/issue-105742.rs

+8
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ pub trait SVec: Index<
1919
//~| missing generics for associated type `SVec::Item`
2020
//~| missing generics for associated type `SVec::Item`
2121
//~| missing generics for associated type `SVec::Item`
22+
//~| missing generics for associated type `SVec::Item`
23+
//~| missing generics for associated type `SVec::Item`
2224
Output = <Index<<Self as SVec>::Item,
2325
//~^ expected 1 lifetime argument
2426
//~| expected 1 generic argument
2527
//~| missing generics for associated type `SVec::Item`
2628
//~| missing generics for associated type `SVec::Item`
2729
//~| missing generics for associated type `SVec::Item`
2830
//~| missing generics for associated type `SVec::Item`
31+
//~| missing generics for associated type `SVec::Item`
32+
//~| missing generics for associated type `SVec::Item`
2933
Output = <Self as SVec>::Item> as SVec>::Item,
3034
//~^ expected 1 lifetime argument
3135
//~| expected 1 generic argument
@@ -34,11 +38,15 @@ pub trait SVec: Index<
3438
//~| missing generics for associated type `SVec::Item`
3539
//~| missing generics for associated type `SVec::Item`
3640
//~| missing generics for associated type `SVec::Item`
41+
//~| missing generics for associated type `SVec::Item`
42+
//~| missing generics for associated type `SVec::Item`
3743
//~| expected 1 generic argument
3844
//~| missing generics for associated type `SVec::Item`
3945
//~| missing generics for associated type `SVec::Item`
4046
//~| missing generics for associated type `SVec::Item`
4147
//~| missing generics for associated type `SVec::Item`
48+
//~| missing generics for associated type `SVec::Item`
49+
//~| missing generics for associated type `SVec::Item`
4250
> {
4351
type Item<'a, T>;
4452

0 commit comments

Comments
 (0)