]> git.lizzy.rs Git - rust.git/blob - tests/ui/rfcs/rfc-2005-default-binding-mode/constref.rs
Rollup merge of #106244 - atouchet:readme3, r=workingjubilee
[rust.git] / tests / ui / rfcs / rfc-2005-default-binding-mode / constref.rs
1 // run-pass
2 const CONST_REF: &[u8; 3] = b"foo";
3
4 trait Foo {
5     const CONST_REF_DEFAULT: &'static [u8; 3] = b"bar";
6     const CONST_REF: &'static [u8; 3];
7 }
8
9 impl Foo for i32 {
10     const CONST_REF: &'static [u8; 3] = b"jjj";
11 }
12
13 impl Foo for i64 {
14     const CONST_REF_DEFAULT: &'static [u8; 3] = b"ggg";
15     const CONST_REF: &'static [u8; 3] = b"fff";
16 }
17
18 // Check that (associated and free) const references are not mistaken for a
19 // non-reference pattern (in which case they would be auto-dereferenced, making
20 // the types mismatched).
21
22 fn const_ref() -> bool {
23     let f = b"foo";
24     match f {
25         CONST_REF => true,
26         _ => false,
27     }
28 }
29
30 fn associated_const_ref() -> bool {
31     match (b"bar", b"jjj", b"ggg", b"fff") {
32         (i32::CONST_REF_DEFAULT, i32::CONST_REF, i64::CONST_REF_DEFAULT, i64::CONST_REF) => true,
33         _ => false,
34     }
35 }
36
37 pub fn main() {
38     assert!(const_ref());
39     assert!(associated_const_ref());
40 }