Thanks for your help. It works on the test but not in my main program.

I'll try to update the test to make it works like the main program but I have not yet found what make the base code different.

Philippe

Le 24/04/2014 23:06, Artella Coding a écrit :
Hi, the following modified program seems to work (I am using rustc 0.11-pre-nightly (d35804e 2014-04-18 00:01:22 -0700) :


**********************************************************
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 mut 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(&mut borrow_test),
            None => {},
         }
     }

}

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



On Thu, Apr 24, 2014 at 9:23 PM, Philippe Delrieu <[email protected] <mailto:[email protected]>> wrote:

    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 <http://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 <http://test_match.rs:21>         match
    test.match_fn()   {
    ^~~~
    test_match.rs:24:10: 24:10 note: previous borrow ends here
    test_match.rs:21 <http://test_match.rs:21>         match
    test.match_fn()   {
    test_match.rs:22 <http://test_match.rs:22>             Some(mut
    borrow_test) => test.test_mutable(borrow_test),
    test_match.rs:23 <http://test_match.rs:23>             None => {},
    test_match.rs:24 <http://test_match.rs:24>         }

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



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

Reply via email to