Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 1 commit into from
Aug 4, 2021

Commits on Aug 4, 2021

  1. Document lifetime elision for fn types, Fn*, impl

    Currently, the lifetime elision doc only documents function definitions, but lifetime elision is also allowed in the following other locations:
    
    * `fn` types, such as `fn(&T)`
    * `Fn`/`FnMut`/`FnOnce`, such as `Fn(&T)`
    * `impl` headers
    
    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 rust-lang/rust#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
    ssbr committed Aug 4, 2021
    Configuration menu
    Copy the full SHA
    3abf036 View commit details
    Browse the repository at this point in the history