Why is the mutable reference not moved here?

后端 未结 2 1778
说谎
说谎 2020-12-01 18:37

I was under the impression that mutable references (i.e. &mut T) are always moved. That makes perfect sense, since they allow exclusive mutable access. In t

2条回答
  •  北荒
    北荒 (楼主)
    2020-12-01 19:06

    I asked something along those lines here.

    It seems that in some (many?) cases, instead of a move, a re-borrow takes place. Memory safety is not violated, only the "moved" value is still around. I could not find any docs on that behavior either.

    @Levans opened a github issue here, although I'm not entirely convinced this is just a doc issue: dependably moving out of a &mut reference seems central to Rust's approach of ownership.

提交回复
热议问题