Why not automatic inference of 'static in foo() -> &str?

Another related thread (Why are lifetime explicit? - #7 by Yandros) just linked to Bugs You'll Probably Only Have In Rust - Faultlore which has another good example.

It's helpful that this code doesn't compile:

fn foo(input: *const u32) -> &u32 {
    unsafe {
        return &*input
    }
}

Because -> &'static u32 is almost certainly wrong, so allowing it to elide to that would be unfortunate.

3 Likes