|
|
|
|
|
by legerdemain
1261 days ago
|
|
I've posted similar minimal examples before. The first one triggers a move (and then fails to compile), while the second one triggers a reborrow. Sure, you can explicitly write out every instance of reborrowing with `&mut *`. That would require you to understand every instance that triggers it, and would also be unbelievably noisy, since automatic dereferencing and automatic reborrowing are actually incredibly common. > pub fn main() {
> let mut x = String::from("moo");
> let y = &mut x;
> let z = y;
> println!("{:?}", y)
> }
>
> pub fn main() {
> let mut x = String::from("moo");
> let y = &mut x;
> let z: &mut _ = y;
> println!("{:?}", y)
> }
|
|
It's completely optional fearure. You don't have to rely on it. Like auto-insertion of semicolons in JS maybe it's better if you don't. Although likelihood of this biting you is way lower than in case of relying on semicolons autoinsertion.