summaryrefslogtreecommitdiffstats
path: root/src/tools/clippy/tests/ui/ok_expect.rs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--src/tools/clippy/tests/ui/ok_expect.rs27
1 files changed, 27 insertions, 0 deletions
diff --git a/src/tools/clippy/tests/ui/ok_expect.rs b/src/tools/clippy/tests/ui/ok_expect.rs
new file mode 100644
index 000000000..ff68d38c7
--- /dev/null
+++ b/src/tools/clippy/tests/ui/ok_expect.rs
@@ -0,0 +1,27 @@
+use std::io;
+
+struct MyError(()); // doesn't implement Debug
+
+#[derive(Debug)]
+struct MyErrorWithParam<T> {
+ x: T,
+}
+
+fn main() {
+ let res: Result<i32, ()> = Ok(0);
+ let _ = res.unwrap();
+
+ res.ok().expect("disaster!");
+ // the following should not warn, since `expect` isn't implemented unless
+ // the error type implements `Debug`
+ let res2: Result<i32, MyError> = Ok(0);
+ res2.ok().expect("oh noes!");
+ let res3: Result<u32, MyErrorWithParam<u8>> = Ok(0);
+ res3.ok().expect("whoof");
+ let res4: Result<u32, io::Error> = Ok(0);
+ res4.ok().expect("argh");
+ let res5: io::Result<u32> = Ok(0);
+ res5.ok().expect("oops");
+ let res6: Result<u32, &str> = Ok(0);
+ res6.ok().expect("meh");
+}