Merge StaticMut
and Static
logic
This commit is contained in:
parent
d6fa4070be
commit
9e3fbcfd57
1 changed files with 6 additions and 6 deletions
|
@ -44,9 +44,9 @@ struct InternVisitor<'rt, 'a: 'rt, 'mir: 'rt, 'tcx: 'a+'rt+'mir> {
|
||||||
|
|
||||||
#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)]
|
#[derive(Copy, Clone, Debug, PartialEq, Hash, Eq)]
|
||||||
enum InternMode {
|
enum InternMode {
|
||||||
/// Mutable references don't change the `mutability` field to `Immutable`
|
/// Mutable references must in fact be immutable due to their surrounding immutability in a
|
||||||
StaticMut,
|
/// `static`. In a `static mut` we start out as mutable and thus can also contain further `&mtu`
|
||||||
/// Mutable references must in fact be immutable due to their surrounding immutability
|
/// that will actually be treated as mutable.
|
||||||
Static,
|
Static,
|
||||||
/// UnsafeCell is OK in the value of a constant, but not behind references in a constant
|
/// UnsafeCell is OK in the value of a constant, but not behind references in a constant
|
||||||
ConstBase,
|
ConstBase,
|
||||||
|
@ -171,10 +171,10 @@ for
|
||||||
// This is not an inherent limitation, but one that we know to be true, because
|
// 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.
|
// const qualification enforces it. We can lift it in the future.
|
||||||
match (self.mode, mutability) {
|
match (self.mode, mutability) {
|
||||||
// all is "good and well" in the unsoundness of `static mut`
|
|
||||||
(InternMode::StaticMut, _) => {},
|
|
||||||
// immutable references are fine everywhere
|
// immutable references are fine everywhere
|
||||||
(_, hir::Mutability::MutImmutable) => {},
|
(_, 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
|
// 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`
|
// because they are behind an immutable one, or they are behind an `UnsafeCell`
|
||||||
// and thus ok.
|
// and thus ok.
|
||||||
|
@ -251,7 +251,7 @@ pub fn intern_const_alloc_recursive(
|
||||||
Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static),
|
Some(hir::Mutability::MutImmutable) => (Mutability::Immutable, InternMode::Static),
|
||||||
None => (Mutability::Immutable, InternMode::ConstBase),
|
None => (Mutability::Immutable, InternMode::ConstBase),
|
||||||
// `static mut` doesn't care about interior mutability, it's mutable anyway
|
// `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
|
// type based interning
|
||||||
|
|
Loading…
Reference in a new issue