rust/tests/ui/issues/issue-5708.rs

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

56 lines
990 B
Rust
Raw Normal View History

// run-pass
#![allow(unused_variables)]
/*
2014-01-08 02:49:13 +00:00
# ICE when returning struct with reference to trait
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.
2014-01-08 02:49:13 +00:00
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> {
2019-05-28 18:47:21 +00:00
inner: &'a (dyn Inner+'a)
}
impl<'a> Outer<'a> {
2019-05-28 18:47:21 +00:00
fn new(inner: &dyn Inner) -> Outer {
Outer {
inner: inner
}
}
}
pub fn main() {
let inner: isize = 5;
2019-05-28 18:47:21 +00:00
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> {
2019-05-28 18:47:21 +00:00
foos: Vec<&'a (dyn MyTrait<T>+'a)> ,
}
impl<'a, T> MyContainer<'a, T> {
2019-05-28 18:47:21 +00:00
pub fn add (&mut self, foo: &'a dyn MyTrait<T>) {
self.foos.push(foo);
}
}