about summary refs log tree commit diff
path: root/compiler/rustc_const_eval/src
diff options
context:
space:
mode:
authorTomasz Miąsko <tomasz.miasko@gmail.com>2021-10-30 00:00:00 +0000
committerTomasz Miąsko <tomasz.miasko@gmail.com>2021-11-03 16:43:12 +0100
commitbc4931ed7e98084480b82ef236d6c5c713645ea5 (patch)
tree66af2f3daa9677a105c41c603252a655cd42056b /compiler/rustc_const_eval/src
parentb285e0c5d828d958ac22efa1e82648b178d1cbd5 (diff)
downloadrust-bc4931ed7e98084480b82ef236d6c5c713645ea5.tar.gz
rust-bc4931ed7e98084480b82ef236d6c5c713645ea5.zip
`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.
Diffstat (limited to 'compiler/rustc_const_eval/src')
-rw-r--r--compiler/rustc_const_eval/src/transform/check_consts/resolver.rs11
1 files changed, 5 insertions, 6 deletions
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