]> git.proxmox.com Git - rustc.git/blob - src/test/run-pass/issues/issue-5708.rs
New upstream version 1.33.0+dfsg1
[rustc.git] / src / test / run-pass / issues / issue-5708.rs
1 // run-pass
2 #![allow(unused_variables)]
3 /*
4 # ICE when returning struct with reference to trait
5
6 A function which takes a reference to a trait and returns a
7 struct with that reference results in an ICE.
8
9 This does not occur with concrete types, only with references
10 to traits.
11 */
12
13
14 // original
15 trait Inner {
16 fn print(&self);
17 }
18
19 impl Inner for isize {
20 fn print(&self) { print!("Inner: {}\n", *self); }
21 }
22
23 struct Outer<'a> {
24 inner: &'a (Inner+'a)
25 }
26
27 impl<'a> Outer<'a> {
28 fn new(inner: &Inner) -> Outer {
29 Outer {
30 inner: inner
31 }
32 }
33 }
34
35 pub fn main() {
36 let inner: isize = 5;
37 let outer = Outer::new(&inner as &Inner);
38 outer.inner.print();
39 }
40
41
42 // minimal
43 pub trait MyTrait<T> {
44 fn dummy(&self, t: T) -> T { panic!() }
45 }
46
47 pub struct MyContainer<'a, T:'a> {
48 foos: Vec<&'a (MyTrait<T>+'a)> ,
49 }
50
51 impl<'a, T> MyContainer<'a, T> {
52 pub fn add (&mut self, foo: &'a MyTrait<T>) {
53 self.foos.push(foo);
54 }
55 }