2013-09-02 08:33:17 -05:00
|
|
|
// Copyright 2013 The Rust Project Developers. See the COPYRIGHT
|
|
|
|
// file at the top-level directory of this distribution and at
|
|
|
|
// http://rust-lang.org/COPYRIGHT.
|
|
|
|
//
|
|
|
|
// Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
|
|
|
|
// http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
|
|
|
|
// <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
|
|
|
|
// option. This file may not be copied, modified, or distributed
|
|
|
|
// except according to those terms.
|
|
|
|
|
|
|
|
/*
|
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);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Inner for int {
|
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> {
|
2014-11-20 14:08:02 -06:00
|
|
|
inner: &'a (Inner+'a)
|
2013-09-02 08:33:17 -05:00
|
|
|
}
|
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
impl<'a> Outer<'a> {
|
2014-07-17 23:44:59 -05:00
|
|
|
fn new(inner: &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-01-25 15:05:03 -06:00
|
|
|
let inner = 5;
|
2013-09-02 08:33:17 -05:00
|
|
|
let outer = Outer::new(&inner as &Inner);
|
|
|
|
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
|
|
|
|
2013-12-10 01:16:18 -06:00
|
|
|
pub struct MyContainer<'a, T> {
|
2014-11-20 14:08:02 -06:00
|
|
|
foos: Vec<&'a (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> {
|
|
|
|
pub fn add (&mut self, foo: &'a MyTrait<T>) {
|
2013-09-02 08:33:17 -05:00
|
|
|
self.foos.push(foo);
|
|
|
|
}
|
|
|
|
}
|