Skip to content

Commit 1409af7

Browse files
authored
Unrolled build for rust-lang#135466
Rollup merge of rust-lang#135466 - compiler-errors:leak-check-impossible, r=lcnr Leak check in `impossible_predicates` to avoid monomorphizing impossible instances Fixes rust-lang#135462 r? lcnr
2 parents 3736b85 + 94ffced commit 1409af7

File tree

3 files changed

+91
-3
lines changed

3 files changed

+91
-3
lines changed

compiler/rustc_trait_selection/src/traits/mod.rs

+12-3
Original file line numberDiff line numberDiff line change
@@ -714,9 +714,18 @@ pub fn impossible_predicates<'tcx>(tcx: TyCtxt<'tcx>, predicates: Vec<ty::Clause
714714
}
715715
let errors = ocx.select_all_or_error();
716716

717-
let result = !errors.is_empty();
718-
debug!("impossible_predicates = {:?}", result);
719-
result
717+
if !errors.is_empty() {
718+
return true;
719+
}
720+
721+
// Leak check for any higher-ranked trait mismatches.
722+
// We only need to do this in the old solver, since the new solver already
723+
// leak-checks.
724+
if !infcx.next_trait_solver() && infcx.leak_check(ty::UniverseIndex::ROOT, None).is_err() {
725+
return true;
726+
}
727+
728+
false
720729
}
721730

722731
fn instantiate_and_check_impossible_predicates<'tcx>(
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
//@ build-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
// Regression test for #135462.
6+
#![allow(coherence_leak_check)]
7+
8+
type A = fn(&'static ());
9+
type B = fn(&());
10+
11+
trait Bound<P: WithAssoc>: From<GetAssoc<P>> {
12+
}
13+
impl Bound<B> for String {}
14+
15+
trait Trt<T> {
16+
fn __(&self, x: T) where T: Bound<A> {
17+
T::from(());
18+
}
19+
}
20+
21+
impl<T, S> Trt<T> for S {}
22+
23+
type GetAssoc<T> = <T as WithAssoc>::Ty;
24+
25+
trait WithAssoc {
26+
type Ty;
27+
}
28+
29+
impl WithAssoc for B {
30+
type Ty = String;
31+
}
32+
33+
impl WithAssoc for A {
34+
type Ty = ();
35+
}
36+
37+
fn main() {
38+
let x: &'static dyn Trt<String> = &();
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
//@ build-pass
2+
//@ revisions: current next
3+
//@ ignore-compare-mode-next-solver (explicit revisions)
4+
//@[next] compile-flags: -Znext-solver
5+
6+
trait Foo {}
7+
impl Foo for fn(&'static ()) {}
8+
9+
trait Bar {
10+
type Assoc: Default;
11+
}
12+
impl<T: Foo> Bar for T {
13+
type Assoc = usize;
14+
}
15+
impl Bar for fn(&()) {
16+
type Assoc = ();
17+
}
18+
19+
fn needs_foo<T: Foo>() -> usize {
20+
needs_bar::<T>()
21+
}
22+
23+
fn needs_bar<T: Bar>() -> <T as Bar>::Assoc {
24+
Default::default()
25+
}
26+
27+
trait Evil<T> {
28+
fn bad(&self)
29+
where
30+
T: Foo,
31+
{
32+
needs_foo::<T>();
33+
}
34+
}
35+
36+
impl Evil<fn(&())> for () {}
37+
38+
fn main() {
39+
let x: &dyn Evil<fn(&())> = &();
40+
}

0 commit comments

Comments
 (0)