Debian Codegraph @

gcc/testsuite/rust/borrowck/tmp.rs

raw
1 // { dg-additional-options "-frust-compile-until=compilation -frust-borrowcheck -fdiagnostics-show-caret -fdiagnostics-show-line-numbers" }
2 // { dg-enable-nn-line-numbers "" }
3
4 #[lang = "sized"]
5 pub trait Sized {}
6
7 fn immutable_borrow_while_immutable_borrowed() {
8 let x = 0;
9 let y = &x;
10 let z = &x;
11 let w = y;
12 }
13
14
15 fn immutable_borrow_while_mutable_borrowed() {
16 let mut x = 0;
17 let y = &mut x;
18 let z = &x; //~ ERROR
19 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
20 let w = y;
21 /*
22 { dg-begin-multiline-output "" }
23 NN | let y = &mut x;
24 | ~
25 | |
26 | borrow occurs here
27 NN | let z = &x; //~ ERROR
28 | ^
29 | |
30 | borrowed value used here
31 { dg-end-multiline-output "" }
32 */
33 }
34
35 fn mutable_borrow_while_immutable_borrowed() {
36 let x = 0;
37 let y = &x;
38 let z = &mut x; //~ ERROR
39 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
40 let w = y;
41 /*
42 { dg-begin-multiline-output "" }
43 NN | let y = &x;
44 | ~
45 | |
46 | borrow occurs here
47 NN | let z = &mut x; //~ ERROR
48 | ^
49 | |
50 | borrowed value used here
51 { dg-end-multiline-output "" }
52 */
53 }
54
55 fn mutable_borrow_while_mutable_borrowed() {
56 let mut x = 0;
57 let y = &mut x;
58 let z = &mut x; //~ ERROR
59 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
60 let w = y;
61 /*
62 { dg-begin-multiline-output "" }
63 NN | let y = &mut x;
64 | ~
65 | |
66 | borrow occurs here
67 NN | let z = &mut x; //~ ERROR
68 | ^
69 | |
70 | borrowed value used here
71 { dg-end-multiline-output "" }
72 */
73 }
74
75 fn immutable_reborrow_while_immutable_borrowed() {
76 let x = 0;
77 let y = &x;
78 let z = &*y;
79 }
80
81 fn immutable_reborrow_while_mutable_borrowed() {
82 let mut x = 0;
83 let y = &mut x;
84 let z = &*y;
85 }
86
87 fn mutable_reborrow_while_immutable_borrowed() {
88 // { dg-error "Cannot reborrow immutable borrow as mutable" "" { target *-*-* } .-1 }
89 let x = 0;
90 let y = &x;
91 let z = &mut *y; //~ ERROR
92 /*
93 { dg-begin-multiline-output "" }
94 NN | fn mutable_reborrow_while_immutable_borrowed() {
95 | ^~
96 { dg-end-multiline-output "" }
97 */
98 }
99
100 fn read_while_mutable_borrowed() {
101 let mut x = 0;
102 let y = &mut x;
103 let z = x; //~ ERROR
104 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
105 let w = y;
106 /*
107 { dg-begin-multiline-output "" }
108 NN | let y = &mut x;
109 | ~
110 | |
111 | borrow occurs here
112 NN | let z = x; //~ ERROR
113 | ^
114 | |
115 | borrowed value used here
116 { dg-end-multiline-output "" }
117 */
118 }
119
120 fn write_while_borrowed() {
121 let mut x = 0;
122 let y = &x;
123 x = 1; //~ ERROR
124 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
125 let z = y;
126 /*
127 { dg-begin-multiline-output "" }
128 NN | let y = &x;
129 | ~
130 | |
131 | borrow occurs here
132 NN | x = 1; //~ ERROR
133 | ^
134 | |
135 | borrowed value used here
136 { dg-end-multiline-output "" }
137 */
138 }
139
140 fn write_while_immutable_borrowed() {
141 let x = 0;
142 let y = &x;
143 x = 1; //~ ERROR
144 // { dg-error "use of borrowed value" "" { target *-*-* } .-1 }
145 let z = y;
146 /*
147 { dg-begin-multiline-output "" }
148 NN | let y = &x;
149 | ~
150 | |
151 | borrow occurs here
152 NN | x = 1; //~ ERROR
153 | ^
154 | |
155 | borrowed value used here
156 { dg-end-multiline-output "" }
157 */
158 }