Hello,

I have a problem in my code and I can't find a solution. I develop a test case that generate the same error. Any idea?

use std::vec::Vec;
use std::rc::Rc;
use std::cell::RefCell;

struct Test;

impl Test {
    fn match_fn<'a>(&'a self) ->Option<&'a Test> {
        None
    }

    fn test_mutable<'a>(&'a mut self, test: &'a Test) {}
}

fn TestMatchBorrow()    {
    let mut viewList: Vec<~Test> = Vec::new();

    for ref mut test in viewList.mut_iter()    {
        match test.match_fn()   {
            Some(mut borrow_test) => test.test_mutable(borrow_test),
            None => {},
        }
    }

}

#[main]
fn main() {
    TestMatchBorrow();
}

The test struct can't be changed.
If I don't put the borrow_test in test.test_mutable(borrow_test) it compile.

The error :
test_match.rs:22:38: 22:42 error: cannot borrow `***test` as mutable because it is also borrowed as immutable test_match.rs:22 Some(mut borrow_test) => test.test_mutable(borrow_test),
^~~~
test_match.rs:21:15: 21:19 note: previous borrow of `***test` occurs here; the immutable borrow prevents subsequent moves or mutable borrows of `***test` until the borrow ends
test_match.rs:21         match test.match_fn()   {
^~~~
test_match.rs:24:10: 24:10 note: previous borrow ends here
test_match.rs:21         match test.match_fn()   {
test_match.rs:22 Some(mut borrow_test) => test.test_mutable(borrow_test),
test_match.rs:23             None => {},
test_match.rs:24         }

Philippe
_______________________________________________
Rust-dev mailing list
[email protected]
https://mail.mozilla.org/listinfo/rust-dev

Reply via email to