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.
Rollup merge of rust-lang#95807 - TaKO8Ki:suggest-local-var-for-vecto…
…r, r=fee1-dead Suggest adding a local for vector to fix borrowck errors closes rust-lang#95574
- 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