Closed
Description
let x: || -> &str = || "hello"; // fine
fn x() -> &str { "hello" } // error
This is a result of lifetime elision not existing for closures. (Should it?) This was the only backwards-incompatible part of lifetime elision, and so for backwards-compatibility lifetime annotations should be required for closure types as well, in case lifetime elision is ever added to closures. Also, it’d be more consistent with normal functions.
This applies to return type annotations in closure expressions, too: let x = || -> &str "hello"
also compiles without an explicit lifetime annotation.
Metadata
Metadata
Assignees
Labels
No labels