Skip to content

Commit 62c3160

Browse files
committed
Adjust assign-imm-local-twice.rs
- Document the test intention, including both the language semantics it is checking, as well as the borrowck diagnostics that this is exercising. - Tag this test with `//@ run-rustfix` as this ui test exercises a suggestion diagnostics to make an immutable local var mutable. - Minor error annotation reformatting.
1 parent 5a79963 commit 62c3160

File tree

3 files changed

+38
-9
lines changed

3 files changed

+38
-9
lines changed

tests/ui/assign-imm-local-twice.fixed

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
//! Check that we do not allow assigning twice to an immutable variable. This test also checks a
2+
//! few pieces of borrowck diagnostics:
3+
//!
4+
//! - A multipart borrowck diagnostics that points out the first assignment to an immutable
5+
//! variable, alongside violating assignments that follow subsequently.
6+
//! - A suggestion diagnostics to make the immutable binding mutable.
7+
8+
//@ run-rustfix
9+
10+
fn main() {
11+
let mut v: isize;
12+
//~^ HELP consider making this binding mutable
13+
//~| SUGGESTION mut
14+
v = 1;
15+
//~^ NOTE first assignment
16+
println!("v={}", v);
17+
v = 2;
18+
//~^ ERROR cannot assign twice to immutable variable
19+
//~| NOTE cannot assign twice to immutable
20+
println!("v={}", v);
21+
}

tests/ui/assign-imm-local-twice.rs

+15-7
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,21 @@
1-
fn test() {
1+
//! Check that we do not allow assigning twice to an immutable variable. This test also checks a
2+
//! few pieces of borrowck diagnostics:
3+
//!
4+
//! - A multipart borrowck diagnostics that points out the first assignment to an immutable
5+
//! variable, alongside violating assignments that follow subsequently.
6+
//! - A suggestion diagnostics to make the immutable binding mutable.
7+
8+
//@ run-rustfix
9+
10+
fn main() {
211
let v: isize;
312
//~^ HELP consider making this binding mutable
413
//~| SUGGESTION mut
5-
v = 1; //~ NOTE first assignment
14+
v = 1;
15+
//~^ NOTE first assignment
616
println!("v={}", v);
7-
v = 2; //~ ERROR cannot assign twice to immutable variable
8-
//~| NOTE cannot assign twice to immutable
17+
v = 2;
18+
//~^ ERROR cannot assign twice to immutable variable
19+
//~| NOTE cannot assign twice to immutable
920
println!("v={}", v);
1021
}
11-
12-
fn main() {
13-
}

tests/ui/assign-imm-local-twice.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
error[E0384]: cannot assign twice to immutable variable `v`
2-
--> $DIR/assign-imm-local-twice.rs:7:5
2+
--> $DIR/assign-imm-local-twice.rs:17:5
33
|
44
LL | v = 1;
55
| ----- first assignment to `v`
6-
LL | println!("v={}", v);
6+
...
77
LL | v = 2;
88
| ^^^^^ cannot assign twice to immutable variable
99
|

0 commit comments

Comments
 (0)