These examples show a sample problem:
fn implicit_reborrow<T>(x: &mut T) -> &mut T { x } fn explicit_reborrow<T>(x: &mut T) -> &mut T { &mut *x } fn implicit_reborrow_bad<T>(x: &mut T) -> &mut T { &mut x } fn explicit_reborrow_bad<T>(x: &mut T) -> &mut T { &mut **&mut x }
In explicit_ versions, it is shown that the compiler outputs via deref coercions .
In _bad versions _bad both errors are the same, and the other two are compiled.
This is either a mistake or a limitation on how implementers are currently implemented in the compiler. The invariance of &mut T over T may have something to do with it, because it leads to the fact that &mut &'a mut T is invariant compared to 'a and, therefore, more restrictive during output than the case with a common reference ( &&'a T ), although rigor is not needed in this situation.
eddyb
source share