File tree Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Expand file tree Collapse file tree 3 files changed +38
-9
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change 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 ( ) {
2
11
let v: isize ;
3
12
//~^ HELP consider making this binding mutable
4
13
//~| SUGGESTION mut
5
- v = 1 ; //~ NOTE first assignment
14
+ v = 1 ;
15
+ //~^ NOTE first assignment
6
16
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
9
20
println ! ( "v={}" , v) ;
10
21
}
11
-
12
- fn main ( ) {
13
- }
Original file line number Diff line number Diff line change 1
1
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
3
3
|
4
4
LL | v = 1;
5
5
| ----- first assignment to `v`
6
- LL | println!("v={}", v);
6
+ ...
7
7
LL | v = 2;
8
8
| ^^^^^ cannot assign twice to immutable variable
9
9
|
You can’t perform that action at this time.
0 commit comments