Skip to content

redundant_closure fires for trait function that differs in levels of borrow from point-free form #3802

Closed
@Arnavion

Description

@Arnavion

clippy 0.0.212 (d61b2541 2019-02-19)

#![deny(clippy::redundant_closure)]

pub trait Dependency {
    fn required(&self) -> bool;
}

pub fn foo<D>(dependencies: &[D]) where D: Dependency {
    let _ = dependencies.iter().filter(|dep| dep.required());
}
error: redundant closure found
 --> src/lib.rs:8:40
  |
8 |     let _ = dependencies.iter().filter(|dep| dep.required());
  |                                        ^^^^^^^^^^^^^^^^^^^^ help: remove closure as shown: `Dependency::required`

But that suggestion will not compile because dep is a &&D and Dependency::required wants a &D

    let _ = dependencies.iter().filter(Dependency::required);
error[E0277]: the trait bound `&D: Dependency` is not satisfied
 --> src/lib.rs:9:40
  |
9 |     let _ = dependencies.iter().filter(Dependency::required);
  |                                        ^^^^^^^^^^^^^^^^^^^^ the trait `Dependency` is not implemented for `&D`
  |
note: required by `Dependency::required`

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when applied

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions