Skip to content

Commit cb591db

Browse files
RalfJungoli-obk
andcommitted
more clear code
Co-authored-by: Oli Scherer <[email protected]>
1 parent a97ab84 commit cb591db

File tree

1 file changed

+6
-11
lines changed

1 file changed

+6
-11
lines changed

compiler/rustc_const_eval/src/interpret/validity.rs

+6-11
Original file line numberDiff line numberDiff line change
@@ -454,20 +454,17 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
454454
// here since we cannot know if there really is an `UnsafeCell` inside
455455
// `Option<UnsafeCell>` -- so we check that in the recursive descent behind this
456456
// reference.
457-
if size == Size::ZERO || tam.mutbl == Mutability::Not {
458-
Mutability::Not
459-
} else {
460-
Mutability::Mut
461-
}
457+
if size == Size::ZERO { Mutability::Not } else { tam.mutbl }
462458
}
463459
};
464460
// Proceed recursively even for ZST, no reason to skip them!
465461
// `!` is a ZST and we want to validate it.
466462
if let Ok((alloc_id, _offset, _prov)) = self.ecx.ptr_try_get_alloc_id(place.ptr()) {
467463
// Let's see what kind of memory this points to.
468-
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id);
464+
// `unwrap` since dangling pointers have already been handled.
465+
let alloc_kind = self.ecx.tcx.try_get_global_alloc(alloc_id).unwrap();
469466
match alloc_kind {
470-
Some(GlobalAlloc::Static(did)) => {
467+
GlobalAlloc::Static(did) => {
471468
// Special handling for pointers to statics (irrespective of their type).
472469
assert!(!self.ecx.tcx.is_thread_local_static(did));
473470
assert!(self.ecx.tcx.is_static(did));
@@ -506,7 +503,7 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
506503
// referring to statics).
507504
return Ok(());
508505
}
509-
Some(GlobalAlloc::Memory(alloc)) => {
506+
GlobalAlloc::Memory(alloc) => {
510507
if alloc.inner().mutability == Mutability::Mut
511508
&& matches!(self.ctfe_mode, Some(CtfeValidationMode::Const { .. }))
512509
{
@@ -525,14 +522,12 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, '
525522
throw_validation_failure!(self.path, MutableRefToImmutable);
526523
}
527524
}
528-
Some(GlobalAlloc::Function(..) | GlobalAlloc::VTable(..)) => {
525+
GlobalAlloc::Function(..) | GlobalAlloc::VTable(..) => {
529526
// These are immutable, we better don't allow mutable pointers here.
530527
if ptr_expected_mutbl == Mutability::Mut {
531528
throw_validation_failure!(self.path, MutableRefToImmutable);
532529
}
533530
}
534-
// Dangling, already handled.
535-
None => bug!(),
536531
}
537532
}
538533
let path = &self.path;

0 commit comments

Comments
 (0)