6

Add `manual_bits` lint by paolobarbolini · Pull Request #8213 · rust-lang/rust-c...

 2 years ago
source link: https://github.com/rust-lang/rust-clippy/pull/8213
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Copy link

Contributor

mikerite commented 16 days ago

edited

It looks like it triggers for size_of_val as well. I don't think it should do this.

#![warn(clippy::size_of_as_bits)]

use std::mem;

fn main() {
    let x = 0u32;
    println!("{}", 8 * mem::size_of_val(&x));
}
warning: you seem to be using `mem::size_of::<T>()` to obtain the size of `T` in bits
 --> src/main.rs:7:20
  |
7 |     println!("{}", 8 * mem::size_of_val(&x));
  |                    ^^^^^^^^^^^^^^^^^^^^^^^^ help: consider using: `u32::BITS`
  |
note: the lint level is defined here
 --> src/main.rs:1:9
  |
1 | #![warn(clippy::size_of_as_bits)]
  |         ^^^^^^^^^^^^^^^^^^^^^^^
  = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#size_of_as_bits

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK