Guest User

Untitled

a guest
Apr 26th, 2018
51
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.16 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
  4. });
  5. }
  6.  
  7.  
  8. /* ~~~~=== stderr ===~~~~
  9. Compiling playground v0.0.1 (file:///playground)
  10. error[E0597]: `v` does not live long enough
  11. --> src/main.rs:5:65
  12. |
  13. 4 | / println!("{:?}", {
  14. 5 | | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes
  15. | | ^ borrowed value does not live long enough
  16. 6 | | });
  17. | |_____-_- borrowed value needs to live until here
  18. | |
  19. | `v` dropped here while still borrowed
  20. |
  21. = note: this error originates in a macro outside of the current crate (in Nightly builds, run with -Z external-macro-backtrace for more info)
  22.  
  23. error[E0506]: cannot assign to `bytes` because it is borrowed
  24. --> src/main.rs:5:77
  25. |
  26. 5 | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes
  27. | ^^^^^^^^^^^^^-----^^^^^
  28. | | |
  29. | | borrow of `bytes` occurs here
  30. | assignment to borrowed `bytes` occurs here
  31.  
  32. error[E0505]: cannot move out of `bytes` because it is borrowed
  33. --> src/main.rs:5:102
  34. |
  35. 5 | let v = vec![1, 2, 3, 4, 5]; let mut bytes: &mut [u8] = v.as_mut(); bytes = &mut bytes[2..]; bytes
  36. | ----- ^^^^^ move out of `bytes` occurs here
  37. | |
  38. | borrow of `*bytes` occurs here
  39.  
  40. error: aborting due to 3 previous errors
  41.  
  42. error: Could not compile `playground`.
  43.  
  44. To learn more, run the command again with --verbose.
  45.  
  46. */
  47.  
  48. /* ~~~~=== stdout ===~~~~
  49.  
  50. */
Add Comment
Please, Sign In to add comment