Skip to content

let-underscore-must-use is triggered when Debug is derived #4980

@ArekPiekarz

Description

@ArekPiekarz

cargo clippy -V: clippy 0.0.212 (c807fbc 2019-12-29)
rustc -V: rustc 1.42.0-nightly (da3629b 2019-12-29)

Summary

Deriving Debug on a struct with at least one field triggers let-underscore-must-use lint.

Steps to reproduce

Given the following code:

#[derive(Debug)]
struct Foo {
    field: i32,
}

fn main() {
}

When cargo clippy -- -W clippy::let-underscore-must-use is run it emits a warning:

warning: non-binding let on an expression with #[must_use] type
 --> src/main.rs:1:10
  |
1 | #[derive(Debug)]
  |          ^^^^^
  |
  = note: requested on the command line with `-W clippy::let-underscore-must-use`
  = help: consider explicitly using expression value
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_underscore_must_use

If we run cargo expand, we can see the compiler generates an anonymous binding indeed:

#[automatically_derived]
#[allow(unused_qualifications)]
impl ::core::fmt::Debug for Foo {
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match *self {
            Foo {
                field: ref __self_0_0,
            } => {
                let mut debug_trait_builder = f.debug_struct("Foo");
                let _ = debug_trait_builder.field("field", &&(*__self_0_0));
                debug_trait_builder.finish()
            }
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingT-macrosType: Issues with macros and macro expansiongood first issueThese issues are a good way to get started with Clippy

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions