Skip to content

Commit 7f34b61

Browse files
committed
Add test for the bug I just caused
1 parent 372912b commit 7f34b61

File tree

1 file changed

+54
-0
lines changed

1 file changed

+54
-0
lines changed
Lines changed: 54 additions & 0 deletions
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 closure that is threaded
3+
// 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() {}

0 commit comments

Comments
 (0)