From 9e3fbcfd571d3ed4c0729a1ae822377bc075fcd6 Mon Sep 17 00:00:00 2001 From: Oliver Scherer Date: Tue, 11 Jun 2019 16:17:08 +0200 Subject: [PATCH] Merge `StaticMut` and `Static` logic --- src/librustc_mir/interpret/intern.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/librustc_mir/interpret/intern.rs b/src/librustc_mir/interpret/intern.rs index a7aee9407a49..c450e3be1dda 100644 --- a/src/librustc_mir/interpret/intern.rs +++ b/src/librustc_mir/interpret/intern.rs @@ -44,9 +44,9 @@ struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> { #[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)] enum InternMode { - /// Mutable references don't change the `mutability` field to `Immutable` - StaticMut, - /// Mutable references must in fact be immutable due to their surrounding immutability + /// Mutable references must in fact be immutable due to their surrounding immutability in a + /// `static`. In a `static mut` we start out as mutable and thus can also contain further `&mtu` + /// that will actually be treated as mutable. Static, /// UnsafeCell is OK in the value of a constant, but not behind references in a constant ConstBase, @@ -171,10 +171,10 @@ for // This is not an inherent limitation, but one that we know to be true, because // const qualification enforces it. We can lift it in the future. match (self.mode, mutability) { - // all is "good and well" in the unsoundness of `static mut` - (InternMode::StaticMut, _) => {}, // immutable references are fine everywhere (_, hir::Mutability::MutImmutable) => {}, + // all is "good and well" in the unsoundness of `static mut` + // mutable references are ok in `static`. Either they are treated as immutable // because they are behind an immutable one, or they are behind an `UnsafeCell` // and thus ok. @@ -251,7 +251,7 @@ pub fn intern_const_alloc_recursive( Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static), None => (Mutability::Immutable, InternMode::ConstBase), // `static mut` doesn't care about interior mutability, it's mutable anyway - Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::StaticMut), + Some(hir::Mutability::MutMutable) => (Mutability::Mutable, InternMode::Static), }; // type based interning