Borrow checker prohibits two mutually exclusive mutable borrows

An alternate workaround is to use a ref mut pattern. This compiles with the latest stable compiler:

fn last(&mut self) -> &mut Self {
    if let Some(ref mut next) = self.next {
        return next.last();
    }
    self
}

(See also this recent topic.)

1 Like