]> git.lizzy.rs Git - rust.git/blob - src/test/ui/structs-enums/expr-if-struct.rs
Rollup merge of #105843 - compiler-errors:sugg-const, r=lcnr
[rust.git] / src / test / ui / structs-enums / expr-if-struct.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3
4
5
6
7 // Tests for if as expressions returning nominal types
8
9 #[derive(Copy, Clone)]
10 struct I { i: isize }
11
12 fn test_rec() {
13     let rs = if true { I {i: 100} } else { I {i: 101} };
14     assert_eq!(rs.i, 100);
15 }
16
17 #[derive(Copy, Clone, Debug)]
18 enum mood { happy, sad, }
19
20 impl PartialEq for mood {
21     fn eq(&self, other: &mood) -> bool {
22         ((*self) as usize) == ((*other) as usize)
23     }
24     fn ne(&self, other: &mood) -> bool { !(*self).eq(other) }
25 }
26
27 fn test_tag() {
28     let rs = if true { mood::happy } else { mood::sad };
29     assert_eq!(rs, mood::happy);
30 }
31
32 pub fn main() { test_rec(); test_tag(); }