Skip to content

Commit 257f687

Browse files
Use the new solver in the impossible_predicates
1 parent be181dd commit 257f687

File tree

2 files changed

+43
-9
lines changed

2 files changed

+43
-9
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

+5-9
Original file line numberDiff line numberDiff line change
@@ -690,8 +690,11 @@ fn replace_param_and_infer_args_with_placeholder<'tcx>(
690690
/// used during analysis.
691691
pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause<'tcx>>) -> bool {
692692
debug!("impossible_predicates(predicates={:?})", predicates);
693-
let (infcx, param_env) =
694-
tcx.infer_ctxt().build_with_typing_env(ty::TypingEnv::fully_monomorphized());
693+
let (infcx, param_env) = tcx
694+
.infer_ctxt()
695+
.with_next_trait_solver(true)
696+
.build_with_typing_env(ty::TypingEnv::fully_monomorphized());
697+
695698
let ocx = ObligationCtxt::new(&infcx);
696699
let predicates = ocx.normalize(&ObligationCause::dummy(), param_env, predicates);
697700
for predicate in predicates {
@@ -704,13 +707,6 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
704707
return true;
705708
}
706709

707-
// Leak check for any higher-ranked trait mismatches.
708-
// We only need to do this in the old solver, since the new solver already
709-
// leak-checks.
710-
if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
711-
return true;
712-
}
713-
714710
false
715711
}
716712

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
//@ run-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
trait Id {
7+
type This<'a>;
8+
}
9+
impl<T> Id for T {
10+
type This<'a> = T;
11+
}
12+
13+
trait Trait<T> {}
14+
impl<T: Id> Trait<for<'a> fn(T::This<'a>)> for T {}
15+
16+
trait Method<T: Id> {
17+
fn call_me(&self)
18+
where
19+
T: Trait<for<'a> fn(T::This<'a>)>;
20+
}
21+
22+
impl<T, U> Method<U> for T {
23+
fn call_me(&self) {
24+
println!("method was reachable");
25+
}
26+
}
27+
28+
fn generic<T: Id>(x: &dyn Method<T>) {
29+
// Proving `T: Trait<for<'a> fn(T::This<'a>)>` holds.
30+
x.call_me();
31+
}
32+
33+
fn main() {
34+
// Proving `u32: Trait<fn(u32)>` fails due to incompleteness.
35+
// We don't add the method to the vtable of `dyn Method`, so
36+
// calling it causes UB.
37+
generic::<u32>(&());
38+
}

0 commit comments

Comments
 (0)