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