]> git.lizzy.rs Git - rust.git/commitdiff
move ok_expect tests
authorCameron Steffen <CSteffen@trustwave.com>
Tue, 10 Oct 2017 05:03:39 +0000 (00:03 -0500)
committerCameron Steffen <CSteffen@trustwave.com>
Tue, 10 Oct 2017 05:03:39 +0000 (00:03 -0500)
tests/ui/methods.rs
tests/ui/methods.stderr
tests/ui/ok_expect.rs [new file with mode: 0644]
tests/ui/ok_expect.stderr [new file with mode: 0644]

index 20776ca15da456db2f334df99fd66a6492c8994c..e3a75521f3076e2d99cadfcc4b111f0e7cdae9e8 100644 (file)
@@ -393,32 +393,6 @@ fn get_unwrap() {
 
 #[allow(similar_names)]
 fn main() {
-    use std::io;
-
     let opt = Some(0);
     let _ = opt.unwrap();
-
-    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");
-}
-
-struct MyError(()); // doesn't implement Debug
-
-#[derive(Debug)]
-struct MyErrorWithParam<T> {
-    x: T
 }
index 1b5deef998e2c24c95617e4f643956e4fab0af38..18b04371d1b6493421e58d7ab3eae5e225979370 100644 (file)
@@ -500,50 +500,10 @@ error: called `.get_mut().unwrap()` on a VecDeque. Using `[]` is more clear and
     |          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: try this: `&mut some_vecdeque[0]`
 
 error: used unwrap() on an Option value. If you don't want to handle the None case gracefully, consider using expect() to provide a better panic message
-   --> $DIR/methods.rs:399:13
+   --> $DIR/methods.rs:397:13
     |
-399 |     let _ = opt.unwrap();
+397 |     let _ = opt.unwrap();
     |             ^^^^^^^^^^^^
     |
     = note: `-D option-unwrap-used` implied by `-D warnings`
 
-error: used unwrap() on a Result value. If you don't want to handle the Err case gracefully, consider using expect() to provide a better panic message
-   --> $DIR/methods.rs:402:13
-    |
-402 |     let _ = res.unwrap();
-    |             ^^^^^^^^^^^^
-    |
-    = note: `-D result-unwrap-used` implied by `-D warnings`
-
-error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
-   --> $DIR/methods.rs:404:5
-    |
-404 |     res.ok().expect("disaster!");
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
-    |
-    = note: `-D ok-expect` implied by `-D warnings`
-
-error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
-   --> $DIR/methods.rs:410:5
-    |
-410 |     res3.ok().expect("whoof");
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
-   --> $DIR/methods.rs:412:5
-    |
-412 |     res4.ok().expect("argh");
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
-   --> $DIR/methods.rs:414:5
-    |
-414 |     res5.ok().expect("oops");
-    |     ^^^^^^^^^^^^^^^^^^^^^^^^
-
-error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
-   --> $DIR/methods.rs:416:5
-    |
-416 |     res6.ok().expect("meh");
-    |     ^^^^^^^^^^^^^^^^^^^^^^^
-
diff --git a/tests/ui/ok_expect.rs b/tests/ui/ok_expect.rs
new file mode 100644 (file)
index 0000000..4341e8e
--- /dev/null
@@ -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");
+}
diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr
new file mode 100644 (file)
index 0000000..79b09b3
--- /dev/null
@@ -0,0 +1,32 @@
+error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
+  --> $DIR/ok_expect.rs:14:5
+   |
+14 |     res.ok().expect("disaster!");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+   |
+   = note: `-D ok-expect` implied by `-D warnings`
+
+error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
+  --> $DIR/ok_expect.rs:20:5
+   |
+20 |     res3.ok().expect("whoof");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
+  --> $DIR/ok_expect.rs:22:5
+   |
+22 |     res4.ok().expect("argh");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
+  --> $DIR/ok_expect.rs:24:5
+   |
+24 |     res5.ok().expect("oops");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^^
+
+error: called `ok().expect()` on a Result value. You can call `expect` directly on the `Result`
+  --> $DIR/ok_expect.rs:26:5
+   |
+26 |     res6.ok().expect("meh");
+   |     ^^^^^^^^^^^^^^^^^^^^^^^
+