Skip to content

Commit 430327c

Browse files
committed
scope
1 parent a904a2c commit 430327c

File tree

1 file changed

+16
-0
lines changed

1 file changed

+16
-0
lines changed

rust/src/main.rs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,22 @@ fn raw_pointers() {
239239
}
240240
}
241241

242+
#[test]
243+
fn scope() {
244+
let mut a = String::from("a");
245+
fn delete(_arg: String) {
246+
// argument is moved end deleted by destructor
247+
}
248+
if false {
249+
delete(a); // the value is moved here even under the "if false"
250+
}
251+
// value of a is unusable here
252+
a = "1".to_string();
253+
let c = a;
254+
// value of a is unusable here
255+
assert_eq!(c, "1")
256+
}
257+
242258
#[test]
243259
fn mutable_function_argument() {
244260
let mut a = String::from("a");

0 commit comments

Comments
 (0)