Skip to content

Commit 233fdb4

Browse files
committed
Some new tests I added.
1 parent 5b74843 commit 233fdb4

16 files changed

+1308
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
error[E0381]: use of possibly uninitialized variable: `t.0`
2+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:25:31
3+
|
4+
LL | println!("{:?} {:?}", t.0, t.1);
5+
| ^^^ use of possibly uninitialized `t.0`
6+
7+
error[E0381]: use of possibly uninitialized variable: `t.1`
8+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:25:36
9+
|
10+
LL | println!("{:?} {:?}", t.0, t.1);
11+
| ^^^ use of possibly uninitialized `t.1`
12+
13+
error[E0381]: use of possibly uninitialized variable: `u.0`
14+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:35:31
15+
|
16+
LL | println!("{:?} {:?}", u.0, u.1);
17+
| ^^^ use of possibly uninitialized `u.0`
18+
19+
error[E0381]: use of possibly uninitialized variable: `u.1`
20+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:35:36
21+
|
22+
LL | println!("{:?} {:?}", u.0, u.1);
23+
| ^^^ use of possibly uninitialized `u.1`
24+
25+
error[E0381]: use of possibly uninitialized variable: `v.x`
26+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:45:31
27+
|
28+
LL | println!("{:?} {:?}", v.x, v.y);
29+
| ^^^ use of possibly uninitialized `v.x`
30+
31+
error[E0381]: use of possibly uninitialized variable: `v.y`
32+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:45:36
33+
|
34+
LL | println!("{:?} {:?}", v.x, v.y);
35+
| ^^^ use of possibly uninitialized `v.y`
36+
37+
error: aborting due to 6 previous errors
38+
39+
For more information about this error, try `rustc --explain E0381`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
error[E0381]: assign to part of possibly uninitialized variable: `t`
2+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:22:9
3+
|
4+
LL | t.0 = S(1);
5+
| ^^^^^^^^^^ use of possibly uninitialized `t`
6+
7+
error[E0381]: assign to part of possibly uninitialized variable: `u`
8+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:32:9
9+
|
10+
LL | u.0 = S(1);
11+
| ^^^^^^^^^^ use of possibly uninitialized `u`
12+
13+
error[E0381]: assign to part of possibly uninitialized variable: `v`
14+
--> $DIR/issue-54499-field-mutation-marks-mut-as-used.rs:42:9
15+
|
16+
LL | v.x = S(1);
17+
| ^^^^^^^^^^ use of possibly uninitialized `v`
18+
19+
error: aborting due to 3 previous errors
20+
21+
For more information about this error, try `rustc --explain E0381`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// revisions: ast nll
2+
3+
// Since we are testing nll migration explicitly as a separate
4+
// revision, don't worry about the --compare-mode=nll on this test.
5+
6+
// ignore-compare-mode-nll
7+
8+
//[ast]compile-flags: -Z borrowck=ast
9+
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
10+
11+
#![warn(unused)]
12+
#[derive(Debug)]
13+
struct S(i32);
14+
15+
type Tuple = (S, i32);
16+
struct Tpair(S, i32);
17+
struct Spair { x: S, y: i32 }
18+
19+
fn main() {
20+
{
21+
let mut t: Tuple;
22+
t.0 = S(1);
23+
//[nll]~^ ERROR assign to part of possibly uninitialized variable: `t` [E0381]
24+
t.1 = 2;
25+
println!("{:?} {:?}", t.0, t.1);
26+
//[ast]~^ ERROR use of possibly uninitialized variable: `t.0` [E0381]
27+
//[ast]~| ERROR use of possibly uninitialized variable: `t.1` [E0381]
28+
}
29+
30+
{
31+
let mut u: Tpair;
32+
u.0 = S(1);
33+
//[nll]~^ ERROR assign to part of possibly uninitialized variable: `u` [E0381]
34+
u.1 = 2;
35+
println!("{:?} {:?}", u.0, u.1);
36+
//[ast]~^ ERROR use of possibly uninitialized variable: `u.0` [E0381]
37+
//[ast]~| ERROR use of possibly uninitialized variable: `u.1` [E0381]
38+
}
39+
40+
{
41+
let mut v: Spair;
42+
v.x = S(1);
43+
//[nll]~^ ERROR assign to part of possibly uninitialized variable: `v` [E0381]
44+
v.y = 2;
45+
println!("{:?} {:?}", v.x, v.y);
46+
//[ast]~^ ERROR use of possibly uninitialized variable: `v.x` [E0381]
47+
//[ast]~| ERROR use of possibly uninitialized variable: `v.y` [E0381]
48+
}
49+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
error[E0382]: use of moved value: `t.0`
2+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:25:31
3+
|
4+
LL | drop(t);
5+
| - value moved here
6+
...
7+
LL | println!("{:?} {:?}", t.0, t.1);
8+
| ^^^ value used here after move
9+
|
10+
= note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
11+
12+
error[E0382]: use of moved value: `t.1`
13+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:25:36
14+
|
15+
LL | drop(t);
16+
| - value moved here
17+
...
18+
LL | println!("{:?} {:?}", t.0, t.1);
19+
| ^^^ value used here after move
20+
|
21+
= note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
22+
23+
error[E0382]: use of moved value: `u.0`
24+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:33:31
25+
|
26+
LL | drop(u);
27+
| - value moved here
28+
...
29+
LL | println!("{:?} {:?}", u.0, u.1);
30+
| ^^^ value used here after move
31+
|
32+
= note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
33+
34+
error[E0382]: use of moved value: `u.1`
35+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:33:36
36+
|
37+
LL | drop(u);
38+
| - value moved here
39+
...
40+
LL | println!("{:?} {:?}", u.0, u.1);
41+
| ^^^ value used here after move
42+
|
43+
= note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
44+
45+
error[E0382]: use of moved value: `v.x`
46+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:41:31
47+
|
48+
LL | drop(v);
49+
| - value moved here
50+
...
51+
LL | println!("{:?} {:?}", v.x, v.y);
52+
| ^^^ value used here after move
53+
|
54+
= note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
55+
56+
error[E0382]: use of moved value: `v.y`
57+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:41:36
58+
|
59+
LL | drop(v);
60+
| - value moved here
61+
...
62+
LL | println!("{:?} {:?}", v.x, v.y);
63+
| ^^^ value used here after move
64+
|
65+
= note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
66+
67+
error: aborting due to 6 previous errors
68+
69+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
error[E0382]: assign to part of moved value: `t`
2+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:23:9
3+
|
4+
LL | drop(t);
5+
| - value moved here
6+
LL | t.0 = S(1);
7+
| ^^^^^^^^^^ value partially assigned here after move
8+
|
9+
= note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
10+
11+
error[E0382]: assign to part of moved value: `u`
12+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:31:9
13+
|
14+
LL | drop(u);
15+
| - value moved here
16+
LL | u.0 = S(1);
17+
| ^^^^^^^^^^ value partially assigned here after move
18+
|
19+
= note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
20+
21+
error[E0382]: assign to part of moved value: `v`
22+
--> $DIR/issue-54499-field-mutation-of-moved-out-with-mut.rs:39:9
23+
|
24+
LL | drop(v);
25+
| - value moved here
26+
LL | v.x = S(1);
27+
| ^^^^^^^^^^ value partially assigned here after move
28+
|
29+
= note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
30+
31+
error: aborting due to 3 previous errors
32+
33+
For more information about this error, try `rustc --explain E0382`.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
// revisions: ast nll
2+
3+
// Since we are testing nll migration explicitly as a separate
4+
// revision, don't worry about the --compare-mode=nll on this test.
5+
6+
// ignore-compare-mode-nll
7+
8+
//[ast]compile-flags: -Z borrowck=ast
9+
//[nll]compile-flags: -Z borrowck=migrate -Z two-phase-borrows
10+
11+
#![warn(unused)]
12+
#[derive(Debug)]
13+
struct S(i32);
14+
15+
type Tuple = (S, i32);
16+
struct Tpair(S, i32);
17+
struct Spair { x: S, y: i32 }
18+
19+
fn main() {
20+
{
21+
let mut t: Tuple = (S(0), 0);
22+
drop(t);
23+
t.0 = S(1);
24+
t.1 = 2;
25+
println!("{:?} {:?}", t.0, t.1);
26+
}
27+
28+
{
29+
let mut u: Tpair = Tpair(S(0), 0);
30+
drop(u);
31+
u.0 = S(1);
32+
u.1 = 2;
33+
println!("{:?} {:?}", u.0, u.1);
34+
}
35+
36+
{
37+
let mut v: Spair = Spair { x: S(0), y: 0 };
38+
drop(v);
39+
v.x = S(1);
40+
v.y = 2;
41+
println!("{:?} {:?}", v.x, v.y);
42+
}
43+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,124 @@
1+
error[E0594]: cannot assign to field `t.0` of immutable binding
2+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:23:9
3+
|
4+
LL | let t: Tuple = (S(0), 0);
5+
| - help: make this binding mutable: `mut t`
6+
LL | drop(t);
7+
LL | t.0 = S(1);
8+
| ^^^^^^^^^^ cannot mutably borrow field of immutable binding
9+
10+
error[E0594]: cannot assign to field `t.1` of immutable binding
11+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:27:9
12+
|
13+
LL | let t: Tuple = (S(0), 0);
14+
| - help: make this binding mutable: `mut t`
15+
...
16+
LL | t.1 = 2;
17+
| ^^^^^^^ cannot mutably borrow field of immutable binding
18+
19+
error[E0594]: cannot assign to field `u.0` of immutable binding
20+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:38:9
21+
|
22+
LL | let u: Tpair = Tpair(S(0), 0);
23+
| - help: make this binding mutable: `mut u`
24+
LL | drop(u);
25+
LL | u.0 = S(1);
26+
| ^^^^^^^^^^ cannot mutably borrow field of immutable binding
27+
28+
error[E0594]: cannot assign to field `u.1` of immutable binding
29+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:42:9
30+
|
31+
LL | let u: Tpair = Tpair(S(0), 0);
32+
| - help: make this binding mutable: `mut u`
33+
...
34+
LL | u.1 = 2;
35+
| ^^^^^^^ cannot mutably borrow field of immutable binding
36+
37+
error[E0594]: cannot assign to field `v.x` of immutable binding
38+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:53:9
39+
|
40+
LL | let v: Spair = Spair { x: S(0), y: 0 };
41+
| - help: make this binding mutable: `mut v`
42+
LL | drop(v);
43+
LL | v.x = S(1);
44+
| ^^^^^^^^^^ cannot mutably borrow field of immutable binding
45+
46+
error[E0594]: cannot assign to field `v.y` of immutable binding
47+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:57:9
48+
|
49+
LL | let v: Spair = Spair { x: S(0), y: 0 };
50+
| - help: make this binding mutable: `mut v`
51+
...
52+
LL | v.y = 2;
53+
| ^^^^^^^ cannot mutably borrow field of immutable binding
54+
55+
error[E0382]: use of moved value: `t.0`
56+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:30:31
57+
|
58+
LL | drop(t);
59+
| - value moved here
60+
...
61+
LL | println!("{:?} {:?}", t.0, t.1);
62+
| ^^^ value used here after move
63+
|
64+
= note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
65+
66+
error[E0382]: use of moved value: `t.1`
67+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:30:36
68+
|
69+
LL | drop(t);
70+
| - value moved here
71+
...
72+
LL | println!("{:?} {:?}", t.0, t.1);
73+
| ^^^ value used here after move
74+
|
75+
= note: move occurs because `t` has type `(S, i32)`, which does not implement the `Copy` trait
76+
77+
error[E0382]: use of moved value: `u.0`
78+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:45:31
79+
|
80+
LL | drop(u);
81+
| - value moved here
82+
...
83+
LL | println!("{:?} {:?}", u.0, u.1);
84+
| ^^^ value used here after move
85+
|
86+
= note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
87+
88+
error[E0382]: use of moved value: `u.1`
89+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:45:36
90+
|
91+
LL | drop(u);
92+
| - value moved here
93+
...
94+
LL | println!("{:?} {:?}", u.0, u.1);
95+
| ^^^ value used here after move
96+
|
97+
= note: move occurs because `u` has type `Tpair`, which does not implement the `Copy` trait
98+
99+
error[E0382]: use of moved value: `v.x`
100+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:60:31
101+
|
102+
LL | drop(v);
103+
| - value moved here
104+
...
105+
LL | println!("{:?} {:?}", v.x, v.y);
106+
| ^^^ value used here after move
107+
|
108+
= note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
109+
110+
error[E0382]: use of moved value: `v.y`
111+
--> $DIR/issue-54499-field-mutation-of-moved-out.rs:60:36
112+
|
113+
LL | drop(v);
114+
| - value moved here
115+
...
116+
LL | println!("{:?} {:?}", v.x, v.y);
117+
| ^^^ value used here after move
118+
|
119+
= note: move occurs because `v` has type `Spair`, which does not implement the `Copy` trait
120+
121+
error: aborting due to 12 previous errors
122+
123+
Some errors occurred: E0382, E0594.
124+
For more information about an error, try `rustc --explain E0382`.

0 commit comments

Comments
 (0)