2017-10-11 38 views
1
struct A; 
impl A { 
    fn foo(&mut self) {} 
} 

fn main() { 
    let mut a = A; 
    let x = &{ &mut a }; 
    x.foo(); 
} 
error[E0389]: cannot borrow data mutably in a `&` reference 
--> src/main.rs:9:5 
    | 
9 |  x.foo(); 
    | ^assignment into an immutable reference 

回答

1

你不能。你有一個不可變的參考,這意味着一切後面的引用是不可變的從引用的所有者的角度來看。如果不是這種情況,那麼對於每個事物只有一個單一的可變引用的整個概念將是微不足道的。

相關問題