move ok_expect tests

This commit is contained in:
Cameron Steffen 2017-10-10 00:03:39 -05:00
parent 3356d121df
commit 90b428e88d
4 changed files with 61 additions and 68 deletions

View 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
}

View 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");
| ^^^^^^^^^^^^^^^^^^^^^^^

27
tests/ui/ok_expect.rs Normal file
View file

@ -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");
}

32
tests/ui/ok_expect.stderr Normal file
View file

@ -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");
| ^^^^^^^^^^^^^^^^^^^^^^^