fn foo() -> Box<Reader + 'static> {
let v = [1, 2, 3];
box std::io::BufReader::new(v)
}
fn main() {
let mut foo = foo();
println!("{}", foo.read_to_end());
}
This should not compile, since v is &'a [u8] for some non-'static 'a and thus BufReader<'a> will contain &'a [u8] as well. It compiles fine however and results in the varying output depending on the optimization level (which shows that this is an UB out of the "safe" code).
Tested with rustc 0.13.0-nightly (1c3ddd297 2014-10-13 23:27:46 +0000) and playpen.