Closed
Description
Minimal example:
use std::string::String;
trait T {
fn get(&self) -> &String;
}
struct S<'a> {
data: &'a String
}
impl<'a> T for S<'a> {
fn get(&self) -> &String {
return self.data;
}
}
fn get_s() -> Box<T> {
let s = String::from_str("Hello world");
return box S{data: &s} as Box<T>;
}
fn main() {
println!("{}", get_s().get());
}
get_s() returns a struct S upcasted to T which contains a reference to local variable which gets destroyed. This compiles fine on nightly, 0.11.0 complains about conflicting lifetime requirements. Removing upcast makes nightly complain too (about missing lifetime specifier).