Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- use std::collections::LinkedList;
- struct Bar {
- ll: LinkedList<Foo>
- }
- struct Foo {}
- impl Bar {
- fn foo_alloc<'a>(&'a mut self) -> &Option<&'a mut Foo> {
- let foo = Foo{};
- self.ll.push_back(foo);
- &self.ll.front_mut()
- }
- }
- error: borrowed value does not live long enough
- --> src/main.rs:14:10
- |
- 14 | &self.ll.front_mut()
- | ^^^^^^^^^^^^^^^^^^^ does not live long enough
- 15 | }
- | - temporary value only lives until here
- |
- note: borrowed value must be valid for the lifetime 'a as defined on the body at 11:59...
- --> src/main.rs:11:60
- |
- 11 | fn foo_alloc<'a>(&'a mut self) -> &Option<&'a mut Foo> {
- | ____________________________________________________________^ starting here...
- 12 | | let foo = Foo{};
- 13 | | self.ll.push_back(foo);
- 14 | | &self.ll.front_mut()
- 15 | | }
- | |_____^ ...ending here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement