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

Provide suggestion to dereference closure tail if appropriate #122213

Merged
merged 2 commits into from
Apr 11, 2024

Commits on Apr 5, 2024

  1. Provide suggestion to dereference closure tail if appropriate

    When encoutnering a case like
    
    ```rust
    //@ run-rustfix
    use std::collections::HashMap;
    
    fn main() {
        let vs = vec![0, 0, 1, 1, 3, 4, 5, 6, 3, 3, 3];
    
        let mut counts = HashMap::new();
        for num in vs {
            let count = counts.entry(num).or_insert(0);
            *count += 1;
        }
    
        let _ = counts.iter().max_by_key(|(_, v)| v);
    ```
    produce the following suggestion
    ```
    error: lifetime may not live long enough
      --> $DIR/return-value-lifetime-error.rs:13:47
       |
    LL |     let _ = counts.iter().max_by_key(|(_, v)| v);
       |                                       ------- ^ returning this value requires that `'1` must outlive `'2`
       |                                       |     |
       |                                       |     return type of closure is &'2 &i32
       |                                       has type `&'1 (&i32, &i32)`
       |
    help: dereference the return value
       |
    LL |     let _ = counts.iter().max_by_key(|(_, v)| **v);
       |                                               ++
    ```
    
    Fix rust-lang#50195.
    estebank committed Apr 5, 2024
    Configuration menu
    Copy the full SHA
    9de6b70 View commit details
    Browse the repository at this point in the history

Commits on Apr 10, 2024

  1. Configuration menu
    Copy the full SHA
    f2465f8 View commit details
    Browse the repository at this point in the history