Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- fn main() {
- println!("{:?}", {
- let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes[0] = 10; v
- });
- }
- /* ~~~~=== stderr ===~~~~
- Compiling playground v0.0.1 (file:///playground)
- error[E0596]: cannot borrow immutable local variable `v` as mutable
- --> src/main.rs:5:65
- |
- 5 | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes[0] = 10; v
- | - consider changing this to `mut v` ^ cannot borrow mutably
- error[E0506]: cannot assign to `bytes` because it is borrowed
- --> src/main.rs:5:77
- |
- 5 | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes[0] = 10; v
- | ^^^^^^^^^^^^^-----^^^^^
- | | |
- | | borrow of `bytes` occurs here
- | assignment to borrowed `bytes` occurs here
- error[E0506]: cannot assign to `bytes[..]` because it is borrowed
- --> src/main.rs:5:102
- |
- 5 | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes[0] = 10; v
- | ----- ^^^^^^^^^^^^^ assignment to borrowed `bytes[..]` occurs here
- | |
- | borrow of `bytes[..]` occurs here
- error: aborting due to 3 previous errors
- error: Could not compile `playground`.
- To learn more, run the command again with --verbose.
- */
- /* ~~~~=== stdout ===~~~~
- */
Add Comment
Please, Sign In to add comment