]> git.proxmox.com Git - rustc.git/blame - src/test/run-pass/issue-15571.rs
Imported Upstream version 1.0.0~beta
[rustc.git] / src / test / run-pass / issue-15571.rs
CommitLineData
1a4d82fc
JJ
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
14fn match_on_local() {
c34b1796 15 let mut foo: Option<Box<_>> = Some(box 5);
1a4d82fc
JJ
16 match foo {
17 None => {},
18 Some(x) => {
19 foo = Some(x);
20 }
21 }
22 println!("'{}'", foo.unwrap());
23}
24
85aaf69f 25fn match_on_arg(mut foo: Option<Box<i32>>) {
1a4d82fc
JJ
26 match foo {
27 None => {}
28 Some(x) => {
29 foo = Some(x);
30 }
31 }
32 println!("'{}'", foo.unwrap());
33}
34
35fn match_on_binding() {
c34b1796 36 match Some(Box::new(7)) {
1a4d82fc
JJ
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
49fn match_on_upvar() {
c34b1796 50 let mut foo: Option<Box<_>> = Some(box 8);
85aaf69f 51 let f = move|| {
1a4d82fc
JJ
52 match foo {
53 None => {},
54 Some(x) => {
55 foo = Some(x);
56 }
57 }
58 println!("'{}'", foo.unwrap());
59 };
60 f();
61}
62
63fn main() {
64 match_on_local();
85aaf69f 65 match_on_arg(Some(box 6));
1a4d82fc
JJ
66 match_on_binding();
67 match_on_upvar();
68}