From bc4931ed7e98084480b82ef236d6c5c713645ea5 Mon Sep 17 00:00:00 2001 From: Tomasz Miąsko Date: Sat, 30 Oct 2021 00:00:00 +0000 Subject: `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. --- .../rustc_const_eval/src/transform/check_consts/resolver.rs | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'compiler/rustc_const_eval/src') diff --git a/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs b/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs index 2420f31ac08..fcce829eba4 100644 --- a/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs +++ b/compiler/rustc_const_eval/src/transform/check_consts/resolver.rs @@ -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 -- cgit 1.4.1-3-g733a5