]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-5708.rs
cleanup: s/impl Copy/#[derive(Copy)]/g
[rust.git] / src / test / run-pass / issue-5708.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 /*
12 # ICE when returning struct with reference to trait
13
14 A function which takes a reference to a trait and returns a
15 struct with that reference results in an ICE.
16
17 This does not occur with concrete types, only with references
18 to traits.
19 */
20
21
22 // original
23 trait Inner {
24     fn print(&self);
25 }
26
27 impl Inner for int {
28     fn print(&self) { print!("Inner: {}\n", *self); }
29 }
30
31 struct Outer<'a> {
32     inner: &'a (Inner+'a)
33 }
34
35 impl<'a> Outer<'a> {
36     fn new(inner: &Inner) -> Outer {
37         Outer {
38             inner: inner
39         }
40     }
41 }
42
43 pub fn main() {
44     let inner = 5i;
45     let outer = Outer::new(&inner as &Inner);
46     outer.inner.print();
47 }
48
49
50 // minimal
51 pub trait MyTrait<T> { }
52
53 pub struct MyContainer<'a, T> {
54     foos: Vec<&'a (MyTrait<T>+'a)> ,
55 }
56
57 impl<'a, T> MyContainer<'a, T> {
58     pub fn add (&mut self, foo: &'a MyTrait<T>) {
59         self.foos.push(foo);
60     }
61 }