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

Account for missing lifetime in opaque and trait object return types #72543

Merged
merged 10 commits into from
May 31, 2020

Commits on May 30, 2020

  1. Account for missing lifetime in opaque return type

    When encountering an opaque closure return type that needs to bound a
    lifetime to the function's arguments, including borrows and type params,
    provide appropriate suggestions that lead to working code.
    
    Get the user from
    
    ```rust
    fn foo<G, T>(g: G, dest: &mut T) -> impl FnOnce()
    where
        G: Get<T>
    {
        move || {
            *dest = g.get();
        }
    }
    ```
    
    to
    
    ```rust
    fn foo<'a, G: 'a, T>(g: G, dest: &'a mut T) -> impl FnOnce() +'a
    where
        G: Get<T>
    {
        move || {
            *dest = g.get();
        }
    }
    ```
    estebank committed May 30, 2020
    Configuration menu
    Copy the full SHA
    f49ebbb View commit details
    Browse the repository at this point in the history
  2. Improve output of argument anonymous borrow missing annotation involv…

    …ing opaque return type
    
    Go from
    
    ```
    error[E0495]: cannot infer an appropriate lifetime due to conflicting requirements
      --> file8.rs:22:5
       |
    22 | /     move || {
    23 | |         *dest = g.get();
    24 | |     }
       | |_____^
       |
    note: first, the lifetime cannot outlive the anonymous lifetime rust-lang#1 defined on the function body at 18:1...
      --> file8.rs:18:1
       |
    18 | / fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
    19 | | where
    20 | |     G: Get<T>
    21 | | {
    ...  |
    24 | |     }
    25 | | }
       | |_^
    note: ...so that the types are compatible
      --> file8.rs:22:5
       |
    22 | /     move || { //~ ERROR cannot infer an appropriate lifetime
    23 | |         *dest = g.get();
    24 | |     }
       | |_____^
       = note: expected  `&mut T`
                  found  `&mut T`
    note: but, the lifetime must be valid for the lifetime `'a` as defined on the function body at 18:8...
      --> file8.rs:18:8
       |
    18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
       |        ^^
    note: ...so that return value is valid for the call
      --> file8.rs:18:45
       |
    18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
       |                                             ^^^^^^^^^^^^^^^^^^^^^^^
    ```
    
    to
    
    ```
    error[E0621]: explicit lifetime required in the type of `dest`
      --> file8.rs:18:45
       |
    18 | fn bat<'a, G: 'a, T>(g: G, dest: &mut T) -> impl FnOnce() + '_ + 'a
       |                                  ------     ^^^^^^^^^^^^^^^^^^^^^^^ lifetime `'a` required
       |                                  |
       |                                  help: add explicit lifetime `'a` to the type of `dest`: `&'a mut T`
       ```
    estebank committed May 30, 2020
    Configuration menu
    Copy the full SHA
    99d9ccd View commit details
    Browse the repository at this point in the history
  3. Fix NLL output

    estebank committed May 30, 2020
    Configuration menu
    Copy the full SHA
    a724d9a View commit details
    Browse the repository at this point in the history
  4. Account for returned dyn Trait evaluating to 'static lifetime

    Provide a suggestion for `dyn Trait + '_` when possible.
    estebank committed May 30, 2020
    Configuration menu
    Copy the full SHA
    65f492b View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    731ea85 View commit details
    Browse the repository at this point in the history
  6. Update nll tests

    estebank committed May 30, 2020
    Configuration menu
    Copy the full SHA
    1d9472b View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    8f7ee34 View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    224ad32 View commit details
    Browse the repository at this point in the history
  9. Configuration menu
    Copy the full SHA
    6dcd744 View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    83f6f22 View commit details
    Browse the repository at this point in the history