Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions compiler/rustc_const_eval/src/interpret/validity.rs
Original file line number Diff line number Diff line change
Expand Up @@ -680,8 +680,11 @@ impl<'rt, 'tcx, M: Machine<'tcx>> ValidityVisitor<'rt, 'tcx, M> {
format!("encountered a {ptr_kind} pointing to uninhabited type {ty}")
)
}
// Recursive checking
if let Some(ref_tracking) = self.ref_tracking.as_deref_mut() {

// Recursive checking (but not inside `MaybeDangling` of course).
if let Some(ref_tracking) = self.ref_tracking.as_deref_mut()
&& !self.may_dangle
{
// Proceed recursively even for ZST, no reason to skip them!
// `!` is a ZST and we want to validate it.
if let Some(ctfe_mode) = self.ctfe_mode {
Expand Down
4 changes: 4 additions & 0 deletions tests/ui/consts/const-eval/valid-const.rs
Original file line number Diff line number Diff line change
@@ -1,10 +1,12 @@
//@ check-pass
//
// Some constants that *are* valid
#![feature(maybe_dangling)]

use std::mem;
use std::ptr::NonNull;
use std::num::NonZero;
use std::mem::MaybeDangling;

const NON_NULL_PTR1: NonNull<u8> = unsafe { mem::transmute(1usize) };
const NON_NULL_PTR2: NonNull<u8> = unsafe { mem::transmute(&0) };
Expand All @@ -14,4 +16,6 @@ const NON_NULL_USIZE: NonZero<usize> = unsafe { mem::transmute(1usize) };

const UNIT: () = ();

const INVALID_INSIDE_MAYBE_DANGLING: MaybeDangling<&bool> = unsafe { std::mem::transmute(&5u8) };

fn main() {}
Loading