2023-05-31 12:47:10 -05:00
|
|
|
#![allow(clippy::unnecessary_literal_unwrap)]
|
|
|
|
|
2017-10-10 00:03:39 -05:00
|
|
|
use std::io;
|
|
|
|
|
|
|
|
struct MyError(()); // doesn't implement Debug
|
|
|
|
|
|
|
|
#[derive(Debug)]
|
|
|
|
struct MyErrorWithParam<T> {
|
2018-12-09 16:26:16 -06:00
|
|
|
x: T,
|
2017-10-10 00:03:39 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
fn main() {
|
|
|
|
let res: Result<i32, ()> = Ok(0);
|
|
|
|
let _ = res.unwrap();
|
|
|
|
|
|
|
|
res.ok().expect("disaster!");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `ok().expect()` on a `Result` value
|
2017-10-10 00:03:39 -05:00
|
|
|
// 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!");
|
2018-12-09 16:26:16 -06:00
|
|
|
let res3: Result<u32, MyErrorWithParam<u8>> = Ok(0);
|
2017-10-10 00:03:39 -05:00
|
|
|
res3.ok().expect("whoof");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `ok().expect()` on a `Result` value
|
2017-10-10 00:03:39 -05:00
|
|
|
let res4: Result<u32, io::Error> = Ok(0);
|
|
|
|
res4.ok().expect("argh");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `ok().expect()` on a `Result` value
|
2017-10-10 00:03:39 -05:00
|
|
|
let res5: io::Result<u32> = Ok(0);
|
|
|
|
res5.ok().expect("oops");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `ok().expect()` on a `Result` value
|
2017-10-10 00:03:39 -05:00
|
|
|
let res6: Result<u32, &str> = Ok(0);
|
|
|
|
res6.ok().expect("meh");
|
2023-07-28 14:35:48 -05:00
|
|
|
//~^ ERROR: called `ok().expect()` on a `Result` value
|
2017-10-10 00:03:39 -05:00
|
|
|
}
|