mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
const validity checking: do not recurse to references inside MaybeDangling
This commit is contained in:
@@ -680,8 +680,11 @@ fn check_safe_pointer(
|
||||
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 {
|
||||
|
||||
@@ -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) };
|
||||
@@ -14,4 +16,6 @@
|
||||
|
||||
const UNIT: () = ();
|
||||
|
||||
const INVALID_INSIDE_MAYBE_DANGLING: MaybeDangling<&bool> = unsafe { std::mem::transmute(&5u8) };
|
||||
|
||||
fn main() {}
|
||||
|
||||
Reference in New Issue
Block a user