Skip to content

Commit 6bc57c6

Browse files
committed
Auto merge of #139960 - amandasystems:placeholder-ui-tests, r=lcnr
Add tests for two untested cases of placeholder relations During work on #130227, I discovered several situations not covered by any previously existing UI test. This commit introudces tests to cover that. r? lcnr
2 parents 8bf5a8d + e9d374c commit 6bc57c6

File tree

3 files changed

+110
-0
lines changed

3 files changed

+110
-0
lines changed

Diff for: tests/ui/borrowck/static-trait-bound-lost.rs

+54
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
// This test is a reduced version of a bug introduced during work on type-tests for Polonius.
2+
// The underlying problem is that the 'static bound is lost for a type parameter that is
3+
// threaded deeply enough, causing an error.
4+
// The bug was first observed in exr-1.4.1/src/image/read/mod.rs:124:5 during perf test.
5+
6+
//@ check-pass
7+
8+
use std::marker::PhantomData;
9+
10+
struct ReadAllLayers<ReadChannels> {
11+
px: PhantomData<ReadChannels>,
12+
}
13+
14+
trait ReadLayers<'s> {}
15+
16+
impl<'s, C> ReadLayers<'s> for ReadAllLayers<C> where C: ReadChannels<'s> {}
17+
18+
fn make_builder<A, Set, Pixels>(
19+
_: Set,
20+
) -> ReadAllLayers<CollectPixels<A, Pixels, Set>>
21+
where
22+
Set: Fn(&mut Pixels),
23+
{
24+
todo!()
25+
}
26+
27+
struct CollectPixels<Pixel, PixelStorage, SetPixel> {
28+
px: PhantomData<(SetPixel, Pixel, PixelStorage)>,
29+
}
30+
31+
impl<'s, PixelStorage, SetPixel: 's> ReadChannels<'s>
32+
for CollectPixels<usize, PixelStorage, SetPixel>
33+
where
34+
SetPixel: Fn(&mut PixelStorage),
35+
{
36+
}
37+
38+
trait ReadChannels<'s> {}
39+
40+
fn from_file<L>(_: L)
41+
where
42+
for<'s> L: ReadLayers<'s>,
43+
{
44+
}
45+
46+
pub fn read_all_rgba_layers_from_file<Set: 'static, Pixels: 'static>(
47+
set_pixel: Set,
48+
) where
49+
Set: Fn(&mut Pixels),
50+
{
51+
from_file(make_builder(set_pixel)); // Error triggered.
52+
}
53+
54+
pub fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Test that we correctly handle some cases of placeholder leaks.
2+
//
3+
//@ compile-flags:-Zno-leak-check
4+
5+
6+
struct Co<'a>(&'a ());
7+
struct Inv<'a>(*mut &'a ());
8+
struct Contra<'a>(fn(&'a ()));
9+
10+
// `exists<'e> forall<'p> 'p: 'e` -> ERROR
11+
fn p_outlives_e(
12+
x: for<'e> fn(for<'p> fn(fn(fn(Contra<'e>, Co<'p>)))),
13+
) -> fn(fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
14+
x //~ ERROR mismatched types [E0308]
15+
}
16+
17+
// `exists<'e> forall<'p> 'e: 'p` -> Ok, 'e: 'static
18+
fn e_outlives_p_static(
19+
x: for<'e> fn(Inv<'e>, for<'p> fn(fn(fn(Contra<'p>, Co<'e>)))),
20+
) -> fn(Inv<'static>, fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
21+
x
22+
}
23+
24+
// `exists<'e> forall<'p> 'e: 'p` -> Ok, 'e: 'static -> ERROR
25+
fn e_outlives_p_static_err<'not_static>(
26+
x: for<'e> fn(Inv<'e>, for<'p> fn(fn(fn(Contra<'p>, Co<'e>)))),
27+
) -> fn(Inv<'not_static>, fn(fn(for<'unify> fn(Contra<'unify>, Co<'unify>)))) {
28+
x //~ ERROR lifetime may not live long enough
29+
}
30+
31+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
error[E0308]: mismatched types
2+
--> $DIR/placeholder-outlives-existential.rs:14: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:28: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)