]> git.lizzy.rs Git - rust.git/blob - src/test/ui/nll/closure-borrow-spans.rs
Auto merge of #54720 - davidtwco:issue-51191, r=nikomatsakis
[rust.git] / src / test / ui / nll / closure-borrow-spans.rs
1 // Copyright 2018 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 // check that existing borrows due to a closure capture give a special note
12
13 #![feature(nll)]
14
15 fn move_while_borrowed(x: String) {
16     let f = || x.len();
17     let y = x; //~ ERROR
18     f.use_ref();
19 }
20
21 fn borrow_mut_while_borrowed(mut x: i32) {
22     let f = || x;
23     let y = &mut x; //~ ERROR
24     f.use_ref();
25 }
26
27 fn drop_while_borrowed() {
28     let f;
29     {
30         let x = 1;
31         f = || x; //~ ERROR
32     }
33     f.use_ref();
34 }
35
36 fn assign_while_borrowed(mut x: i32) {
37     let f = || x;
38     x = 1; //~ ERROR
39     f.use_ref();
40 }
41
42 fn copy_while_borrowed_mut(mut x: i32) {
43     let f = || x = 0;
44     let y = x; //~ ERROR
45     f.use_ref();
46 }
47
48 fn borrow_while_borrowed_mut(mut x: i32) {
49     let f = || x = 0;
50     let y = &x; //~ ERROR
51     f.use_ref();
52 }
53
54 fn borrow_mut_while_borrowed_mut(mut x: i32) {
55     let f = || x = 0;
56     let y = &mut x; //~ ERROR
57     f.use_ref();
58 }
59
60 fn drop_while_borrowed_mut() {
61     let f;
62     {
63         let mut x = 1;
64         f = || x = 0; //~ ERROR
65     }
66     f.use_ref();
67 }
68
69 fn assign_while_borrowed_mut(mut x: i32) {
70     let f = || x = 0;
71     x = 1; //~ ERROR
72     f.use_ref();
73 }
74
75 fn copy_while_borrowed_unique(x: &mut i32) {
76     let f = || *x = 0;
77     let y = x; //~ ERROR
78     f.use_ref();
79 }
80
81 fn borrow_while_borrowed_unique(x: &mut i32) {
82     let f = || *x = 0;
83     let y = &x; //~ ERROR
84     f.use_ref();
85 }
86
87 fn borrow_mut_while_borrowed_unique(mut x: &mut i32) {
88     let f = || *x = 0;
89     let y = &mut x; //~ ERROR
90     f.use_ref();
91 }
92
93 fn drop_while_borrowed_unique() {
94     let mut z = 1;
95     let f;
96     {
97         let x = &mut z;
98         f = || *x = 0; //~ ERROR
99     }
100     f.use_ref();
101 }
102
103 fn assign_while_borrowed_unique(x: &mut i32) {
104     let f = || *x = 0;
105     *x = 1; //~ ERROR
106     f.use_ref();
107 }
108
109 fn main() {}
110
111 trait Fake { fn use_mut(&mut self) { } fn use_ref(&self) { }  }
112 impl<T> Fake for T { }