]> git.lizzy.rs Git - rust.git/blob - src/test/ui/issues/issue-23261.rs
Rollup merge of #60492 - acrrd:issues/54054_chain, r=SimonSapin
[rust.git] / src / test / ui / issues / issue-23261.rs
1 // run-pass
2 // Matching on a DST struct should not trigger an LLVM assertion.
3
4 struct Foo<T: ?Sized> {
5     a: i32,
6     inner: T
7 }
8
9 trait Get {
10     fn get(&self) -> i32;
11 }
12
13 impl Get for i32 {
14     fn get(&self) -> i32 {
15         *self
16     }
17 }
18
19 fn check_val(val: &Foo<[u8]>) {
20     match *val {
21         Foo { a, .. } => {
22             assert_eq!(a, 32);
23         }
24     }
25 }
26
27 fn check_dst_val(val: &Foo<[u8]>) {
28     match *val {
29         Foo { ref inner, .. } => {
30             assert_eq!(inner, [1, 2, 3]);
31         }
32     }
33 }
34
35 fn check_both(val: &Foo<[u8]>) {
36     match *val {
37         Foo { a, ref inner } => {
38             assert_eq!(a, 32);
39             assert_eq!(inner, [1, 2, 3]);
40         }
41     }
42 }
43
44 fn check_trait_obj(val: &Foo<dyn Get>) {
45     match *val {
46         Foo { a, ref inner } => {
47             assert_eq!(a, 32);
48             assert_eq!(inner.get(), 32);
49         }
50     }
51 }
52
53 fn main() {
54     let foo: &Foo<[u8]> = &Foo { a: 32, inner: [1, 2, 3] };
55     check_val(foo);
56     check_dst_val(foo);
57     check_both(foo);
58
59     let foo: &Foo<dyn Get> = &Foo { a: 32, inner: 32 };
60     check_trait_obj(foo);
61 }