]>
Commit | Line | Data |
---|---|---|
abe05a73 XL |
1 | // Copyright 2016 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 | // Basic test for free regions in the NLL code. This test ought to | |
12 | // report an error due to a reborrowing constraint. Right now, we get | |
13 | // a variety of errors from the older, AST-based machinery (notably | |
14 | // borrowck), and then we get the NLL error at the end. | |
15 | ||
83c7162d | 16 | // compile-flags:-Zborrowck=compare |
abe05a73 XL |
17 | |
18 | struct Map { | |
19 | } | |
20 | ||
21 | impl Map { | |
22 | fn get(&self) -> Option<&String> { None } | |
23 | fn set(&mut self, v: String) { } | |
24 | } | |
25 | ||
26 | fn ok(map: &mut Map) -> &String { | |
27 | loop { | |
28 | match map.get() { | |
29 | Some(v) => { | |
30 | return v; | |
31 | } | |
32 | None => { | |
94b46f34 | 33 | map.set(String::new()); // Ideally, this would not error. |
ff7c6d11 | 34 | //~^ ERROR borrowed as immutable (Ast) |
94b46f34 | 35 | //~| ERROR borrowed as immutable (Mir) |
abe05a73 XL |
36 | } |
37 | } | |
38 | } | |
39 | } | |
40 | ||
41 | fn err(map: &mut Map) -> &String { | |
42 | loop { | |
43 | match map.get() { | |
44 | Some(v) => { | |
45 | map.set(String::new()); // Both AST and MIR error here | |
ff7c6d11 XL |
46 | //~^ ERROR borrowed as immutable (Mir) |
47 | //~| ERROR borrowed as immutable (Ast) | |
abe05a73 XL |
48 | return v; |
49 | } | |
50 | None => { | |
94b46f34 | 51 | map.set(String::new()); // Ideally, just AST would error here |
ff7c6d11 | 52 | //~^ ERROR borrowed as immutable (Ast) |
94b46f34 | 53 | //~| ERROR borrowed as immutable (Mir) |
abe05a73 XL |
54 | } |
55 | } | |
56 | } | |
57 | } | |
58 | ||
59 | fn main() { } |