&mut
references located in aliasable memory should be considered frozen
#10445
Labels
&mut
references located in aliasable memory should be considered frozen
#10445
We only permit
&mut
pointees to be mutated if the&mut
is in a unique location (i.e., another&mut
, a local variable, etc). Based on this, it is safe to conclude that the memory referenced by an&mut
pointer found in an aliasable location is frozen. But the borrow checker considers such memory to be unsafe for use. This is overly conservative and prevents important compositional patterns.In particular, I should be able to define a type
BorrowedMap
that looks like this:and now I should be able to implement the
Map<K,V>
trait forBorrowedMap
:However I can't because I get an error at the marked line. This is because
self.map
is an&mut
found inside of an aliasable location (self
) and hence it cannot be considered frozen. But why not? Nobody can mutate it, after all.Note that the maximum lifetime of a freeze would be
'a
(which is sufficient for this case).Nominating.
The text was updated successfully, but these errors were encountered: