Borrow checker limitation?
⚓ Rust 📅 2025-09-23 👤 surdeus 👁️ 9I'm trying to code something that looks like the following code, but I get an errors saying that self is already borrowed when I'm calling the second method.
I don't understand what happen here, the code seams correct. Also is there any workaround for this?
struct Foo;
impl Foo {
fn get_mut(&mut self) -> Option<&mut str> {
if let Some(x) = self.find_1_mut() {
return Some(x);
}
if let Some(x) = self.find_2_mut() { // Error: `self` already borrowed
return Some(x);
}
None
}
fn find_1_mut(&mut self) -> Option<&mut str> {
todo!();
}
fn find_2_mut(&mut self) -> Option<&mut str> {
todo!();
}
}
1 post - 1 participant
🏷️ Rust_feed