Guest User

Untitled

a guest
Apr 26th, 2018
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.93 KB | None | 0 0
  1. fn main() {
  2. println!("{:?}", {
  3. let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes[0] = 10; v
  4. });
  5. }
  6.  
  7.  
  8. /* ~~~~=== stderr ===~~~~
  9. Compiling playground v0.0.1 (file:///playground)
  10. error[E0596]: cannot borrow immutable local variable `v` as mutable
  11. --> src/main.rs:5:65
  12. |
  13. 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
  14. | - consider changing this to `mut v` ^ cannot borrow mutably
  15.  
  16. error[E0506]: cannot assign to `bytes` because it is borrowed
  17. --> src/main.rs:5:77
  18. |
  19. 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
  20. | ^^^^^^^^^^^^^-----^^^^^
  21. | | |
  22. | | borrow of `bytes` occurs here
  23. | assignment to borrowed `bytes` occurs here
  24.  
  25. error[E0506]: cannot assign to `bytes[..]` because it is borrowed
  26. --> src/main.rs:5:102
  27. |
  28. 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
  29. | ----- ^^^^^^^^^^^^^ assignment to borrowed `bytes[..]` occurs here
  30. | |
  31. | borrow of `bytes[..]` occurs here
  32.  
  33. error: aborting due to 3 previous errors
  34.  
  35. error: Could not compile `playground`.
  36.  
  37. To learn more, run the command again with --verbose.
  38.  
  39. */
  40.  
  41. /* ~~~~=== stdout ===~~~~
  42.  
  43. */
Add Comment
Please, Sign In to add comment