From 257f68777f469bdd26d4763dc0cbd99c99b74e1d Mon Sep 17 00:00:00 2001 From: Michael Goulet Date: Wed, 19 Mar 2025 17:53:43 +0000 Subject: [PATCH] Use the new solver in the impossible_predicates --- .../rustc_trait_selection/src/traits/mod.rs | 14 +++---- tests/ui/traits/vtable/impossible-method.rs | 38 +++++++++++++++++++ 2 files changed, 43 insertions(+), 9 deletions(-) create mode 100644 tests/ui/traits/vtable/impossible-method.rs diff --git a/compiler/rustc_trait_selection/src/traits/mod.rs b/compiler/rustc_trait_selection/src/traits/mod.rs index 0987c5b42d881..7a744dfc2ad8d 100644 --- a/compiler/rustc_trait_selection/src/traits/mod.rs +++ b/compiler/rustc_trait_selection/src/traits/mod.rs @@ -690,8 +690,11 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>( /// used during analysis. pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec>) -> bool { debug!("impossible_predicates(predicates={:?})", predicates); - let (infcx, param_env) = - tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized()); + let (infcx, param_env) = tcx + .infer_ctxt() + .with_next_trait_solver(true) + .build_with_typing_env(ty::TypingEnv::fully_monomorphized()); + let ocx = ObligationCtxt::new(&infcx); let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates); for predicate in predicates { @@ -704,13 +707,6 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec; +} +impl Id for T { + type This<'a> = T; +} + +trait Trait {} +impl Trait fn(T::This<'a>)> for T {} + +trait Method { + fn call_me(&self) + where + T: Trait fn(T::This<'a>)>; +} + +impl Method for T { + fn call_me(&self) { + println!("method was reachable"); + } +} + +fn generic(x: &dyn Method) { + // Proving `T: Trait fn(T::This<'a>)>` holds. + x.call_me(); +} + +fn main() { + // Proving `u32: Trait` fails due to incompleteness. + // We don't add the method to the vtable of `dyn Method`, so + // calling it causes UB. + generic::(&()); +}