]> git.lizzy.rs Git - rust.git/blob - tests/ui/ok_expect.rs
Auto merge of #3635 - matthiaskrgr:revert_random_state_3603, r=xfix
[rust.git] / tests / ui / ok_expect.rs
1 // Copyright 2014-2018 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution.
3 //
4 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
5 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
6 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
7 // option. This file may not be copied, modified, or distributed
8 // except according to those terms.
9
10 use std::io;
11
12 struct MyError(()); // doesn't implement Debug
13
14 #[derive(Debug)]
15 struct MyErrorWithParam<T> {
16     x: T,
17 }
18
19 fn main() {
20     let res: Result<i32, ()> = Ok(0);
21     let _ = res.unwrap();
22
23     res.ok().expect("disaster!");
24     // the following should not warn, since `expect` isn't implemented unless
25     // the error type implements `Debug`
26     let res2: Result<i32, MyError> = Ok(0);
27     res2.ok().expect("oh noes!");
28     let res3: Result<u32, MyErrorWithParam<u8>> = Ok(0);
29     res3.ok().expect("whoof");
30     let res4: Result<u32, io::Error> = Ok(0);
31     res4.ok().expect("argh");
32     let res5: io::Result<u32> = Ok(0);
33     res5.ok().expect("oops");
34     let res6: Result<u32, &str> = Ok(0);
35     res6.ok().expect("meh");
36 }