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

On borrow return type, suggest borrowing from arg or owned return type #117914

Merged
merged 9 commits into from
Dec 12, 2023

Commits on Nov 20, 2023

  1. On borrow return type, suggest borrowing from arg or owned return type

    When we encounter a function with a return type that has an anonymous
    lifetime with no argument to borrow from, besides suggesting the
    `'static` lifetime we now also suggest changing the arguments to be
    borrows or changing the return type to be an owned type.
    
    ```
    error[E0106]: missing lifetime specifier
      --> $DIR/variadic-ffi-6.rs:7:6
       |
    LL | ) -> &usize {
       |      ^ expected named lifetime parameter
       |
       = help: this function's return type contains a borrowed value, but there is no value for it to be borrowed from
    help: consider using the `'static` lifetime, but this is uncommon unless you're returning a borrowed value from a `const` or a `static`
       |
    LL | ) -> &'static usize {
       |       +++++++
    help: instead, you are more likely to want to change one of the arguments to be borrowed...
       |
    LL |     x: &usize,
       |        +
    help: ...or alternatively, to want to return an owned value
       |
    LL - ) -> &usize {
    LL + ) -> usize {
       |
    ```
    
    Fix rust-lang#85843.
    estebank committed Nov 20, 2023
    Configuration menu
    Copy the full SHA
    b7a23bc View commit details
    Browse the repository at this point in the history
  2. Account for impl Trait in lifetime suggestion

    When encountering
    ```rust
    fn g(mut x: impl Iterator<Item = &()>) -> Option<&()> { /* */ }
    ```
    Suggest
    ```rust
    fn g<'a>(mut x: impl Iterator<Item = &'a ()>) -> Option<&'a ()> { /* */ }
    ```
    estebank committed Nov 20, 2023
    Configuration menu
    Copy the full SHA
    5fce361 View commit details
    Browse the repository at this point in the history
  3. Tweak wording

    estebank committed Nov 20, 2023
    Configuration menu
    Copy the full SHA
    d30252e View commit details
    Browse the repository at this point in the history
  4. Configuration menu
    Copy the full SHA
    dec7f00 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    2a92d82 View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    85f26ad View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    bb9d720 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    02bea16 View commit details
    Browse the repository at this point in the history
  9. let-chain fmt

    estebank committed Nov 20, 2023
    Configuration menu
    Copy the full SHA
    eee4cc6 View commit details
    Browse the repository at this point in the history