]> git.lizzy.rs Git - rust.git/blob - tests/ui/question_mark.rs
Adapt the *.stderr files of the ui-tests to the tool_lints
[rust.git] / tests / ui / question_mark.rs
1 fn some_func(a: Option<u32>) -> Option<u32> {
2         if a.is_none() {
3                 return None
4         }
5
6         a
7 }
8
9 pub enum SeemsOption<T> {
10     Some(T),
11     None
12 }
13
14 impl<T> SeemsOption<T> {
15     pub fn is_none(&self) -> bool {
16         match *self {
17             SeemsOption::None => true,
18             SeemsOption::Some(_) => false,
19         }
20     }
21 }
22
23 fn returns_something_similar_to_option(a: SeemsOption<u32>) -> SeemsOption<u32> {
24     if a.is_none() {
25         return SeemsOption::None;
26     }
27
28     a
29 }
30
31 pub struct SomeStruct {
32         pub opt: Option<u32>,
33 }
34
35 impl SomeStruct {
36         pub fn func(&self) -> Option<u32> {
37                 if (self.opt).is_none() {
38                         return None;
39                 }
40
41                 self.opt
42         }
43 }
44
45 fn main() {
46         some_func(Some(42));
47         some_func(None);
48
49         let some_struct = SomeStruct { opt: Some(54) };
50         some_struct.func();
51
52     let so = SeemsOption::Some(45);
53     returns_something_similar_to_option(so);
54 }