summaryrefslogtreecommitdiffstats
path: root/tests/ui/lint/forgetting_copy_types.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-05-18 02:49:50 +0000
commit9835e2ae736235810b4ea1c162ca5e65c547e770 (patch)
tree3fcebf40ed70e581d776a8a4c65923e8ec20e026 /tests/ui/lint/forgetting_copy_types.rs
parentReleasing progress-linux version 1.70.0+dfsg2-1~progress7.99u1. (diff)
downloadrustc-9835e2ae736235810b4ea1c162ca5e65c547e770.tar.xz
rustc-9835e2ae736235810b4ea1c162ca5e65c547e770.zip
Merging upstream version 1.71.1+dfsg1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'tests/ui/lint/forgetting_copy_types.rs')
-rw-r--r--tests/ui/lint/forgetting_copy_types.rs56
1 files changed, 56 insertions, 0 deletions
diff --git a/tests/ui/lint/forgetting_copy_types.rs b/tests/ui/lint/forgetting_copy_types.rs
new file mode 100644
index 000000000..224c7bcd5
--- /dev/null
+++ b/tests/ui/lint/forgetting_copy_types.rs
@@ -0,0 +1,56 @@
+// check-pass
+
+#![warn(forgetting_copy_types)]
+
+use std::mem::forget;
+use std::vec::Vec;
+
+#[derive(Copy, Clone)]
+struct SomeStruct;
+
+struct AnotherStruct {
+ x: u8,
+ y: u8,
+ z: Vec<u8>,
+}
+
+impl Clone for AnotherStruct {
+ fn clone(&self) -> AnotherStruct {
+ AnotherStruct {
+ x: self.x,
+ y: self.y,
+ z: self.z.clone(),
+ }
+ }
+}
+
+fn main() {
+ let s1 = SomeStruct {};
+ let s2 = s1;
+ let s3 = &s1;
+ let mut s4 = s1;
+ let ref s5 = s1;
+
+ forget(s1); //~ WARN calls to `std::mem::forget`
+ forget(s2); //~ WARN calls to `std::mem::forget`
+ forget(s3); //~ WARN calls to `std::mem::forget`
+ forget(s4); //~ WARN calls to `std::mem::forget`
+ forget(s5); //~ WARN calls to `std::mem::forget`
+
+ let a1 = AnotherStruct {
+ x: 255,
+ y: 0,
+ z: vec![1, 2, 3],
+ };
+ let a2 = &a1;
+ let mut a3 = a1.clone();
+ let ref a4 = a1;
+ let a5 = a1.clone();
+
+ forget(a2); //~ WARN calls to `std::mem::forget`
+ let a3 = &a1;
+ forget(a3); //~ WARN calls to `std::mem::forget`
+ forget(a4); //~ WARN calls to `std::mem::forget`
+ let a5 = a1.clone();
+ forget(a5);
+}