Advertisement
Guest User

Untitled

a guest
Feb 22nd, 2017
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. use std::collections::LinkedList;
  2.  
  3. struct Bar {
  4. ll: LinkedList<Foo>
  5. }
  6.  
  7. struct Foo {}
  8.  
  9.  
  10. impl Bar {
  11. fn foo_alloc<'a>(&'a mut self) -> &Option<&'a mut Foo> {
  12. let foo = Foo{};
  13. self.ll.push_back(foo);
  14. &self.ll.front_mut()
  15. }
  16. }
  17.  
  18. error: borrowed value does not live long enough
  19. --> src/main.rs:14:10
  20. |
  21. 14 | &self.ll.front_mut()
  22. | ^^^^^^^^^^^^^^^^^^^ does not live long enough
  23. 15 | }
  24. | - temporary value only lives until here
  25. |
  26. note: borrowed value must be valid for the lifetime 'a as defined on the body at 11:59...
  27. --> src/main.rs:11:60
  28. |
  29. 11 | fn foo_alloc<'a>(&'a mut self) -> &Option<&'a mut Foo> {
  30. | ____________________________________________________________^ starting here...
  31. 12 | | let foo = Foo{};
  32. 13 | | self.ll.push_back(foo);
  33. 14 | | &self.ll.front_mut()
  34. 15 | | }
  35. | |_____^ ...ending here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement