more clear code
Co-authored-by: Oli Scherer <github35764891676564198441@oli-obk.de>
This commit is contained in:
parent
0288a0bfa0
commit
73ce868c7e
1 changed files with 6 additions and 11 deletions
|
@ -454,20 +454,17 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||||
// here since we cannot know if there really is an `UnsafeCell` inside
|
// here since we cannot know if there really is an `UnsafeCell` inside
|
||||||
// `Option<UnsafeCell>` -- so we check that in the recursive descent behind this
|
// `Option<UnsafeCell>` -- so we check that in the recursive descent behind this
|
||||||
// reference.
|
// reference.
|
||||||
if size == Size::ZERO || tam.mutbl == Mutability::Not {
|
if size == Size::ZERO { Mutability::Not } else { tam.mutbl }
|
||||||
Mutability::Not
|
|
||||||
} else {
|
|
||||||
Mutability::Mut
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
// Proceed recursively even for ZST, no reason to skip them!
|
// Proceed recursively even for ZST, no reason to skip them!
|
||||||
// `!` is a ZST and we want to validate it.
|
// `!` is a ZST and we want to validate it.
|
||||||
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr()) {
|
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr()) {
|
||||||
// Let's see what kind of memory this points to.
|
// Let's see what kind of memory this points to.
|
||||||
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id);
|
// `unwrap` since dangling pointers have already been handled.
|
||||||
|
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id).unwrap();
|
||||||
match alloc_kind {
|
match alloc_kind {
|
||||||
Some(GlobalAlloc::Static(did)) => {
|
GlobalAlloc::Static(did) => {
|
||||||
// Special handling for pointers to statics (irrespective of their type).
|
// Special handling for pointers to statics (irrespective of their type).
|
||||||
assert!(!self.ecx.tcx.is_thread_local_static(did));
|
assert!(!self.ecx.tcx.is_thread_local_static(did));
|
||||||
assert!(self.ecx.tcx.is_static(did));
|
assert!(self.ecx.tcx.is_static(did));
|
||||||
|
@ -506,7 +503,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||||
// referring to statics).
|
// referring to statics).
|
||||||
return Ok(());
|
return Ok(());
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Memory(alloc)) => {
|
GlobalAlloc::Memory(alloc) => {
|
||||||
if alloc.inner().mutability == Mutability::Mut
|
if alloc.inner().mutability == Mutability::Mut
|
||||||
&& matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. }))
|
&& matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. }))
|
||||||
{
|
{
|
||||||
|
@ -525,14 +522,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
|
||||||
throw_validation_failure!(self.path, MutableRefToImmutable);
|
throw_validation_failure!(self.path, MutableRefToImmutable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
Some(GlobalAlloc::Function(..) | GlobalAlloc::VTable(..)) => {
|
GlobalAlloc::Function(..) | GlobalAlloc::VTable(..) => {
|
||||||
// These are immutable, we better don't allow mutable pointers here.
|
// These are immutable, we better don't allow mutable pointers here.
|
||||||
if ptr_expected_mutbl == Mutability::Mut {
|
if ptr_expected_mutbl == Mutability::Mut {
|
||||||
throw_validation_failure!(self.path, MutableRefToImmutable);
|
throw_validation_failure!(self.path, MutableRefToImmutable);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// Dangling, already handled.
|
|
||||||
None => bug!(),
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
let path = &self.path;
|
let path = &self.path;
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue