]> git.proxmox.com Git - rustc.git/blob - tests/ui/nll/get_default.rs
New upstream version 1.68.2+dfsg1
[rustc.git] / tests / ui / nll / get_default.rs
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
6 struct Map {
7 }
8
9 impl Map {
10 fn get(&self) -> Option<&String> { None }
11 fn set(&mut self, v: String) { }
12 }
13
14 fn ok(map: &mut Map) -> &String {
15 loop {
16 match map.get() {
17 Some(v) => {
18 return v;
19 }
20 None => {
21 map.set(String::new()); // Ideally, this would not error.
22 //~^ ERROR borrowed as immutable
23 }
24 }
25 }
26 }
27
28 fn 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
33 //~^ ERROR borrowed as immutable
34 return v;
35 }
36 None => {
37 map.set(String::new()); // Ideally, just AST would error here
38 //~^ ERROR borrowed as immutable
39 }
40 }
41 }
42 }
43
44 fn main() { }