Skip to content

Let_unit_value false positive when return type is type parameter #1502

Closed
@dtolnay

Description

@dtolnay
fn main() {
    let _: () = f();
}

fn f<T: Default>() -> T {
    T::default()
}
warning: this let-binding has unit value. Consider omitting `let _ =`, #[warn(let_unit_value)] on by default
 --> src/main.rs:2:5
  |
2 |     let _: () = f();
  |     ^^^^^^^^^^^^^^^^
  |
  = help: for further information visit https://github.com/Manishearth/rust-clippy/wiki#let_unit_value

Maybe this specific case would be clearer with f::<()>() but I consider this a false positive. Came up in serde_json unit tests where we test that serde_json::from_str can parse various representations of ().

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: Clippy is not doing the correct thingE-hardCall for participation: This a hard problem and requires more experience or effort to work onI-false-positiveIssue: The lint was triggered on code it shouldn't haveT-middleType: Probably requires verifiying types

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions