Rust: wrong borrow order? -


while programming sudoku solver in rust had issue code related borrowing. while issue easy solve (with little bit of verbosity), seemed strange me compiler didn't accept first code.

it difficult explain problem is, have made little example

use io::stdio::println;  struct dog; impl dog {     fn bark(&self, text: &str) {         println(text);     }      fn get_text(&mut self) -> ~str {         ~"some text"     } }  fn main() {     let mut dog = dog;      // causes error     dog.bark(dog.get_text());      // allowed     let text = dog.get_text();     dog.bark(text); } 

is bug? if not, why borrow checker enforce coding way?

yes, bug: #6268.

the borrow checker doesn't seem understand arguments evaluated time original method called , thinks &mut self of get_text aliasing &self of bark (and having aliasing &mut pointer illegal).


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -