]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/trait-object-generics.rs
Auto merge of #22541 - Manishearth:rollup, r=Gankro
[rust.git] / src / test / run-pass / trait-object-generics.rs
1 // Copyright 2013 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
11 // test for #8664
12
13 #![allow(unknown_features)]
14 #![feature(box_syntax)]
15
16 use std::marker;
17
18 pub trait Trait2<A> {
19     fn doit(&self) -> A;
20 }
21
22 pub struct Impl<A1, A2, A3> {
23     m1: marker::PhantomData<(A1,A2,A3)>,
24     /*
25      * With A2 we get the ICE:
26      * task <unnamed> failed at 'index out of bounds: the len is 1 but the index is 1',
27      * src/librustc/middle/subst.rs:58
28      */
29     t: Box<Trait2<A2>+'static>
30 }
31
32 impl<A1, A2, A3> Impl<A1, A2, A3> {
33     pub fn step(&self) {
34         self.t.doit();
35     }
36 }
37
38 // test for #8601
39
40 enum Type<T> { Constant(T) }
41
42 trait Trait<K,V> {
43     fn method(&self,Type<(K,V)>) -> int;
44 }
45
46 impl<V> Trait<u8,V> for () {
47     fn method(&self, _x: Type<(u8,V)>) -> int { 0 }
48 }
49
50 pub fn main() {
51     let a = box() () as Box<Trait<u8, u8>>;
52     assert_eq!(a.method(Type::Constant((1u8, 2u8))), 0);
53 }