Skip to content

Commit 6f9041b

Browse files
committed
add the leak check to the new solver
1 parent 04056b5 commit 6f9041b

File tree

2 files changed

+29
-0
lines changed

2 files changed

+29
-0
lines changed

compiler/rustc_trait_selection/src/solve/eval_ctxt/canonical.rs

+5
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,11 @@ impl<'tcx> EvalCtxt<'_, 'tcx> {
137137

138138
#[instrument(level = "debug", skip(self), ret)]
139139
fn compute_external_query_constraints(&self) -> Result<ExternalConstraints<'tcx>, NoSolution> {
140+
self.infcx.leak_check(ty::UniverseIndex::ROOT, None).map_err(|e| {
141+
debug!(?e, "failed the leak check");
142+
NoSolution
143+
})?;
144+
140145
// Cannot use `take_registered_region_obligations` as we may compute the response
141146
// inside of a `probe` whenever we have multiple choices inside of the solver.
142147
let region_obligations = self.infcx.inner.borrow().region_obligations().to_owned();
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// run-pass
2+
// revisions: old next
3+
//[next] compile-flags: -Ztrait-solver=next
4+
#![allow(coherence_leak_check)]
5+
6+
trait Trait: Sized {
7+
fn is_higher_ranked(self) -> bool;
8+
}
9+
10+
impl Trait for for<'a> fn(&'a ()) {
11+
fn is_higher_ranked(self) -> bool {
12+
true
13+
}
14+
}
15+
impl<'a> Trait for fn(&'a ()) {
16+
fn is_higher_ranked(self) -> bool {
17+
false
18+
}
19+
}
20+
21+
fn main() {
22+
let x: for<'a> fn(&'a ()) = |&()| ();
23+
assert!(x.is_higher_ranked());
24+
}

0 commit comments

Comments
 (0)