Repository navigation
Open
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Description
Summary
.
Lint Name
redundant_closure_for_method_calls
Reproducer
I tried this code:
#![allow(clippy::stable_sort_primitive)]
use std::cell::Ref;
mod issue_5754 {}
// The closure parameter is not dereferenced anymore, so non-Copy types can be linted
mod issue_6001 {
struct Test(String);
impl Test {
// Return an owned type so that we don't hit the fix for 5754
fn name(&self) -> String {
self.0.clone()
}
}
pub fn test() {
let mut args: Vec<Test> = vec![];
// Forward
args.sort_by_key(|a| a.name());
args.sort_unstable_by_key(|a| a.name());
// Reverse
args.sort_by(|a, b| b.name().cmp(&a.name()));
args.sort_unstable_by(|a, b| b.name().cmp(&a.name()));
}
}
fn main() {
issue_6001::test();
}cargo clippy --fix -- -Aclippy::unnecessary_sort_by -Wclippy::pedantic
The following errors were reported:
error[E0433]: failed to resolve: use of undeclared crate or module `issue_6001`
--> src/main.rs:21:26
|
21 | args.sort_by_key(issue_6001::Test::name);
| ^^^^^^^^^^ use of undeclared crate or module `issue_6001`
error[E0433]: failed to resolve: use of undeclared crate or module `issue_6001`
--> src/main.rs:22:35
|
22 | args.sort_unstable_by_key(issue_6001::Test::name);
| ^^^^^^^^^^ use of undeclared crate or module `issue_6001`
error: aborting due to 2 previous errors
For more information about this error, try `rustc --explain E0433`.
Original diagnostics will follow.
warning: unused import: `std::cell::Ref`
--> src/main.rs:3:5
|
3 | use std::cell::Ref;
| ^^^^^^^^^^^^^^
|
= note: `#[warn(unused_imports)]` on by default
warning: redundant closure
--> src/main.rs:21:26
|
21 | args.sort_by_key(|a| a.name());
| ^^^^^^^^^^^^ help: replace the closure with the method itself: `issue_6001::Test::name`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
= note: `-W clippy::redundant-closure-for-method-calls` implied by `-W clippy::pedantic`
warning: redundant closure
--> src/main.rs:22:35
|
22 | args.sort_unstable_by_key(|a| a.name());
| ^^^^^^^^^^^^ help: replace the closure with the method itself: `issue_6001::Test::name`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
Version
rustc 1.67.0-nightly (b3bc6bf31 2022-11-24)
binary: rustc
commit-hash: b3bc6bf31265ac10946a0832092dbcedf9b26805
commit-date: 2022-11-24
host: x86_64-unknown-linux-gnu
release: 1.67.0-nightly
LLVM version: 15.0.4
Additional Labels
No response
Metadata
Metadata
Assignees
Labels
C-bugCategory: Clippy is not doing the correct thingCategory: Clippy is not doing the correct thingI-false-positiveIssue: The lint was triggered on code it shouldn't haveIssue: The lint was triggered on code it shouldn't haveI-suggestion-causes-errorIssue: The suggestions provided by this Lint cause an ICE/error when appliedIssue: The suggestions provided by this Lint cause an ICE/error when applied
Activity