|
| 1 | +// Copyright 2014 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 | +struct A { a: int, b: Box<int> } |
| 12 | +struct B { a: Box<int>, b: Box<int> } |
| 13 | + |
| 14 | +fn borrow<T>(_: &T) { } |
| 15 | + |
| 16 | +fn move_after_use() { |
| 17 | + let x = A { a: 1, b: box 2 }; |
| 18 | + drop(x.a); |
| 19 | + drop(x.b); |
| 20 | +} |
| 21 | + |
| 22 | +fn move_after_fu_use() { |
| 23 | + let x = A { a: 1, b: box 2 }; |
| 24 | + let _y = A { b: box 3, .. x }; |
| 25 | + drop(x.b); |
| 26 | +} |
| 27 | + |
| 28 | +fn fu_move_after_use() { |
| 29 | + let x = A { a: 1, b: box 2 }; |
| 30 | + drop(x.a); |
| 31 | + let y = A { a: 3, .. x }; |
| 32 | + drop(y.b); |
| 33 | +} |
| 34 | + |
| 35 | +fn fu_move_after_fu_use() { |
| 36 | + let x = A { a: 1, b: box 2 }; |
| 37 | + let _y = A { b: box 3, .. x }; |
| 38 | + let z = A { a: 4, .. x }; |
| 39 | + drop(z.b); |
| 40 | +} |
| 41 | + |
| 42 | +fn use_after_move() { |
| 43 | + let x = A { a: 1, b: box 2 }; |
| 44 | + drop(x.b); |
| 45 | + drop(x.a); |
| 46 | +} |
| 47 | + |
| 48 | +fn use_after_fu_move() { |
| 49 | + let x = A { a: 1, b: box 2 }; |
| 50 | + let y = A { a: 3, .. x }; |
| 51 | + drop(x.a); |
| 52 | + drop(y.b); |
| 53 | +} |
| 54 | + |
| 55 | +fn fu_use_after_move() { |
| 56 | + let x = A { a: 1, b: box 2 }; |
| 57 | + drop(x.b); |
| 58 | + let _y = A { b: box 3, .. x }; |
| 59 | +} |
| 60 | + |
| 61 | +fn fu_use_after_fu_move() { |
| 62 | + let x = A { a: 1, b: box 2 }; |
| 63 | + let y = A { a: 3, .. x }; |
| 64 | + let _z = A { b: box 3, .. x }; |
| 65 | + drop(y.b); |
| 66 | +} |
| 67 | + |
| 68 | +fn borrow_after_move() { |
| 69 | + let x = A { a: 1, b: box 2 }; |
| 70 | + drop(x.b); |
| 71 | + borrow(&x.a); |
| 72 | +} |
| 73 | + |
| 74 | +fn borrow_after_fu_move() { |
| 75 | + let x = A { a: 1, b: box 2 }; |
| 76 | + let y = A { a: 3, .. x }; |
| 77 | + borrow(&x.a); |
| 78 | + drop(y.b); |
| 79 | +} |
| 80 | + |
| 81 | +fn move_after_borrow() { |
| 82 | + let x = A { a: 1, b: box 2 }; |
| 83 | + borrow(&x.a); |
| 84 | + drop(x.b); |
| 85 | +} |
| 86 | + |
| 87 | +fn fu_move_after_borrow() { |
| 88 | + let x = A { a: 1, b: box 2 }; |
| 89 | + borrow(&x.a); |
| 90 | + let y = A { a: 3, .. x }; |
| 91 | + drop(y.b); |
| 92 | +} |
| 93 | + |
| 94 | +fn mut_borrow_after_mut_borrow() { |
| 95 | + let mut x = A { a: 1, b: box 2 }; |
| 96 | + let y = &mut x.a; |
| 97 | + let z = &mut x.b; |
| 98 | + drop(*y); |
| 99 | + drop(**z); |
| 100 | +} |
| 101 | + |
| 102 | +fn move_after_move() { |
| 103 | + let x = B { a: box 1, b: box 2 }; |
| 104 | + drop(x.a); |
| 105 | + drop(x.b); |
| 106 | +} |
| 107 | + |
| 108 | +fn move_after_fu_move() { |
| 109 | + let x = B { a: box 1, b: box 2 }; |
| 110 | + let y = B { a: box 3, .. x }; |
| 111 | + drop(x.a); |
| 112 | + drop(y.b); |
| 113 | +} |
| 114 | + |
| 115 | +fn fu_move_after_move() { |
| 116 | + let x = B { a: box 1, b: box 2 }; |
| 117 | + drop(x.a); |
| 118 | + let z = B { a: box 3, .. x }; |
| 119 | + drop(z.b); |
| 120 | +} |
| 121 | + |
| 122 | +fn fu_move_after_fu_move() { |
| 123 | + let x = B { a: box 1, b: box 2 }; |
| 124 | + let y = B { b: box 3, .. x }; |
| 125 | + let z = B { a: box 4, .. x }; |
| 126 | + drop(y.a); |
| 127 | + drop(z.b); |
| 128 | +} |
| 129 | + |
| 130 | +fn use_after_assign_after_move() { |
| 131 | + let mut x = A { a: 1, b: box 2 }; |
| 132 | + drop(x.b); |
| 133 | + x = A { a: 3, b: box 4 }; |
| 134 | + drop(*x.b); |
| 135 | +} |
| 136 | + |
| 137 | +fn use_after_field_assign_after_move() { |
| 138 | + let mut x = A { a: 1, b: box 2 }; |
| 139 | + drop(x.b); |
| 140 | + x.b = box 3; |
| 141 | + drop(*x.b); |
| 142 | +} |
| 143 | + |
| 144 | +fn borrow_after_assign_after_move() { |
| 145 | + let mut x = A { a: 1, b: box 2 }; |
| 146 | + drop(x.b); |
| 147 | + x = A { a: 3, b: box 4 }; |
| 148 | + borrow(&x.b); |
| 149 | +} |
| 150 | + |
| 151 | +fn borrow_after_field_assign_after_move() { |
| 152 | + let mut x = A { a: 1, b: box 2 }; |
| 153 | + drop(x.b); |
| 154 | + x.b = box 3; |
| 155 | + borrow(&x.b); |
| 156 | +} |
| 157 | + |
| 158 | +fn move_after_assign_after_move() { |
| 159 | + let mut x = A { a: 1, b: box 2 }; |
| 160 | + let y = x.b; |
| 161 | + x = A { a: 3, b: box 4 }; |
| 162 | + drop(x.b); |
| 163 | + drop(y); |
| 164 | +} |
| 165 | + |
| 166 | +fn move_after_field_assign_after_move() { |
| 167 | + let mut x = A { a: 1, b: box 2 }; |
| 168 | + drop(x.b); |
| 169 | + x.b = box 3; |
| 170 | + drop(x.b); |
| 171 | +} |
| 172 | + |
| 173 | +fn use_after_assign_after_uninit() { |
| 174 | + let mut x: A; |
| 175 | + x = A { a: 1, b: box 2 }; |
| 176 | + drop(x.a); |
| 177 | +} |
| 178 | + |
| 179 | +fn borrow_after_assign_after_uninit() { |
| 180 | + let mut x: A; |
| 181 | + x = A { a: 1, b: box 2 }; |
| 182 | + borrow(&x.a); |
| 183 | +} |
| 184 | + |
| 185 | +fn move_after_assign_after_uninit() { |
| 186 | + let mut x: A; |
| 187 | + x = A { a: 1, b: box 2 }; |
| 188 | + drop(x.b); |
| 189 | +} |
| 190 | + |
| 191 | +fn main() { |
| 192 | + move_after_use(); |
| 193 | + move_after_fu_use(); |
| 194 | + fu_move_after_use(); |
| 195 | + fu_move_after_fu_use(); |
| 196 | + use_after_move(); |
| 197 | + use_after_fu_move(); |
| 198 | + fu_use_after_move(); |
| 199 | + fu_use_after_fu_move(); |
| 200 | + |
| 201 | + borrow_after_move(); |
| 202 | + borrow_after_fu_move(); |
| 203 | + move_after_borrow(); |
| 204 | + fu_move_after_borrow(); |
| 205 | + mut_borrow_after_mut_borrow(); |
| 206 | + |
| 207 | + move_after_move(); |
| 208 | + move_after_fu_move(); |
| 209 | + fu_move_after_move(); |
| 210 | + fu_move_after_fu_move(); |
| 211 | + |
| 212 | + use_after_assign_after_move(); |
| 213 | + use_after_field_assign_after_move(); |
| 214 | + borrow_after_assign_after_move(); |
| 215 | + borrow_after_field_assign_after_move(); |
| 216 | + move_after_assign_after_move(); |
| 217 | + move_after_field_assign_after_move(); |
| 218 | + |
| 219 | + use_after_assign_after_uninit(); |
| 220 | + borrow_after_assign_after_uninit(); |
| 221 | + move_after_assign_after_uninit(); |
| 222 | +} |
| 223 | + |
0 commit comments