Guest User

relations-between-regions-v0

a guest
Jun 21st, 2018
57
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Rust 0.66 KB | None | 0 0
  1. fn main() {
  2.   let mut x: i32 = 17;
  3.   let     y: i32 = 21;
  4.  
  5.   let mut u: Vec<&/* '0 */ i32> = vec![];
  6.   let mut v: Vec<&/* '1 */ i32> = vec![];
  7.  
  8.   /* { // NLL */
  9.  
  10.   let p: &/* '3 */ i32 = &/* '2 */x;
  11.   let q: &/* '5 */ i32 = &/* '4 */y;
  12.  
  13.   let mut r: &/* '6 */ mut Vec<&/* '7 */ i32>;
  14.  
  15.   r = &/* '8 */ mut u;
  16.   r.push(p);
  17.  
  18.   r = &/* '9 */ mut v;
  19.   r.push(q);
  20.  
  21.   /* } // NLL */
  22.  
  23.   x += 1; // <-- Error! can't mutate `x` while borrowed by `u` through `p`
  24.           // If `'0 == '1 == '7`, could the analysis (wrongly) conclude
  25.           // that the borrowing by `v` is also problematic?
  26.  
  27.   take(v);
  28. }
  29.  
  30. fn take<T>(p: T) { /* ... */ }
Add Comment
Please, Sign In to add comment