diff options
| author | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2024-12-08 14:01:10 +0800 |
|---|---|---|
| committer | 许杰友 Jieyou Xu (Joe) <39484203+jieyouxu@users.noreply.github.com> | 2024-12-08 15:32:04 +0800 |
| commit | 62c3160a2981186e67932bfc693743d0152b4723 (patch) | |
| tree | 5b841705c499b7a4141285622128184291913136 | |
| parent | 5a79963179a2aafb60342144abb02c17262a1f43 (diff) | |
| download | rust-62c3160a2981186e67932bfc693743d0152b4723.tar.gz rust-62c3160a2981186e67932bfc693743d0152b4723.zip | |
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.
| -rw-r--r-- | tests/ui/assign-imm-local-twice.fixed | 21 | ||||
| -rw-r--r-- | tests/ui/assign-imm-local-twice.rs | 22 | ||||
| -rw-r--r-- | tests/ui/assign-imm-local-twice.stderr | 4 |
3 files changed, 38 insertions, 9 deletions
diff --git a/tests/ui/assign-imm-local-twice.fixed b/tests/ui/assign-imm-local-twice.fixed new file mode 100644 index 00000000000..dca994141bb --- /dev/null +++ b/tests/ui/assign-imm-local-twice.fixed @@ -0,0 +1,21 @@ +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { + let mut v: isize; + //~^ HELP consider making this binding mutable + //~| SUGGESTION mut + v = 1; + //~^ NOTE first assignment + println!("v={}", v); + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable + println!("v={}", v); +} diff --git a/tests/ui/assign-imm-local-twice.rs b/tests/ui/assign-imm-local-twice.rs index b2dfeb564d9..43437fa69fa 100644 --- a/tests/ui/assign-imm-local-twice.rs +++ b/tests/ui/assign-imm-local-twice.rs @@ -1,13 +1,21 @@ -fn test() { +//! Check that we do not allow assigning twice to an immutable variable. This test also checks a +//! few pieces of borrowck diagnostics: +//! +//! - A multipart borrowck diagnostics that points out the first assignment to an immutable +//! variable, alongside violating assignments that follow subsequently. +//! - A suggestion diagnostics to make the immutable binding mutable. + +//@ run-rustfix + +fn main() { let v: isize; //~^ HELP consider making this binding mutable //~| SUGGESTION mut - v = 1; //~ NOTE first assignment + v = 1; + //~^ NOTE first assignment println!("v={}", v); - v = 2; //~ ERROR cannot assign twice to immutable variable - //~| NOTE cannot assign twice to immutable + v = 2; + //~^ ERROR cannot assign twice to immutable variable + //~| NOTE cannot assign twice to immutable println!("v={}", v); } - -fn main() { -} diff --git a/tests/ui/assign-imm-local-twice.stderr b/tests/ui/assign-imm-local-twice.stderr index fda3aa3de1b..0a2138d0b96 100644 --- a/tests/ui/assign-imm-local-twice.stderr +++ b/tests/ui/assign-imm-local-twice.stderr @@ -1,9 +1,9 @@ error[E0384]: cannot assign twice to immutable variable `v` - --> $DIR/assign-imm-local-twice.rs:7:5 + --> $DIR/assign-imm-local-twice.rs:17:5 | LL | v = 1; | ----- first assignment to `v` -LL | println!("v={}", v); +... LL | v = 2; | ^^^^^ cannot assign twice to immutable variable | |
