Skip to content

Commit 3d754f6

Browse files
committed
Test reproducing the bug we had
1 parent a0193a4 commit 3d754f6

File tree

2 files changed

+57
-0
lines changed

2 files changed

+57
-0
lines changed
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Test that the preprocessing step correctly handles some
2+
// cases of placeholder leaks.
3+
//
4+
//@ compile-flags:-Zno-leak-check
5+
6+
7+
struct Co<'a>(&'a ());
8+
struct Inv<'a>(*mut &'a ());
9+
struct Contra<'a>(fn(&'a ()));
10+
11+
// `exists<'e> forall<'p> 'p: 'e` -> ERROR
12+
fn p_outlives_e(
13+
x: for<'e> fn(for<'p> fn(fn(fn(Contra<'e>, Co<'p>)))),
14+
) -> fn(fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
15+
x //~ ERROR mismatched types [E0308]
16+
}
17+
18+
// `exists<'e> forall<'p> 'e: 'p` -> Ok, 'e: 'static
19+
fn e_outlives_p_static(
20+
x: for<'e> fn(Inv<'e>, for<'p> fn(fn(fn(Contra<'p>, Co<'e>)))),
21+
) -> fn(Inv<'static>, fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
22+
x
23+
}
24+
25+
// `exists<'e> forall<'p> 'e: 'p` -> Ok, 'e: 'static -> ERROR
26+
fn e_outlives_p_static_err<'not_static>(
27+
x: for<'e> fn(Inv<'e>, for<'p> fn(fn(fn(Contra<'p>, Co<'e>)))),
28+
) -> fn(Inv<'not_static>, fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
29+
x //~ ERROR lifetime may not live long enough
30+
}
31+
32+
fn main() {}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/placeholder-outlives-existential.rs:15:5
3+
|
4+
LL | x
5+
| ^ one type is more general than the other
6+
|
7+
= note: expected fn pointer `fn(fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>))))`
8+
found fn pointer `for<'e> fn(for<'e, 'p> fn(for<'e, 'p> fn(for<'e, 'p> fn(Contra<'e>, Co<'p>))))`
9+
10+
error: lifetime may not live long enough
11+
--> $DIR/placeholder-outlives-existential.rs:29:5
12+
|
13+
LL | fn e_outlives_p_static_err<'not_static>(
14+
| ----------- lifetime `'not_static` defined here
15+
...
16+
LL | x
17+
| ^ returning this value requires that `'not_static` must outlive `'static`
18+
|
19+
= note: requirement occurs because of the type `Inv<'_>`, which makes the generic argument `'_` invariant
20+
= note: the struct `Inv<'a>` is invariant over the parameter `'a`
21+
= help: see <https://doc.rust-lang.org/nomicon/subtyping.html> for more information about variance
22+
23+
error: aborting due to 2 previous errors
24+
25+
For more information about this error, try `rustc --explain E0308`.

0 commit comments

Comments
 (0)