Skip to content

let-binding has unit value fix breaks code #111247

@Eagle941

Description

@Eagle941

This is the code:

pub struct AnyId<T: ?Sized> {
   metadata: <T as Pointee>::Metadata,
}

pub struct AnyStore {}

impl AnyStore {
   pub fn push<T: 'static>(value: T) -> AnyId<T> {
      let metadata = std::ptr::metadata(&value);
      AnyId {
	   metadata,
      }
   }
}

I have got this warning:

warning: this let-binding has unit value
  --> dyn_utils\src\any_store.rs:97:3
   |
97 |         let metadata = std::ptr::metadata(&value);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `std::ptr::metadata(&value);`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `#[warn(clippy::let_unit_value)]` on by default

I tried this command:

cargo clippy --fix --lib -p dyn_utils

This happened:

The following errors were reported:
error[E0425]: cannot find value `metadata` in this scope
   --> dyn_utils\src\any_store.rs:111:4
    |
111 |             metadata,
    |             ^^^^^^^^ not found in this scope
    |
help: consider importing one of these items
    |
1   | use core::ptr::metadata;
    |
1   | use std::fs::metadata;
    |
1   | use std::ptr::metadata;
    |

error: aborting due to previous error

For more information about this error, try `rustc --explain E0425`.
Original diagnostics will follow.

warning: this let-binding has unit value
  --> dyn_utils\src\any_store.rs:97:3
   |
97 |         let metadata = std::ptr::metadata(&value);
   |         ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: omit the `let` binding: `std::ptr::metadata(&value);`
   |
   = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#let_unit_value
   = note: `#[warn(clippy::let_unit_value)]` on by default

warning: `dyn_utils` (lib) generated 1 warning (run `cargo clippy --fix --lib -p dyn_utils` to apply 1 suggestion)
    Finished dev [unoptimized + debuginfo] target(s) in 0.48s

Meta

rustc --version --verbose:

rustc 1.69.0-nightly (f3126500f 2023-02-02)
binary: rustc
commit-hash: f3126500f25114ba4e0ac3e76694dd45a22de56d
commit-date: 2023-02-02
host: x86_64-pc-windows-msvc
release: 1.69.0-nightly
LLVM version: 15.0.7

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-bugCategory: This is a bug.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions