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