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