2018-08-30 07:18:55 -05:00
|
|
|
// run-pass
|
2018-09-25 16:51:35 -05:00
|
|
|
#![allow(unused_variables)]
|
2013-09-02 08:33:17 -05:00
|
|
|
/*
|
2014-01-07 20:49:13 -06:00
|
|
|
# ICE when returning struct with reference to trait
|
2013-09-02 08:33:17 -05:00
|
|
|
|
2014-01-07 20:49:13 -06:00
|
|
|
A function which takes a reference to a trait and returns a
|
|
|
|
struct with that reference results in an ICE.
|
2013-09-02 08:33:17 -05:00
|
|
|
|
2014-01-07 20:49:13 -06:00
|
|
|
This does not occur with concrete types, only with references
|
2013-09-02 08:33:17 -05:00
|
|
|
to traits.
|
|
|
|
*/
|
|
|
|
|
2014-03-05 17:28:08 -06:00
|
|
|
|
2013-09-02 08:33:17 -05:00
|
|
|
// original
|
|
|
|
trait Inner {
|
|
|
|
fn print(&self);
|
|
|
|
}
|
|
|
|
|
2015-03-25 19:06:52 -05:00
|
|
|
impl Inner for isize {
|
2014-01-09 04:06:55 -06:00
|
|
|
fn print(&self) { print!("Inner: {}\n", *self); }
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
struct Outer<'a> {
|
2019-05-28 13:47:21 -05:00
|
|
|
inner: &'a (dyn Inner+'a)
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a> Outer<'a> {
|
2019-05-28 13:47:21 -05:00
|
|
|
fn new(inner: &dyn Inner) -> Outer {
|
2013-09-02 08:33:17 -05:00
|
|
|
Outer {
|
|
|
|
inner: inner
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-09-25 02:43:37 -05:00
|
|
|
pub fn main() {
|
2015-03-25 19:06:52 -05:00
|
|
|
let inner: isize = 5;
|
2019-05-28 13:47:21 -05:00
|
|
|
let outer = Outer::new(&inner as &dyn Inner);
|
2013-09-02 08:33:17 -05:00
|
|
|
outer.inner.print();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// minimal
|
2015-02-12 09:29:52 -06:00
|
|
|
pub trait MyTrait<T> {
|
|
|
|
fn dummy(&self, t: T) -> T { panic!() }
|
|
|
|
}
|
2013-09-02 08:33:17 -05:00
|
|
|
|
2015-08-07 12:23:11 -05:00
|
|
|
pub struct MyContainer<'a, T:'a> {
|
2019-05-28 13:47:21 -05:00
|
|
|
foos: Vec<&'a (dyn MyTrait<T>+'a)> ,
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a, T> MyContainer<'a, T> {
|
2019-05-28 13:47:21 -05:00
|
|
|
pub fn add (&mut self, foo: &'a dyn MyTrait<T>) {
|
2013-09-02 08:33:17 -05:00
|
|
|
self.foos.push(foo);
|
|
|
|
}
|
|
|
|
}
|