Bir oyunda bir varlık sistemi için kod yazmaya çalışıyorum ama bu hatayı alıyorum, böylece kodu aynı şey yapan bir şeye kaynatıyorum. gerçek kodda aynı hata.Yapı yönteminde borç alma hatası hakkında karışık
Neden derleyici bana self.my_list
referansının baz
işlevi bittiğinde kapsam dışı kaldığını anlatıyor.
Benim pas sürümü for
döngü sona erdiğinde kapsam dışında gider ben sanırdım rustc 1.3.0 (9a92aaf19 2015-09-15)
mı?
Compiling tutorial v0.1.0 (file:///C:/Code/Projects/rust/tutorial)
src\main.rs:35:9: 35:21 error: cannot borrow `self.my_list` as mutable because it is also borrowed as immutable
src\main.rs:35 self.my_list.push(Foo { name : "foo" });
^~~~~~~~~~~~
src\main.rs:29:19: 29:31 note: previous borrow of `self.my_list` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `self.my_list` until the borrow ends
src\main.rs:29 for x in &self.my_list {
^~~~~~~~~~~~
note: in expansion of for loop expansion
src\main.rs:29:9: 33:10 note: expansion site
src\main.rs:38:6: 38:6 note: previous borrow ends here
src\main.rs:28 fn Baz(&mut self, name : &'static str) -> Option<&Foo> {
...
src\main.rs:38 }
^
error: aborting due to previous error
Could not compile `tutorial`.
To learn more, run the command again with --verbose.
... –
Bu yalnızca oluşur for döngüsü içindeki başvuruları döndürürsünüz. Sorununuzun MCVE adresi şudur: http://is.gd/dJFkUz –
[Desugared sürümü] (http://is.gd/atsegO) aynı sorunu yaşar. Bu kesinlikle bir hata gibi hissettiriyor ... – Shepmaster