Closed
Description
Best I can do, but it's self-contained:
trait FooTrait {
fn do_thing(&self) -> ~str;
}
struct Container<'a> {
things : ~[&'a FooTrait]
}
impl<'a> Container<'a> {
fn new() -> Container {
Container { things: ~[] }
}
fn add(&mut self, thing: &'a FooTrait) {
self.things.push(thing);
}
}
struct Foo;
impl FooTrait for Foo {
fn do_thing(&self) -> ~str {
~"Test"
}
}
fn make_foo() -> Foo {
Foo
}
fn main() {
let mut c = Container::new();
for _ in range(0, 10) {
let foo : Foo = make_foo();
let foop : &Foo = &foo;
let foo_obj = foop as &FooTrait;
c.add(foo_obj);
}
}
This compiles. It shouldn't, since foo
doesn't live for long enough. If I don't do the cast (this also happens with coercion), it fails with the expected error message.