Skip to content

redundant_closure calls a tuple struct enum variant a function #8817

@skrapi

Description

@skrapi

Summary

Basically Clippy lint calls the tuple struct that I am using a function which is incorrect, and led to me being confused about what it wanted me to do.

Reproducer

I tried this code:

use std::collections::HashSet;
use std::collections::TryReserveError;

#[derive(Debug)]
enum MyError {
    A(TryReserveError)
}


fn main() {
    let mut hashset: HashSet<u32> = HashSet::<u32>::new();

    hashset.try_reserve(10).map_err(|error| MyError::A(error)).unwrap();
}

I expected to see this happen:
Clippy should tell me that I can just call the tuple struct

Instead, this happened:
Clippy calls the tuple struct a function, which confused me.

Checking playground v0.0.1 (/playground)
warning: redundant closure
  [--> src/main.rs:13:37
](https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=e6487c80374671aecf918e801f279c42#)   |
13 |     hashset.try_reserve(10).map_err(|error| MyError::A(error)).unwrap();
   |                                     ^^^^^^^^^^^^^^^^^^^^^^^^^ help: replace the closure with the function itself: `MyError::A`
   |
   = note: `#[warn(clippy::redundant_closure)]` on by default
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure

warning: `playground` (bin "playground") generated 1 warning
    Finished dev [unoptimized + debuginfo] target(s) in 0.44s
    ```


### Version

_No response_

### Additional Labels

_No response_

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thing

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions