2013-09-02 13:33:17 +00: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-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);
|
|
|
|
}
|
|
|
|
|
|
|
|
impl Inner for int {
|
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> {
|
2014-11-20 20:08:02 +00:00
|
|
|
inner: &'a (Inner+'a)
|
2013-09-02 13:33:17 +00:00
|
|
|
}
|
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
impl<'a> Outer<'a> {
|
2014-07-18 04:44:59 +00:00
|
|
|
fn new(inner: &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-01-25 21:05:03 +00:00
|
|
|
let inner = 5;
|
2013-09-02 13:33:17 +00:00
|
|
|
let outer = Outer::new(&inner as &Inner);
|
|
|
|
outer.inner.print();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// minimal
|
2014-09-19 19:30:07 +00:00
|
|
|
pub trait MyTrait<T> { }
|
2013-09-02 13:33:17 +00:00
|
|
|
|
2013-12-10 07:16:18 +00:00
|
|
|
pub struct MyContainer<'a, T> {
|
2014-11-20 20:08:02 +00:00
|
|
|
foos: Vec<&'a (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> {
|
|
|
|
pub fn add (&mut self, foo: &'a MyTrait<T>) {
|
2013-09-02 13:33:17 +00:00
|
|
|
self.foos.push(foo);
|
|
|
|
}
|
|
|
|
}
|