summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/size_of_ref.rs
blob: 1e83ab82907d39d5416f0ca230ec3144506c9ef6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
#![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())
    }
}