about summary refs log tree commit diff
path: root/src/test/ui/lint
diff options
context:
space:
mode:
authorAaron Kofsky <aaronko@umich.edu>2022-06-04 20:04:01 -0400
committerAaron Kofsky <aaronko@umich.edu>2022-06-04 20:04:01 -0400
commit7e485bf4ddd3f56c76a572757d60c24dcfaa7dbe (patch)
tree1584b163d545cda1d234901d4d6f47c223a15bff /src/test/ui/lint
parenta7e2b3e879790284b64529e3fb7d659274420a90 (diff)
downloadrust-7e485bf4ddd3f56c76a572757d60c24dcfaa7dbe.tar.gz
rust-7e485bf4ddd3f56c76a572757d60c24dcfaa7dbe.zip
Move `let_underscore` tests into the `lint` subfolder.
Diffstat (limited to 'src/test/ui/lint')
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_drop.rs14
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_drop.stderr18
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_lock.rs6
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_lock.stderr18
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_must_use.rs13
-rw-r--r--src/test/ui/lint/let_underscore/let_underscore_must_use.stderr33
6 files changed, 102 insertions, 0 deletions
diff --git a/src/test/ui/lint/let_underscore/let_underscore_drop.rs b/src/test/ui/lint/let_underscore/let_underscore_drop.rs
new file mode 100644
index 00000000000..75c6ecec3ee
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_drop.rs
@@ -0,0 +1,14 @@
+// run-pass
+// compile-flags: -W let_underscore_drop
+
+struct NontrivialDrop;
+
+impl Drop for NontrivialDrop {
+    fn drop(&mut self) {
+        println!("Dropping!");
+    }
+}
+
+fn main() {
+    let _ = NontrivialDrop; //~WARNING non-binding let on a type that implements `Drop`
+}
diff --git a/src/test/ui/lint/let_underscore/let_underscore_drop.stderr b/src/test/ui/lint/let_underscore/let_underscore_drop.stderr
new file mode 100644
index 00000000000..5034f682bb7
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_drop.stderr
@@ -0,0 +1,18 @@
+warning: non-binding let on a type that implements `Drop`
+  --> $DIR/let_underscore_drop.rs:13:5
+   |
+LL |     let _ = NontrivialDrop;
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: requested on the command line with `-W let-underscore-drop`
+help: consider binding to an unused variable
+   |
+LL |     let _unused = NontrivialDrop;
+   |         ~~~~~~~
+help: consider explicitly droping with `std::mem::drop`
+   |
+LL |     let _ = drop(...);
+   |             ~~~~~~~~~
+
+warning: 1 warning emitted
+
diff --git a/src/test/ui/lint/let_underscore/let_underscore_lock.rs b/src/test/ui/lint/let_underscore/let_underscore_lock.rs
new file mode 100644
index 00000000000..c37264136ef
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_lock.rs
@@ -0,0 +1,6 @@
+use std::sync::{Arc, Mutex};
+
+fn main() {
+    let data = Arc::new(Mutex::new(0));
+    let _ = data.lock().unwrap(); //~ERROR non-binding let on a synchronization lock
+}
diff --git a/src/test/ui/lint/let_underscore/let_underscore_lock.stderr b/src/test/ui/lint/let_underscore/let_underscore_lock.stderr
new file mode 100644
index 00000000000..b7e14e8c7b5
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_lock.stderr
@@ -0,0 +1,18 @@
+error: non-binding let on a synchronization lock
+  --> $DIR/let_underscore_lock.rs:5:5
+   |
+LL |     let _ = data.lock().unwrap();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `#[deny(let_underscore_lock)]` on by default
+help: consider binding to an unused variable
+   |
+LL |     let _unused = data.lock().unwrap();
+   |         ~~~~~~~
+help: consider explicitly droping with `std::mem::drop`
+   |
+LL |     let _ = drop(...);
+   |             ~~~~~~~~~
+
+error: aborting due to previous error
+
diff --git a/src/test/ui/lint/let_underscore/let_underscore_must_use.rs b/src/test/ui/lint/let_underscore/let_underscore_must_use.rs
new file mode 100644
index 00000000000..8efaad51ea8
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_must_use.rs
@@ -0,0 +1,13 @@
+// run-pass
+// compile-flags: -W let_underscore_must_use
+
+#[must_use]
+struct MustUseType;
+
+#[must_use]
+fn must_use_function() -> () {}
+
+fn main() {
+    let _ = MustUseType; //~WARNING non-binding let on a expression marked `must_use`
+    let _ = must_use_function(); //~WARNING non-binding let on a expression marked `must_use`
+}
diff --git a/src/test/ui/lint/let_underscore/let_underscore_must_use.stderr b/src/test/ui/lint/let_underscore/let_underscore_must_use.stderr
new file mode 100644
index 00000000000..959572edd7c
--- /dev/null
+++ b/src/test/ui/lint/let_underscore/let_underscore_must_use.stderr
@@ -0,0 +1,33 @@
+warning: non-binding let on a expression marked `must_use`
+  --> $DIR/let_underscore_must_use.rs:11:5
+   |
+LL |     let _ = MustUseType;
+   |     ^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: requested on the command line with `-W let-underscore-must-use`
+help: consider binding to an unused variable
+   |
+LL |     let _unused = MustUseType;
+   |         ~~~~~~~
+help: consider explicitly droping with `std::mem::drop`
+   |
+LL |     let _ = drop(...);
+   |             ~~~~~~~~~
+
+warning: non-binding let on a expression marked `must_use`
+  --> $DIR/let_underscore_must_use.rs:12:5
+   |
+LL |     let _ = must_use_function();
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+help: consider binding to an unused variable
+   |
+LL |     let _unused = must_use_function();
+   |         ~~~~~~~
+help: consider explicitly droping with `std::mem::drop`
+   |
+LL |     let _ = drop(...);
+   |             ~~~~~~~~~
+
+warning: 2 warnings emitted
+