Skip to content

Commit

Permalink
Don't use implied trait predicates in gather_explicit_predicates_of
Browse files Browse the repository at this point in the history
  • Loading branch information
compiler-errors committed May 1, 2023
1 parent 8ea71f2 commit bec7193
Show file tree
Hide file tree
Showing 22 changed files with 319 additions and 79 deletions.
17 changes: 11 additions & 6 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -96,8 +96,9 @@ fn gather_explicit_predicates_of(tcx: TyCtxt<'_>, def_id: LocalDefId) -> ty::Gen
| ItemKind::Struct(_, generics)
| ItemKind::Union(_, generics) => generics,

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

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

// In default impls, we can assume that the self type implements
Expand Down
8 changes: 8 additions & 0 deletions tests/rustdoc-ui/issues/issue-105742.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,17 @@ pub trait SVec: Index<
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
Output = <Index<<Self as SVec>::Item,
//~^ expected 1 lifetime argument
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
Output = <Self as SVec>::Item> as SVec>::Item,
//~^ expected 1 lifetime argument
//~| expected 1 generic argument
Expand All @@ -34,11 +38,15 @@ pub trait SVec: Index<
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| expected 1 generic argument
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
//~| missing generics for associated type `SVec::Item`
> {
type Item<'a, T>;

Expand Down
Loading

0 comments on commit bec7193

Please sign in to comment.