0
fn push_val(a: &mut Vec<i32>) {
    a.push(3);
}

fn test_mut_ref() {
    let mut a = vec![1, 2, 3];
    let a_ref = &mut a;
    push_val(a_ref); // &mut Vec<i32> doesn't implement Copy trait
    a_ref.push(2);  // why a_ref still can be used in here?

    let a_ref2 = a_ref;
    println!("{:?}", a_ref); // borrowed after move error
}

why the last line has an borrowed after move error, but push_val(a_ref); a_ref.push(2) no error?

Keith
  • 791
  • 6
  • 12
  • 1
    Does this answer your question? [Do mutable references have move semantics?](https://stackoverflow.com/questions/62960584/do-mutable-references-have-move-semantics) In essence, some places the compiler injects an implicit reborrow, but other times it doesn't. – kmdreko Dec 11 '21 at 07:26

0 Answers0