1
Fork 0

Validate self in host predicates correctly

This commit is contained in:
Michael Goulet 2024-12-10 02:28:02 +00:00
parent f6cb952dc1
commit 5d1b6bfc6a
2 changed files with 31 additions and 2 deletions

View file

@ -711,12 +711,19 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
`{filter:?}` implied bounds: {clause:?}" `{filter:?}` implied bounds: {clause:?}"
); );
} }
ty::ClauseKind::HostEffect(host_effect_predicate) => {
assert_eq!(
host_effect_predicate.self_ty(),
ty,
"expected `Self` predicate when computing \
`{filter:?}` implied bounds: {clause:?}"
);
}
ty::ClauseKind::RegionOutlives(_) ty::ClauseKind::RegionOutlives(_)
| ty::ClauseKind::ConstArgHasType(_, _) | ty::ClauseKind::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_) | ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_) | ty::ClauseKind::ConstEvaluatable(_) => {
| ty::ClauseKind::HostEffect(..) => {
bug!( bug!(
"unexpected non-`Self` predicate when computing \ "unexpected non-`Self` predicate when computing \
`{filter:?}` implied bounds: {clause:?}" `{filter:?}` implied bounds: {clause:?}"

View file

@ -0,0 +1,22 @@
// Regression test for <https://github.com/rust-lang/rust/issues/133526>.
// Ensures we don't ICE when we encounter a `HostEffectPredicate` when computing
// the "item super predicates" for `Assoc`.
//@ compile-flags: -Znext-solver
//@ check-pass
#![feature(const_trait_impl)]
#[const_trait]
trait Trait {
type Assoc: const Trait;
}
const fn needs_trait<T: ~const Trait>() {}
fn test<T: Trait>() {
const { needs_trait::<T::Assoc>() };
}
fn main() {}