]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/rfc-2005-default-binding-mode/constref.rs
Stabilize match_default_bindings
[rust.git] / src / test / run-pass / rfc-2005-default-binding-mode / constref.rs
1 // Copyright 2017 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 const CONST_REF: &[u8; 3] = b"foo";
12
13 trait Foo {
14     const CONST_REF_DEFAULT: &'static [u8; 3] = b"bar";
15     const CONST_REF: &'static [u8; 3];
16 }
17
18 impl Foo for i32 {
19     const CONST_REF: &'static [u8; 3] = b"jjj";
20 }
21
22 impl Foo for i64 {
23     const CONST_REF_DEFAULT: &'static [u8; 3] = b"ggg";
24     const CONST_REF: &'static [u8; 3] = b"fff";
25 }
26
27 // Check that (associated and free) const references are not mistaken for a
28 // non-reference pattern (in which case they would be auto-dereferenced, making
29 // the types mismatched).
30
31 fn const_ref() -> bool {
32     let f = b"foo";
33     match f {
34         CONST_REF => true,
35         _ => false,
36     }
37 }
38
39 fn associated_const_ref() -> bool {
40     match (b"bar", b"jjj", b"ggg", b"fff") {
41         (i32::CONST_REF_DEFAULT, i32::CONST_REF, i64::CONST_REF_DEFAULT, i64::CONST_REF) => true,
42         _ => false,
43     }
44 }
45
46 pub fn main() {
47     assert!(const_ref());
48     assert!(associated_const_ref());
49 }