]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/rfc-2005-default-binding-mode/lit.rs
Stabilize match_default_bindings
[rust.git] / src / test / run-pass / rfc-2005-default-binding-mode / lit.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 fn with_u8() {
12     let s = 5u8;
13     let r = match &s {
14         4 => false,
15         5 => true,
16         _ => false,
17     };
18     assert!(r);
19 }
20
21 // A string literal isn't mistaken for a non-ref pattern (in which case we'd
22 // deref `s` and mess things up).
23 fn with_str() {
24     let s: &'static str = "abc";
25     match s {
26             "abc" => true,
27             _ => panic!(),
28     };
29 }
30
31 // Ditto with byte strings.
32 fn with_bytes() {
33     let s: &'static [u8] = b"abc";
34     match s {
35         b"abc" => true,
36         _ => panic!(),
37     };
38 }
39
40 pub fn main() {
41     with_str();
42 }