1 // run-pass
2
3 #![allow(dead_code)]
4 #![allow(unused_variables)]
5 #![allow(unreachable_code)]
6 // A regression test extracted from image-0.3.11. The point of
7 // failure was in `index_colors` below.
8
9 use std::ops::{Deref, DerefMut};
10
11 #[derive(Copy, Clone)]
12 pub struct Luma<T: Primitive> { pub data: [T; 1] }
13
14 impl<T: Primitive + 'static> Pixel for Luma<T> {
15 type Subpixel = T;
16 }
17
18 pub struct ImageBuffer<P: Pixel, Container> {
19 pixels: P,
20 c: Container,
21 }
22
23 pub trait GenericImage: Sized {
24 type Pixel: Pixel;
25 }
26
27 pub trait Pixel: Copy + Clone {
28 type Subpixel: Primitive;
29 }
30
31 pub trait Primitive: Copy + PartialOrd<Self> + Clone {
32 }
33
34 impl<P, Container> GenericImage for ImageBuffer<P, Container>
35 where P: Pixel + 'static,
36 Container: Deref<Target=[P::Subpixel]> + DerefMut,
37 P::Subpixel: 'static {
38
39 type Pixel = P;
40 }
41
42 impl Primitive for u8 { }
43
44 impl<P, Container> ImageBuffer<P, Container>
45 where P: Pixel + 'static,
46 P::Subpixel: 'static,
47 Container: Deref<Target=[P::Subpixel]>
48 {
pixels<'a>(&'a self) -> Pixels<'a, Self>49 pub fn pixels<'a>(&'a self) -> Pixels<'a, Self> {
50 loop { }
51 }
52
pixels_mut(&mut self) -> PixelsMut<P>53 pub fn pixels_mut(&mut self) -> PixelsMut<P> {
54 loop { }
55 }
56 }
57
58 pub struct Pixels<'a, I: 'a> {
59 image: &'a I,
60 x: u32,
61 y: u32,
62 width: u32,
63 height: u32
64 }
65
66 impl<'a, I: GenericImage> Iterator for Pixels<'a, I> {
67 type Item = (u32, u32, I::Pixel);
68
next(&mut self) -> Option<(u32, u32, I::Pixel)>69 fn next(&mut self) -> Option<(u32, u32, I::Pixel)> {
70 loop { }
71 }
72 }
73
74 pub struct PixelsMut<'a, P: Pixel + 'a> where P::Subpixel: 'a {
75 chunks: &'a mut P::Subpixel
76 }
77
78 impl<'a, P: Pixel + 'a> Iterator for PixelsMut<'a, P> where P::Subpixel: 'a {
79 type Item = &'a mut P;
80
next(&mut self) -> Option<&'a mut P>81 fn next(&mut self) -> Option<&'a mut P> {
82 loop { }
83 }
84 }
85
index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>) -> ImageBuffer<Luma<u8>, Vec<u8>> where Pix: Pixel<Subpixel=u8> + 'static,86 pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>)
87 -> ImageBuffer<Luma<u8>, Vec<u8>>
88 where Pix: Pixel<Subpixel=u8> + 'static,
89 {
90 // When NLL-enabled, `let mut` below is deemed unnecessary (due to
91 // the remaining code being unreachable); so ignore that lint.
92 #![allow(unused_mut)]
93
94 let mut indices: ImageBuffer<_,Vec<_>> = loop { };
95 for (pixel, idx) in image.pixels().zip(indices.pixels_mut()) {
96 // failured occurred here ^^ because we were requiring that we
97 // could project Pixel or Subpixel from `T_indices` (type of
98 // `indices`), but the type is insufficiently constrained
99 // until we reach the return below.
100 }
101 indices
102 }
103
main()104 fn main() { }
105