]> git.lizzy.rs Git - rust.git/blob - src/test/ui/borrowck/borrowck-match-already-borrowed.rs
Auto merge of #54624 - arielb1:evaluate-outlives, r=nikomatsakis
[rust.git] / src / test / ui / borrowck / borrowck-match-already-borrowed.rs
1 // Copyright 2015 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 // revisions: ast mir
12 //[mir]compile-flags: -Z borrowck=mir
13
14 enum Foo {
15     A(i32),
16     B
17 }
18
19 fn match_enum() {
20     let mut foo = Foo::B;
21     let p = &mut foo;
22     let _ = match foo {
23         Foo::B => 1, //[mir]~ ERROR [E0503]
24         _ => 2,
25         Foo::A(x) => x //[ast]~ ERROR [E0503]
26                        //[mir]~^ ERROR [E0503]
27     };
28     drop(p);
29 }
30
31
32 fn main() {
33     let mut x = 1;
34     let r = &mut x;
35     let _ = match x {
36         x => x + 1, //[ast]~ ERROR [E0503]
37                     //[mir]~^ ERROR [E0503]
38         y => y + 2, //[ast]~ ERROR [E0503]
39                     //[mir]~^ ERROR [E0503]
40     };
41     drop(r);
42 }