]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-23261.rs
Remove the in-tree `flate` crate
[rust.git] / src / test / run-pass / issue-23261.rs
1 // Copyright 2015 The Rust Project Developers. See the COPYRIGHT
2 // file at the top-level directory of this distribution and at
3 // http://rust-lang.org/COPYRIGHT.
4 //
5 // Licensed under the Apache License, Version 2.0 <LICENSE-APACHE or
6 // http://www.apache.org/licenses/LICENSE-2.0> or the MIT license
7 // <LICENSE-MIT or http://opensource.org/licenses/MIT>, at your
8 // option. This file may not be copied, modified, or distributed
9 // except according to those terms.
10
11 // Matching on a DST struct should not trigger an LLVM assertion.
12
13 struct Foo<T: ?Sized> {
14     a: i32,
15     inner: T
16 }
17
18 trait Get {
19     fn get(&self) -> i32;
20 }
21
22 impl Get for i32 {
23     fn get(&self) -> i32 {
24         *self
25     }
26 }
27
28 fn check_val(val: &Foo<[u8]>) {
29     match *val {
30         Foo { a, .. } => {
31             assert_eq!(a, 32);
32         }
33     }
34 }
35
36 fn check_dst_val(val: &Foo<[u8]>) {
37     match *val {
38         Foo { ref inner, .. } => {
39             assert_eq!(inner, [1, 2, 3]);
40         }
41     }
42 }
43
44 fn check_both(val: &Foo<[u8]>) {
45     match *val {
46         Foo { a, ref inner } => {
47             assert_eq!(a, 32);
48             assert_eq!(inner, [1, 2, 3]);
49         }
50     }
51 }
52
53 fn check_trait_obj(val: &Foo<Get>) {
54     match *val {
55         Foo { a, ref inner } => {
56             assert_eq!(a, 32);
57             assert_eq!(inner.get(), 32);
58         }
59     }
60 }
61
62 fn main() {
63     let foo: &Foo<[u8]> = &Foo { a: 32, inner: [1, 2, 3] };
64     check_val(foo);
65     check_dst_val(foo);
66     check_both(foo);
67
68     let foo: &Foo<Get> = &Foo { a: 32, inner: 32 };
69     check_trait_obj(foo);
70 }