Debian Codegraph @

gcc/testsuite/rust/borrowck/test_move_conditional.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 fn test_move_conditional(b1: bool, b2:bool) {
5 struct A {
6 i: i32,
7 }
8
9 let a = A { i: 1 };
10 let b = a;
11 if b1 {
12 let b = a;
13 // { dg-error "use of moved value" "" { target *-*-* } .-1 }
14 /*
15 { dg-begin-multiline-output "" }
16 NN | let b = a;
17 | ~
18 | |
19 | value moved here
20 NN | if b1 {
21 NN | let b = a;
22 | ~
23 | |
24 | value moved here
25 ......
26 NN | let c = a;
27 | ^
28 | |
29 | moved value used here
30 { dg-end-multiline-output "" }
31 */
32 }
33 if b2 {
34 let c = a;
35 // { dg-error "use of moved value" "" { target *-*-* } .-1 }
36 /*
37 { dg-begin-multiline-output "" }
38 NN | let b = a;
39 | ~
40 | |
41 | value moved here
42 NN | if b1 {
43 NN | let b = a;
44 | ^
45 | |
46 | moved value used here
47 ......
48 NN | let c = a;
49 | ~
50 | |
51 | value moved here
52 { dg-end-multiline-output "" }
53 */
54 }
55 }
56
57 fn test_move_fixed(b1: bool, b2:bool) {
58
59 let a = 1; // a is now primitive and can be copied
60 let b = a;
61 if b1 {
62 let b = a;
63 }
64 if b2 {
65 let c = a;
66 }
67 }