diff --git a/tests/ui/methods.rs b/tests/ui/methods.rs index 20776ca15..e3a75521f 100644 --- a/tests/ui/methods.rs +++ b/tests/ui/methods.rs @@ -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 = 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 = Ok(0); - res2.ok().expect("oh noes!"); - let res3: Result>= Ok(0); - res3.ok().expect("whoof"); - let res4: Result = Ok(0); - res4.ok().expect("argh"); - let res5: io::Result = Ok(0); - res5.ok().expect("oops"); - let res6: Result = Ok(0); - res6.ok().expect("meh"); -} - -struct MyError(()); // doesn't implement Debug - -#[derive(Debug)] -struct MyErrorWithParam { - x: T } diff --git a/tests/ui/methods.stderr b/tests/ui/methods.stderr index 1b5deef99..18b04371d 100644 --- a/tests/ui/methods.stderr +++ b/tests/ui/methods.stderr @@ -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 index 000000000..4341e8ea7 --- /dev/null +++ b/tests/ui/ok_expect.rs @@ -0,0 +1,27 @@ +use std::io; + +struct MyError(()); // doesn't implement Debug + +#[derive(Debug)] +struct MyErrorWithParam { + x: T +} + +fn main() { + let res: Result = 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 = Ok(0); + res2.ok().expect("oh noes!"); + let res3: Result>= Ok(0); + res3.ok().expect("whoof"); + let res4: Result = Ok(0); + res4.ok().expect("argh"); + let res5: io::Result = Ok(0); + res5.ok().expect("oops"); + let res6: Result = Ok(0); + res6.ok().expect("meh"); +} diff --git a/tests/ui/ok_expect.stderr b/tests/ui/ok_expect.stderr new file mode 100644 index 000000000..79b09b3fa --- /dev/null +++ b/tests/ui/ok_expect.stderr @@ -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"); + | ^^^^^^^^^^^^^^^^^^^^^^^ +