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