summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/size_of_ref.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:19:13 +0000
commit218caa410aa38c29984be31a5229b9fa717560ee (patch)
treec54bd55eeb6e4c508940a30e94c0032fbd45d677 /src/tools/clippy/tests/ui/size_of_ref.rs
parentReleasing progress-linux version 1.67.1+dfsg1-1~progress7.99u1. (diff)
downloadrustc-218caa410aa38c29984be31a5229b9fa717560ee.tar.xz
rustc-218caa410aa38c29984be31a5229b9fa717560ee.zip
Merging upstream version 1.68.2+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/size_of_ref.rs')
-rw-r--r--src/tools/clippy/tests/ui/size_of_ref.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/size_of_ref.rs b/src/tools/clippy/tests/ui/size_of_ref.rs
new file mode 100644
index 000000000..1e83ab829
--- /dev/null
+++ b/src/tools/clippy/tests/ui/size_of_ref.rs
@@ -0,0 +1,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())
+ }
+}