Skip to content

Commit 5cf16d8

Browse files
authored
Rollup merge of #134105 - compiler-errors:validate-self-preds, r=wesleywiser
Validate self in host predicates correctly `assert_only_contains_predicates_from` was added to make sure that we are computing predicates for the correct self type for a given `PredicateFilter`. That was not implemented correctly for `PredicateFilter::SelfOnly` when there are const predicates. Fixes #133526
2 parents 43b4af5 + 5d1b6bf commit 5cf16d8

File tree

2 files changed

+31
-2
lines changed

2 files changed

+31
-2
lines changed

compiler/rustc_hir_analysis/src/collect/predicates_of.rs

+9-2
Original file line numberDiff line numberDiff line change
@@ -711,12 +711,19 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
711711
`{filter:?}` implied bounds: {clause:?}"
712712
);
713713
}
714+
ty::ClauseKind::HostEffect(host_effect_predicate) => {
715+
assert_eq!(
716+
host_effect_predicate.self_ty(),
717+
ty,
718+
"expected `Self` predicate when computing \
719+
`{filter:?}` implied bounds: {clause:?}"
720+
);
721+
}
714722

715723
ty::ClauseKind::RegionOutlives(_)
716724
| ty::ClauseKind::ConstArgHasType(_, _)
717725
| ty::ClauseKind::WellFormed(_)
718-
| ty::ClauseKind::ConstEvaluatable(_)
719-
| ty::ClauseKind::HostEffect(..) => {
726+
| ty::ClauseKind::ConstEvaluatable(_) => {
720727
bug!(
721728
"unexpected non-`Self` predicate when computing \
722729
`{filter:?}` implied bounds: {clause:?}"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
// Regression test for <https://github.com/rust-lang/rust/issues/133526>.
2+
3+
// Ensures we don't ICE when we encounter a `HostEffectPredicate` when computing
4+
// the "item super predicates" for `Assoc`.
5+
6+
//@ compile-flags: -Znext-solver
7+
//@ check-pass
8+
9+
#![feature(const_trait_impl)]
10+
11+
#[const_trait]
12+
trait Trait {
13+
type Assoc: const Trait;
14+
}
15+
16+
const fn needs_trait<T: ~const Trait>() {}
17+
18+
fn test<T: Trait>() {
19+
const { needs_trait::<T::Assoc>() };
20+
}
21+
22+
fn main() {}

0 commit comments

Comments
 (0)