forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
suggest adding a local for vector to fix borrowck errors
- Loading branch information
Showing
6 changed files
with
109 additions
and
9 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let mut vec = vec![0u32; 420]; | ||
vec[vec.len() - 1] = 123; //~ ERROR cannot borrow `vec` as immutable because it is also borrowed as mutable | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0502]: cannot borrow `vec` as immutable because it is also borrowed as mutable | ||
--> $DIR/suggest-local-var-for-vector.rs:3:9 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ----^^^^^^^^^----- | ||
| | | | ||
| | immutable borrow occurs here | ||
| mutable borrow occurs here | ||
| mutable borrow later used here | ||
| | ||
help: try adding a local storing this... | ||
--> $DIR/suggest-local-var-for-vector.rs:3:9 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ^^^^^^^^^ | ||
help: ...and then using that local here | ||
--> $DIR/suggest-local-var-for-vector.rs:3:5 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0502`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
fn main() { | ||
let mut vec = vec![0u32; 420]; | ||
vec[vec.len() - 1] = 123; //~ ERROR cannot borrow `vec` as immutable because it is also borrowed as mutable | ||
} |
24 changes: 24 additions & 0 deletions
24
src/test/ui/borrowck/suggest-storing-local-var-for-vector.stderr
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
error[E0502]: cannot borrow `vec` as immutable because it is also borrowed as mutable | ||
--> $DIR/suggest-storing-local-var-for-vector.rs:3:9 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ----^^^^^^^^^----- | ||
| | | | ||
| | immutable borrow occurs here | ||
| mutable borrow occurs here | ||
| mutable borrow later used here | ||
| | ||
help: try adding a local storing this... | ||
--> $DIR/suggest-storing-local-var-for-vector.rs:3:9 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ^^^^^^^^^ | ||
help: ...and then using that local here | ||
--> $DIR/suggest-storing-local-var-for-vector.rs:3:5 | ||
| | ||
LL | vec[vec.len() - 1] = 123; | ||
| ^^^^^^^^^^^^^^^^^^ | ||
|
||
error: aborting due to previous error | ||
|
||
For more information about this error, try `rustc --explain E0502`. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters