2019-02-20 11:52:23 -06:00
|
|
|
// Test a case where variance and higher-ranked types interact in surprising ways.
|
2018-10-30 15:38:50 -05:00
|
|
|
//
|
|
|
|
// In particular, we test this pattern in trait solving, where it is not connected
|
|
|
|
// to any part of the source code.
|
rewrite leak check to be based on universes
In the new leak check, instead of getting a list of placeholders to
track, we look for any placeholder that is part of a universe which
was created during the snapshot.
We are looking for the following error patterns:
* P1: P2, where P1 != P2
* P1: R, where R is in some universe that cannot name P1
This new leak check is more precise than before, in that it accepts
this patterns:
* R: P1, even if R cannot name P1, because R = 'static is a valid
sol'n
* R: P1, R: P2, as above
Note that this leak check, when running during subtyping, is less
efficient than before in some sense because it is going to check and
re-check all the universes created since the snapshot. We're going to
move when the leak check runs to try and correct that.
2020-05-18 20:09:40 -05:00
|
|
|
//
|
|
|
|
// check-pass
|
2018-10-30 15:38:50 -05:00
|
|
|
|
|
|
|
trait Trait<T> {}
|
|
|
|
|
|
|
|
fn foo<T>()
|
|
|
|
where
|
|
|
|
T: Trait<for<'b> fn(fn(&'b u32))>,
|
|
|
|
{
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'a> Trait<fn(fn(&'a u32))> for () {}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
// Here, proving that `(): Trait<for<'b> fn(&'b u32)>` uses the impl:
|
|
|
|
//
|
|
|
|
// - The impl provides the clause `forall<'a> { (): Trait<fn(fn(&'a u32))> }`
|
|
|
|
// - We instantiate `'a` existentially to get `(): Trait<fn(fn(&?a u32))>`
|
|
|
|
// - We unify `fn(fn(&?a u32))` with `for<'b> fn(fn(&'b u32))` -- this does a
|
|
|
|
// "bidirectional" subtyping check, so we wind up with:
|
|
|
|
// - `fn(fn(&?a u32)) <: for<'b> fn(fn(&'b u32))` :-
|
|
|
|
// - `fn(&!b u32) <: fn(&?a u32)`
|
|
|
|
// - `&?a u32 <: &!b u32`
|
|
|
|
// - `?a: !'b` -- solveable if `?a` is inferred to `'static`
|
|
|
|
// - `for<'b> fn(fn(&'b u32)) <: fn(fn(&?a u32))` :-
|
|
|
|
// - `fn(&?a u32) <: fn(&?b u32)`
|
|
|
|
// - `&?b u32 <: &?a u32`
|
|
|
|
// - `?b: ?a` -- solveable if `?b` is inferred to `'static`
|
|
|
|
// - So the subtyping check succeeds, somewhat surprisingly.
|
|
|
|
// This is because we can use `'static`.
|
|
|
|
|
|
|
|
foo::<()>();
|
|
|
|
}
|