Skip to content

Commit

Permalink
Rollup merge of #134105 - compiler-errors:validate-self-preds, r=wesl…
Browse files Browse the repository at this point in the history
…eywiser

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
  • Loading branch information
jhpratt authored Dec 11, 2024
2 parents 43b4af5 + 5d1b6bf commit 5cf16d8
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 2 deletions.
11 changes: 9 additions & 2 deletions compiler/rustc_hir_analysis/src/collect/predicates_of.rs
Original file line number Diff line number Diff line change
Expand Up @@ -711,12 +711,19 @@ pub(super) fn assert_only_contains_predicates_from<'tcx>(
`{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::ConstArgHasType(_, _)
| ty::ClauseKind::WellFormed(_)
| ty::ClauseKind::ConstEvaluatable(_)
| ty::ClauseKind::HostEffect(..) => {
| ty::ClauseKind::ConstEvaluatable(_) => {
bug!(
"unexpected non-`Self` predicate when computing \
`{filter:?}` implied bounds: {clause:?}"
Expand Down
22 changes: 22 additions & 0 deletions tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs
Original file line number Diff line number Diff line change
@@ -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() {}

0 comments on commit 5cf16d8

Please sign in to comment.