rust-lang / rust-lang/rust-clippy
`redundant_closure_for_method_calls` suggesting a private module/type
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
I noticed this bug while working on a project using https://github.com/lyssieth/htp/tree/lyssieth-time-support, specifically that it was trying to use a private module from that branch of htp
Lint Name
redundant_closure_for_method_calls
Reproducer
I tried this code:
// `expire` here is an Option<String> generally containing text like: `in 1 hour`, `in 50 min`, etc
let expire = match expire {
Some(expire) => Some(htp::parse(&expire, OffsetDateTime::now_utc())?),
None => None,
};
// this causes the false positive, since `unified` is an internal module for `htp`
// Converting the internal `htp::unified::DateTime` to a usable `time::OffsetDateTime` via the fn `as_time`
let expire = expire.and_then(|dt|dt.as_time());
// after application:
let expire = expire.and_then(htp::unified::DateTime::as_time);
// and this then causes an error.
I saw this happen:
warning: redundant closure
--> src/main.rs:63:46
|
63 | let expire = expire.and_then(|dt| dt.as_time());
| ^^^^^^^^^^^^^^^^^ help: replace the closure with the method itself: `htp::unified::DateTime::as_time`
|
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#redundant_closure_for_method_calls
note: the lint level is defined here
--> src/main.rs:1:9
|
1 | #![warn(clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[warn(clippy::redundant_closure_for_method_calls)]` implied by `#[warn(clippy::pedantic)]`
I expected to see this happen:
It to not trigger, as if the lint is applied, it causes an error instead. htp::unified is a private module of htp.
Version
rustc 1.66.0 (69f9c33d7 2022-12-12)
binary: rustc
commit-hash: 69f9c33d71c871fc16ac445211281c6e7a340943
commit-date: 2022-12-12
host: x86_64-unknown-linux-gnu
release: 1.66.0
LLVM version: 15.0.2
Additional Labels
@rustbot label +I-suggestion-causes-error
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by locating the implementation and tests for the redundant_closure_for_method_calls lint, then reproduce the htp example with the private htp::unified::DateTime type. The fix is done when the lint no longer emits an unusable method suggestion for an inaccessible private module or type.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100