diff options
| author | Ralf Jung <post@ralfj.de> | 2022-05-17 17:32:36 +0200 |
|---|---|---|
| committer | Ralf Jung <post@ralfj.de> | 2022-05-17 17:32:36 +0200 |
| commit | 501f5d09a0920c66d50fc898ae7649794ea26fa3 (patch) | |
| tree | d0ba72e0fa0fa2976b81974d2151cdaf64e69c7a /compiler/rustc_const_eval/src/interpret | |
| parent | 735efc0c703812343a5e5d19b600dac73b8a89f0 (diff) | |
| download | rust-501f5d09a0920c66d50fc898ae7649794ea26fa3.tar.gz rust-501f5d09a0920c66d50fc898ae7649794ea26fa3.zip | |
interpret/validity: reject references to uninhabited types
Diffstat (limited to 'compiler/rustc_const_eval/src/interpret')
| -rw-r--r-- | compiler/rustc_const_eval/src/interpret/validity.rs | 17 |
1 files changed, 11 insertions, 6 deletions
diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 2dab9ff8986..8770ed956e6 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -412,22 +412,27 @@ impl<'rt, 'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, ' self.path, err_ub!(AlignmentCheckFailed { required, has }) => { - "an unaligned {} (required {} byte alignment but found {})", - kind, + "an unaligned {kind} (required {} byte alignment but found {})", required.bytes(), has.bytes() }, err_ub!(DanglingIntPointer(0, _)) => - { "a null {}", kind }, + { "a null {kind}" }, err_ub!(DanglingIntPointer(i, _)) => - { "a dangling {} (address 0x{:x} is unallocated)", kind, i }, + { "a dangling {kind} (address 0x{i:x} is unallocated)" }, err_ub!(PointerOutOfBounds { .. }) => - { "a dangling {} (going beyond the bounds of its allocation)", kind }, + { "a dangling {kind} (going beyond the bounds of its allocation)" }, // This cannot happen during const-eval (because interning already detects // dangling pointers), but it can happen in Miri. err_ub!(PointerUseAfterFree(..)) => - { "a dangling {} (use-after-free)", kind }, + { "a dangling {kind} (use-after-free)" }, ); + // Do not allow pointers to uninhabited types. + if place.layout.abi.is_uninhabited() { + throw_validation_failure!(self.path, + { "a {kind} pointing to uninhabited type {}", place.layout.ty } + ) + } // Recursive checking if let Some(ref mut ref_tracking) = self.ref_tracking { // Proceed recursively even for ZST, no reason to skip them! |
