]> git.proxmox.com Git - rustc.git/blame - src/test/ui/nll/get_default.rs
Update unsuspicious file list
[rustc.git] / src / test / ui / nll / get_default.rs
CommitLineData
abe05a73
XL
1// Basic test for free regions in the NLL code. This test ought to
2// report an error due to a reborrowing constraint. Right now, we get
3// a variety of errors from the older, AST-based machinery (notably
4// borrowck), and then we get the NLL error at the end.
5
abe05a73
XL
6struct Map {
7}
8
9impl Map {
10 fn get(&self) -> Option<&String> { None }
11 fn set(&mut self, v: String) { }
12}
13
14fn ok(map: &mut Map) -> &String {
15 loop {
16 match map.get() {
17 Some(v) => {
18 return v;
19 }
20 None => {
94b46f34 21 map.set(String::new()); // Ideally, this would not error.
48663c56 22 //~^ ERROR borrowed as immutable
abe05a73
XL
23 }
24 }
25 }
26}
27
28fn err(map: &mut Map) -> &String {
29 loop {
30 match map.get() {
31 Some(v) => {
32 map.set(String::new()); // Both AST and MIR error here
48663c56 33 //~^ ERROR borrowed as immutable
abe05a73
XL
34 return v;
35 }
36 None => {
94b46f34 37 map.set(String::new()); // Ideally, just AST would error here
48663c56 38 //~^ ERROR borrowed as immutable
abe05a73
XL
39 }
40 }
41 }
42}
43
44fn main() { }