summaryrefslogtreecommitdiffstats
path: root/src/test/ui/issues/issue-5708.rs
blob: 6fe9943d3689f7eee49cc37446eb3ef80b61bbd2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
// run-pass
#![allow(unused_variables)]
/*
# ICE when returning struct with reference to trait

A function which takes a reference to a trait and returns a
struct with that reference results in an ICE.

This does not occur with concrete types, only with references
to traits.
*/


// original
trait Inner {
    fn print(&self);
}

impl Inner for isize {
    fn print(&self) { print!("Inner: {}\n", *self); }
}

struct Outer<'a> {
    inner: &'a (dyn Inner+'a)
}

impl<'a> Outer<'a> {
    fn new(inner: &dyn Inner) -> Outer {
        Outer {
            inner: inner
        }
    }
}

pub fn main() {
    let inner: isize = 5;
    let outer = Outer::new(&inner as &dyn Inner);
    outer.inner.print();
}


// minimal
pub trait MyTrait<T> {
    fn dummy(&self, t: T) -> T { panic!() }
}

pub struct MyContainer<'a, T:'a> {
    foos: Vec<&'a (dyn MyTrait<T>+'a)> ,
}

impl<'a, T> MyContainer<'a, T> {
    pub fn add (&mut self, foo: &'a dyn MyTrait<T>) {
        self.foos.push(foo);
    }
}