Advertisement
Guest User

Untitled

a guest
Jun 17th, 2019
54
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.70 KB | None | 0 0
  1. pub struct MyStruct<'a> {
  2. pub parent: Option<&'a mut MyStruct<'a>>,
  3. }
  4.  
  5. impl<'a> MyStruct<'a> {
  6. pub fn new() -> Self {
  7. MyStruct { parent: None }
  8. }
  9. }
  10.  
  11. fn main() {
  12. fn inner<'a>(_: &'a mut MyStruct<'a>) {}
  13.  
  14. let mut i = MyStruct::new();
  15. inner(&mut i);
  16. assert!(i.parent.is_none());
  17. }
  18.  
  19. error[E0502]: cannot borrow `i.parent` as immutable because it is also borrowed as mutable
  20. --> src/main.rs:18:13
  21. |
  22. 16 | inner(&mut i);
  23. | ------ mutable borrow occurs here
  24. 17 | }
  25. 18 | assert!(i.parent.is_none());
  26. | ^^^^^^^^
  27. | |
  28. | immutable borrow occurs here
  29. | mutable borrow later used here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement