Why Rust Lifetime Elision cannot inference the proper lifetime annotations on functions?

The signature of your function is your contract with not only the compiler, but also users of your function. Users need to know the contract. It would also be too easy to accidentally make a backwards-incompatible change if the signature was inferred from the body. Additionally, using the signature as the contract allows the compiler to borrow check callers of your function without evaluating the body.

(Edit: corrected auto-correct)

10 Likes