summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/unwrap_expect_used.rs
diff options
context:
space:
mode:
authorDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:37 +0000
committerDaniel Baumann <daniel.baumann@progress-linux.org>2024-04-17 12:06:37 +0000
commit246f239d9f40f633160f0c18f87a20922d4e77bb (patch)
tree5a88572663584b3d4d28e5a20e10abab1be40884 /src/tools/clippy/tests/ui/unwrap_expect_used.rs
parentReleasing progress-linux version 1.64.0+dfsg1-1~progress7.99u1. (diff)
downloadrustc-246f239d9f40f633160f0c18f87a20922d4e77bb.tar.xz
rustc-246f239d9f40f633160f0c18f87a20922d4e77bb.zip
Merging debian version 1.65.0+dfsg1-2.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'src/tools/clippy/tests/ui/unwrap_expect_used.rs')
-rw-r--r--src/tools/clippy/tests/ui/unwrap_expect_used.rs35
1 files changed, 35 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/unwrap_expect_used.rs b/src/tools/clippy/tests/ui/unwrap_expect_used.rs
new file mode 100644
index 000000000..9f27fef82
--- /dev/null
+++ b/src/tools/clippy/tests/ui/unwrap_expect_used.rs
@@ -0,0 +1,35 @@
+#![warn(clippy::unwrap_used, clippy::expect_used)]
+
+trait OptionExt {
+ type Item;
+
+ fn unwrap_err(self) -> Self::Item;
+
+ fn expect_err(self, msg: &str) -> Self::Item;
+}
+
+impl<T> OptionExt for Option<T> {
+ type Item = T;
+ fn unwrap_err(self) -> T {
+ panic!();
+ }
+
+ fn expect_err(self, msg: &str) -> T {
+ panic!();
+ }
+}
+
+fn main() {
+ Some(3).unwrap();
+ Some(3).expect("Hello world!");
+
+ // Don't trigger on unwrap_err on an option
+ Some(3).unwrap_err();
+ Some(3).expect_err("Hellow none!");
+
+ let a: Result<i32, i32> = Ok(3);
+ a.unwrap();
+ a.expect("Hello world!");
+ a.unwrap_err();
+ a.expect_err("Hello error!");
+}