From 5d1b6bfc6ad95298fe3637857976945bd6ae9d9d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Tue, 10 Dec 2024 02:28:02 +0000 Subject: [PATCH] Validate self in host predicates correctly --- .../src/collect/predicates_of.rs | 11 ++++++++-- .../dont-ice-on-const-pred-for-bounds.rs | 22 +++++++++++++++++++ 2 files changed, 31 insertions(+), 2 deletions(-) create mode 100644 tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs diff --git a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs index ca2597e79fd14..1a6c0a934360c 100644 --- a/compiler/rustc_hir_analysis/src/collect/predicates_of.rs +++ b/compiler/rustc_hir_analysis/src/collect/predicates_of.rs @@ -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:?}" diff --git a/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs b/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs new file mode 100644 index 0000000000000..2295c2c3857c7 --- /dev/null +++ b/tests/ui/traits/const-traits/dont-ice-on-const-pred-for-bounds.rs @@ -0,0 +1,22 @@ +// Regression test for . + +// 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() {} + +fn test() { + const { needs_trait::() }; +} + +fn main() {}