Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- pub struct MyStruct<'a> {
- pub parent: Option<&'a mut MyStruct<'a>>,
- }
- impl<'a> MyStruct<'a> {
- pub fn new() -> Self {
- MyStruct { parent: None }
- }
- }
- fn main() {
- fn inner<'a>(_: &'a mut MyStruct<'a>) {}
- let mut i = MyStruct::new();
- inner(&mut i);
- assert!(i.parent.is_none());
- }
- error[E0502]: cannot borrow `i.parent` as immutable because it is also borrowed as mutable
- --> src/main.rs:18:13
- |
- 16 | inner(&mut i);
- | ------ mutable borrow occurs here
- 17 | }
- 18 | assert!(i.parent.is_none());
- | ^^^^^^^^
- | |
- | immutable borrow occurs here
- | mutable borrow later used here
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement