addr_of!
grants mutable access, maybe?
The exact set of permissions granted when forming a raw reference is currently undecided https://github.com/rust-lang/rust/issues/56604. To avoid presupposing any particular outcome, adjust the const qualification to be compatible with decision where raw reference constructed from `addr_of!` grants mutable access.
This commit is contained in:
parent
b285e0c5d8
commit
bc4931ed7e
4 changed files with 63 additions and 12 deletions
|
@ -94,11 +94,10 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
fn address_of_allows_mutation(&self, mt: mir::Mutability, place: mir::Place<'tcx>) -> bool {
|
||||
match mt {
|
||||
mir::Mutability::Mut => true,
|
||||
mir::Mutability::Not => self.shared_borrow_allows_mutation(place),
|
||||
}
|
||||
fn address_of_allows_mutation(&self, _mt: mir::Mutability, _place: mir::Place<'tcx>) -> bool {
|
||||
// Exact set of permissions granted by AddressOf is undecided. Conservatively assume that
|
||||
// it might allow mutation until resolution of #56604.
|
||||
true
|
||||
}
|
||||
|
||||
fn ref_allows_mutation(&self, kind: mir::BorrowKind, place: mir::Place<'tcx>) -> bool {
|
||||
|
@ -110,7 +109,7 @@ where
|
|||
}
|
||||
}
|
||||
|
||||
/// `&` and `&raw` only allow mutation if the borrowed place is `!Freeze`.
|
||||
/// `&` only allow mutation if the borrowed place is `!Freeze`.
|
||||
///
|
||||
/// This assumes that it is UB to take the address of a struct field whose type is
|
||||
/// `Freeze`, then use pointer arithmetic to derive a pointer to a *different* field of
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue