]> git.lizzy.rs Git - rust.git/blob - src/test/run-pass/issue-15571.rs
Auto merge of #23934 - lfairy:write-no-deref, r=alexcrichton
[rust.git] / src / test / run-pass / issue-15571.rs
1 // Copyright 2014 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 #![allow(unknown_features)]
12 #![feature(box_syntax)]
13
14 fn match_on_local() {
15     let mut foo: Option<Box<_>> = Some(box 5);
16     match foo {
17         None => {},
18         Some(x) => {
19             foo = Some(x);
20         }
21     }
22     println!("'{}'", foo.unwrap());
23 }
24
25 fn match_on_arg(mut foo: Option<Box<i32>>) {
26     match foo {
27         None => {}
28         Some(x) => {
29             foo = Some(x);
30         }
31     }
32     println!("'{}'", foo.unwrap());
33 }
34
35 fn match_on_binding() {
36     match Some(Box::new(7)) {
37         mut foo => {
38             match foo {
39                 None => {},
40                 Some(x) => {
41                     foo = Some(x);
42                 }
43             }
44             println!("'{}'", foo.unwrap());
45         }
46     }
47 }
48
49 fn match_on_upvar() {
50     let mut foo: Option<Box<_>> = Some(box 8);
51     let f = move|| {
52         match foo {
53             None => {},
54             Some(x) => {
55                 foo = Some(x);
56             }
57         }
58         println!("'{}'", foo.unwrap());
59     };
60     f();
61 }
62
63 fn main() {
64     match_on_local();
65     match_on_arg(Some(box 6));
66     match_on_binding();
67     match_on_upvar();
68 }