]> git.lizzy.rs Git - rust.git/blob - src/test/compile-fail/borrowck-lend-flow-match.rs
auto merge of #13967 : richo/rust/features/ICE-fails, r=alexcrichton
[rust.git] / src / test / compile-fail / borrowck-lend-flow-match.rs
1 // Copyright 2012-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 // ignore-pretty -- comments are unfaithfully preserved
12
13 #![allow(unused_variable)]
14 #![allow(dead_assignment)]
15
16 fn cond() -> bool { fail!() }
17 fn link<'a>(v: &'a uint, w: &mut &'a uint) -> bool { *w = v; true }
18
19 fn separate_arms() {
20     // Here both arms perform assignments, but only is illegal.
21
22     let mut x = None;
23     match x {
24         None => {
25             // It is ok to reassign x here, because there is in
26             // fact no outstanding loan of x!
27             x = Some(0);
28         }
29         Some(ref _i) => {
30             x = Some(1); //~ ERROR cannot assign
31         }
32     }
33     x.clone(); // just to prevent liveness warnings
34 }
35
36 fn guard() {
37     // Here the guard performs a borrow. This borrow "infects" all
38     // subsequent arms (but not the prior ones).
39
40     let mut a = box 3;
41     let mut b = box 4;
42     let mut w = &*a;
43     match 22 {
44         _ if cond() => {
45             b = box 5;
46         }
47
48         _ if link(&*b, &mut w) => {
49             b = box 6; //~ ERROR cannot assign
50         }
51
52         _ => {
53             b = box 7; //~ ERROR cannot assign
54         }
55     }
56
57     b = box 8; //~ ERROR cannot assign
58 }
59
60 fn main() {}