]> git.proxmox.com Git - rustc.git/blob - src/test/ui/nll/get_default.rs
New upstream version 1.23.0+dfsg1
[rustc.git] / src / test / ui / nll / get_default.rs
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
16 // compile-flags:-Znll -Zborrowck-mir
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 => {
33 map.set(String::new()); // Just AST errors here
34 }
35 }
36 }
37 }
38
39 fn err(map: &mut Map) -> &String {
40 loop {
41 match map.get() {
42 Some(v) => {
43 map.set(String::new()); // Both AST and MIR error here
44 return v;
45 }
46 None => {
47 map.set(String::new()); // Just AST errors here
48 }
49 }
50 }
51 }
52
53 fn main() { }