rust-lang / nomicon

The Dark Arts of Advanced and Unsafe Rust Programming
https://doc.rust-lang.org/nomicon/
Apache License 2.0
1.79k stars 261 forks source link

Document lifetime elision for fn types, Fn*, impl #298

Closed ssbr closed 3 years ago

ssbr commented 3 years ago

Currently, the lifetime elision doc only documents function definitions, but lifetime elision is also allowed in the following other locations:

To demo this up, I made some type aliases for fn/Fn which you can pass &T as a parameter to (to follow the lifetime rules of the surrounding context), and compared what you get with that instead of using fn/Fn directly, where lifetime elision takes on the rules from fn/Fn/etc.

I also demoed up an impl header that used lifetime elision twice, although the error message in that case is broken (filed https://github.com/rust-lang/rust/issues/87763)

The demo was half for this change description, and half just to make sure I understand Rust -- in particular, I really had to reverse engineer it for impl because I wasn't sure, and it didn't seem to be documented anywhere (at least not here!)

https://play.rust-lang.org/?version=stable&mode=debug&edition=2018&gist=f82b280de4b992f225bc32121f333e96