]> git.lizzy.rs Git - rust.git/blob - tests/ui/consts/const-struct.rs
Rollup merge of #106963 - compiler-errors:scope-expr-dupe, r=michaelwoerister
[rust.git] / tests / ui / consts / const-struct.rs
1 // run-pass
2 #![allow(non_camel_case_types)]
3 #![allow(non_upper_case_globals)]
4
5 use std::cmp;
6
7 #[derive(Debug)]
8 struct foo { a: isize, b: isize, c: isize }
9
10 impl cmp::PartialEq for foo {
11     fn eq(&self, other: &foo) -> bool {
12         (*self).a == (*other).a &&
13         (*self).b == (*other).b &&
14         (*self).c == (*other).c
15     }
16     fn ne(&self, other: &foo) -> bool { !(*self).eq(other) }
17 }
18
19 const x : foo = foo { a:1, b:2, c: 3 };
20 const y : foo = foo { b:2, c:3, a: 1 };
21 const z : &'static foo = &foo { a: 10, b: 22, c: 12 };
22 const w : foo = foo { a:5, ..x };
23
24 pub fn main() {
25     assert_eq!(x.b, 2);
26     assert_eq!(x, y);
27     assert_eq!(z.b, 22);
28     assert_eq!(w.a, 5);
29     assert_eq!(w.c, 3);
30     println!("{:#x}", x.b);
31     println!("{:#x}", z.c);
32 }