Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no_effect_underscore_binding fires when ignoring a generic argument #8300

Open
lopopolo opened this issue Jan 17, 2022 · 1 comment
Open
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have

Comments

@lopopolo
Copy link

lopopolo commented Jan 17, 2022

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

https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=3ffd5b85bf0c41df91d23f7eb9e1eea9

Version

playground rust 1.58.0

Clippy 0.1.60 (2022-01-15 ec4bcaa)

Additional Labels

No response

@lopopolo lopopolo added C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have labels Jan 17, 2022
@oxalica
Copy link
Contributor

oxalica commented Aug 5, 2023

The lint also falsely triggers when the binding actually has effects on drop ordering, like to move a generic guard into an async block.

#![warn(clippy::pedantic)]

fn work(_: impl std::future::Future<Output = ()>) { todo!() }

pub fn foo<T>(guard: T) {
    let fut = async move {
        let _guard = guard;
        // work...
    };
    work(fut);
}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: Clippy is not doing the correct thing I-false-positive Issue: The lint was triggered on code it shouldn't have
Projects
None yet
Development

No branches or pull requests

2 participants