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.
9 use std::ops::{Deref, DerefMut};
11 #[derive(Copy, Clone)]
12 pub struct Luma<T: Primitive> { pub data: [T; 1] }
14 impl<T: Primitive + 'static> Pixel for Luma<T> {
18 pub struct ImageBuffer<P: Pixel, Container> {
23 pub trait GenericImage: Sized {
27 pub trait Pixel: Copy + Clone {
28 type Subpixel: Primitive;
31 pub trait Primitive: Copy + PartialOrd<Self> + Clone {
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 {
42 impl Primitive for u8 { }
44 impl<P, Container> ImageBuffer<P, Container>
45 where P: Pixel + 'static,
47 Container: Deref<Target=[P::Subpixel]>
49 pub fn pixels<'a>(&'a self) -> Pixels<'a, Self> {
53 pub fn pixels_mut(&mut self) -> PixelsMut<P> {
58 pub struct Pixels<'a, I: 'a> {
66 impl<'a, I: GenericImage> Iterator for Pixels<'a, I> {
67 type Item = (u32, u32, I::Pixel);
69 fn next(&mut self) -> Option<(u32, u32, I::Pixel)> {
74 pub struct PixelsMut<'a, P: Pixel + 'a> where P::Subpixel: 'a {
75 chunks: &'a mut P::Subpixel
78 impl<'a, P: Pixel + 'a> Iterator for PixelsMut<'a, P> where P::Subpixel: 'a {
79 type Item = &'a mut P;
81 fn next(&mut self) -> Option<&'a mut P> {
86 pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>)
87 -> ImageBuffer<Luma<u8>, Vec<u8>>
88 where Pix: Pixel<Subpixel=u8> + 'static,
90 // When NLL-enabled, `let mut` below is deemed unnecessary (due to
91 // the remaining code being unreachable); so ignore that lint.
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.