We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent d5c1d37 commit d459912Copy full SHA for d459912
1 file changed
rust/src/main.rs
@@ -276,12 +276,17 @@ fn mutable_function_argument() {
276
let mut a = String::from("a");
277
fn append(arg: &mut String, s: &str) {
278
arg.push_str(s);
279
- // immutable: arg += 1;
280
- //arg + 1 // last value is return value
281
}
282
append(&mut a, "b");
283
append(&mut a, "c");
284
assert_eq!(a, "abc");
+ let b = a;
+ // a is undefined
285
+ let c = b + "d"; // content of b is moved here
286
+ // b is unusable here
287
+ assert_eq!(c, "abcd");
288
+ a = c; // reusing a, because it is mutconstantsable
289
+ assert_eq!(a, "abcd");
290
291
292
#[test]
0 commit comments