about summary refs log tree commit diff
diff options
context:
space:
mode:
authorOliver Scherer <github35764891676564198441@oli-obk.de>2019-06-13 17:18:10 +0200
committerOliver Scherer <github35764891676564198441@oli-obk.de>2019-06-19 09:52:36 +0200
commit6229a8f1f6853491808e960a8a88d4396dc391d0 (patch)
tree2da7d6d5ee8c5014ec3a8667bc92f796503df3af
parent521d38adb5610ac0b8da63469630f44691827a3f (diff)
downloadrust-6229a8f1f6853491808e960a8a88d4396dc391d0.tar.gz
rust-6229a8f1f6853491808e960a8a88d4396dc391d0.zip
Elaborate some more on what mutability field means what
-rw-r--r--src/librustc_mir/interpret/intern.rs8
1 files changed, 8 insertions, 0 deletions
diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs
index 98598f0ca30..6ce97ed99ab 100644
--- a/src/librustc_mir/interpret/intern.rs
+++ b/src/librustc_mir/interpret/intern.rs
@@ -181,6 +181,8 @@ for
                     (InternMode::Const, hir::Mutability::MutMutable) =>
                         bug!("const qualif failed to prevent mutable references"),
                 }
+                // Compute the mutability with which we'll start visiting the allocation. This is
+                // what gets changed when we encounter an `UnsafeCell`
                 let mutability = match (self.mutability, mutability) {
                     // The only way a mutable reference actually works as a mutable reference is
                     // by being in a `static mut` directly or behind another mutable reference.
@@ -190,6 +192,7 @@ for
                     (Mutability::Mutable, hir::Mutability::MutMutable) => Mutability::Mutable,
                     _ => Mutability::Immutable,
                 };
+                // Compute the mutability of the allocation
                 let intern_mutability = intern_mutability(
                     self.ecx.tcx.tcx,
                     self.param_env,
@@ -244,6 +247,7 @@ pub fn intern_const_alloc_recursive(
     param_env: ty::ParamEnv<'tcx>,
 ) -> InterpResult<'tcx> {
     let tcx = ecx.tcx;
+    // this `mutability` is the mutability of the place, ignoring the type
     let (mutability, base_intern_mode) = match tcx.static_mutability(def_id) {
         Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static),
         None => (Mutability::Immutable, InternMode::ConstBase),
@@ -255,6 +259,10 @@ pub fn intern_const_alloc_recursive(
     let mut ref_tracking = RefTracking::new((ret, mutability, base_intern_mode));
     let leftover_relocations = &mut FxHashSet::default();
 
+    // This mutability is the combination of the place mutability and the type mutability. If either
+    // is mutable, `alloc_mutability` is mutable. This exists because the entire allocation needs
+    // to be mutable if it contains an `UnsafeCell` anywhere. The other `mutability` exists so that
+    // the visitor does not treat everything outside the `UnsafeCell` as mutable.
     let alloc_mutability = intern_mutability(
         tcx.tcx, param_env, ret.layout.ty, tcx.span, mutability,
     );