about summary refs log tree commit diff
path: root/tests/ui/borrowck/static-trait-bound-lost.rs
blob: 0288acea0f60465dc2faef942dc32cc8f782df35 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
// This test is a reduced version of a bug introduced during work on type-tests for Polonius.
// The underlying problem is that the 'static bound is lost for a type parameter that is
// threaded deeply enough, causing an error.
// The bug was first observed in exr-1.4.1/src/image/read/mod.rs:124:5 during perf test.

//@ check-pass

use std::marker::PhantomData;

struct ReadAllLayers<ReadChannels> {
    px: PhantomData<ReadChannels>,
}

trait ReadLayers<'s> {}

impl<'s, C> ReadLayers<'s> for ReadAllLayers<C> where C: ReadChannels<'s> {}

fn make_builder<A, Set, Pixels>(
    _: Set,
) -> ReadAllLayers<CollectPixels<A, Pixels, Set>>
where
    Set: Fn(&mut Pixels),
{
    todo!()
}

struct CollectPixels<Pixel, PixelStorage, SetPixel> {
    px: PhantomData<(SetPixel, Pixel, PixelStorage)>,
}

impl<'s, PixelStorage, SetPixel: 's> ReadChannels<'s>
    for CollectPixels<usize, PixelStorage, SetPixel>
where
    SetPixel: Fn(&mut PixelStorage),
{
}

trait ReadChannels<'s> {}

fn from_file<L>(_: L)
where
    for<'s> L: ReadLayers<'s>,
{
}

pub fn read_all_rgba_layers_from_file<Set: 'static, Pixels: 'static>(
    set_pixel: Set,
) where
    Set: Fn(&mut Pixels),
{
    from_file(make_builder(set_pixel)); // Error triggered.
}

pub fn main() {}