mirror of
https://github.com/rust-lang/rust-clippy
synced 2024-12-21 10:33:27 +00:00
28 lines
476 B
Rust
28 lines
476 B
Rust
|
#![allow(unused)]
|
||
|
#![warn(clippy::size_of_ref)]
|
||
|
|
||
|
use std::mem::size_of_val;
|
||
|
|
||
|
fn main() {
|
||
|
let x = 5;
|
||
|
let y = &x;
|
||
|
|
||
|
size_of_val(&x); // no lint
|
||
|
size_of_val(y); // no lint
|
||
|
|
||
|
size_of_val(&&x);
|
||
|
size_of_val(&y);
|
||
|
}
|
||
|
|
||
|
struct S {
|
||
|
field: u32,
|
||
|
data: Vec<u8>,
|
||
|
}
|
||
|
|
||
|
impl S {
|
||
|
/// Get size of object including `self`, in bytes.
|
||
|
pub fn size(&self) -> usize {
|
||
|
std::mem::size_of_val(&self) + (std::mem::size_of::<u8>() * self.data.capacity())
|
||
|
}
|
||
|
}
|