Why is there no error when displaying a variable that has been mutably referenced?

Type-wise, yes, if you have a b: &T, then &*b will also be a &T.

When I had let temp = &*dom; I was going from a &mut T to a &T though, and those are different types. That said, it will still happen automatically if you do let temp: &_ = dom -- if a shared reference is expected but an exclusive reference is supplied.

But sometimes a &mut _ will be moved and not automatically reborrowed, in which case you may need to perform the reborrow "manually" with &mut *variable. Here's a recent example.

1 Like