]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/project-defer-unification.rs
New upstream version 1.31.0~beta.4+dfsg1
[rustc.git] / src / test / run-pass / project-defer-unification.rs
CommitLineData
e9174d1e
SL
1// Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2// file at the top-level directory of this distribution and at
3// http://rust-lang.org/COPYRIGHT.
4//
5// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8// option. This file may not be copied, modified, or distributed
9// except according to those terms.
10
0bf4aa26
XL
11#![allow(dead_code)]
12#![allow(unused_variables)]
13#![allow(unreachable_code)]
e9174d1e
SL
14// A regression test extracted from image-0.3.11. The point of
15// failure was in `index_colors` below.
16
17use std::ops::{Deref, DerefMut};
18
19#[derive(Copy, Clone)]
20pub struct Luma<T: Primitive> { pub data: [T; 1] }
21
22impl<T: Primitive + 'static> Pixel for Luma<T> {
23 type Subpixel = T;
24}
25
26pub struct ImageBuffer<P: Pixel, Container> {
27 pixels: P,
28 c: Container,
29}
30
31pub trait GenericImage: Sized {
32 type Pixel: Pixel;
33}
34
35pub trait Pixel: Copy + Clone {
36 type Subpixel: Primitive;
37}
38
39pub trait Primitive: Copy + PartialOrd<Self> + Clone {
40}
41
42impl<P, Container> GenericImage for ImageBuffer<P, Container>
43where P: Pixel + 'static,
44 Container: Deref<Target=[P::Subpixel]> + DerefMut,
45 P::Subpixel: 'static {
46
47 type Pixel = P;
48}
49
50impl Primitive for u8 { }
51
52impl<P, Container> ImageBuffer<P, Container>
53where P: Pixel + 'static,
54 P::Subpixel: 'static,
55 Container: Deref<Target=[P::Subpixel]>
56{
57 pub fn pixels<'a>(&'a self) -> Pixels<'a, Self> {
58 loop { }
59 }
60
61 pub fn pixels_mut(&mut self) -> PixelsMut<P> {
62 loop { }
63 }
64}
65
66pub struct Pixels<'a, I: 'a> {
67 image: &'a I,
68 x: u32,
69 y: u32,
70 width: u32,
71 height: u32
72}
73
74impl<'a, I: GenericImage> Iterator for Pixels<'a, I> {
75 type Item = (u32, u32, I::Pixel);
76
77 fn next(&mut self) -> Option<(u32, u32, I::Pixel)> {
78 loop { }
79 }
80}
81
82pub struct PixelsMut<'a, P: Pixel + 'a> where P::Subpixel: 'a {
83 chunks: &'a mut P::Subpixel
84}
85
86impl<'a, P: Pixel + 'a> Iterator for PixelsMut<'a, P> where P::Subpixel: 'a {
87 type Item = &'a mut P;
88
89 fn next(&mut self) -> Option<&'a mut P> {
90 loop { }
91 }
92}
93
94pub fn index_colors<Pix>(image: &ImageBuffer<Pix, Vec<u8>>)
95 -> ImageBuffer<Luma<u8>, Vec<u8>>
96where Pix: Pixel<Subpixel=u8> + 'static,
97{
0bf4aa26
XL
98 // When NLL-enabled, `let mut` below is deemed unnecessary (due to
99 // the remaining code being unreachable); so ignore that lint.
100 #![allow(unused_mut)]
101
e9174d1e
SL
102 let mut indices: ImageBuffer<_,Vec<_>> = loop { };
103 for (pixel, idx) in image.pixels().zip(indices.pixels_mut()) {
104 // failured occurred here ^^ because we were requiring that we
105 // could project Pixel or Subpixel from `T_indices` (type of
106 // `indices`), but the type is insufficiently constrained
107 // until we reach the return below.
108 }
109 indices
110}
111
112fn main() { }