cannot borrow `self.x` as immutable because `*self` is also borrowed as mutable
问题 First, let the code speak: #[derive(Debug)] struct Bar; #[derive(Debug)] struct Qux { baz: bool } #[derive(Debug)] struct Foo { bars: Vec<Bar>, qux: Qux, } impl Foo { fn get_qux(&mut self) -> &mut Qux { &mut self.qux } fn run(&mut self) { // 1. Fails: let mut qux = self.get_qux(); // 2. Works: // let mut qux = &mut Qux { baz: false }; // 3. Works: // let mut qux = &mut self.qux; let qux_mut = &mut qux; qux_mut.baz = true; for bar in &self.bars { println!(\"{:?}\", bar); } } } fn main() {