]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-5708.rs
point at private fields in struct literal
[rust.git] / src / test / ui / 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 (dyn Inner+'a)
25 }
26
27 impl<'a> Outer<'a> {
28     fn new(inner: &dyn 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 &dyn 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 (dyn MyTrait<T>+'a)> ,
49 }
50
51 impl<'a, T> MyContainer<'a, T> {
52     pub fn add (&mut self, foo: &'a dyn MyTrait<T>) {
53         self.foos.push(foo);
54     }
55 }