reference icon indicating copy to clipboard operation
reference copied to clipboard

Modify mutable deref rule for `&mut T`

Open chorman0773 opened this issue 9 months ago • 2 comments

This indicates that any movable place expression of type &mut T can be dereferenced to yield a mutable place. Presently the rule only lists variables and fields of variables. However, if a &mut T is contained within a movable Box, it is also valid to deref the &mut T and use the resulting place mutably, even if the Box was immutable. See the following playgrounds:

chorman0773 avatar Mar 13 '25 02:03 chorman0773

https://play.rust-lang.org/?version=stable&mode=debug&edition=2024

I checked something and this might be a bit trickerier. According to [expr.move.movable-place], x.0 is not a movable place (which is correct). However, it can be dereferenced mutably (which the previous wording reflects). I'm not sure how to reconcile both cases without building a completely new inductive list.

chorman0773 avatar Mar 20 '25 17:03 chorman0773

@rustbot author

chorman0773 avatar Mar 20 '25 17:03 chorman0773