rust-lang / rust-lang/rust-clippy
`no_effect_underscore_binding` fires when ignoring a generic argument
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 13.5k
- Forks
- 2.2k
- Avg merge
- 2d 10h
- Merged PRs (30d)
- 32
Description
Summary
When accepting a T: IntoIterator argument, no_effect_underscore_binding requires .into_iter() be called on the argument when assigning to an _ prefixed variable.
Lint Name
no_effect_underscore_binding
Reproducer
I tried this code:
#![warn(clippy::all)]
#![warn(clippy::pedantic)]
/// # Errors
/// not implemented
pub fn iter_good<T>(args: T) -> Result<String, &'static str>
where
T: IntoIterator<Item = String>,
{
let _ignored_while_unimplemented = args.into_iter();
Err("good")
}
/// # Errors
/// not implemented
pub fn iter_bad<T>(args: T) -> Result<String, &'static str>
where
T: IntoIterator<Item = String>,
{
let _ignored_while_unimplemented = args;
Err("bad")
}
I saw this happen:
Checking playground v0.0.1 (/playground)
warning: binding to `_` prefixed variable with no side-effect
--> src/lib.rs:20:5
|
20 | let _ignored_while_unimplemented = args;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
|
note: the lint level is defined here
--> src/lib.rs:2:9
|
2 | #![warn(clippy::pedantic)]
| ^^^^^^^^^^^^^^^^
= note: `#[warn(clippy::no_effect_underscore_binding)]` implied by `#[warn(clippy::pedantic)]`
= help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#no_effect_underscore_binding
warning: `playground` (lib) generated 1 warning
Finished dev [unoptimized + debuginfo] target(s) in 0.57s
I expected to see this happen: no warnings
Version
playground rust 1.58.0
Clippy 0.1.60 (2022-01-15 ec4bcaa)
Additional Labels
No response
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 reproducing the no_effect_underscore_binding warning with the iter_good and iter_bad examples from the issue, using the linked Rust Playground. Then inspect the lint's implementation and existing test coverage. Done means the generic IntoIterator binding in iter_bad no longer produces this warning while the expected lint behavior remains covered.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- rust
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100