You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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).
Minimal example:
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).
Possibly related: #12781, #14868 and others.
The text was updated successfully, but these errors were encountered: