Open purpleposeidon opened 5 years ago
Your last example is different because you are not destructuring anything. The unique reference is simply being coerced to a shared reference. In the first two examples coercion doesn't kick in because Rust thinks that it doesn't have enough type information to apply the coercion. Adding type annotations (let &_: &_ = &mut 0;
) does make things compile. You can use let &mut x = &mut 0;
to destructure unique references directly. This works in any pattern (match
, for
, etc.)
Just a minor papercut & inconsistency. Playground: