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 ( ) {
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- }
Original file line number Diff line number Diff line change 11error[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 |
44LL | v = 1;
55 | ----- first assignment to `v`
6- LL | println!("v={}", v);
6+ ...
77LL | v = 2;
88 | ^^^^^ cannot assign twice to immutable variable
99 |
You can’t perform that action at this time.
0 commit comments