From 3c9a699af6b28bcd5110e6e8dc23c733a8e0d09c Mon Sep 17 00:00:00 2001 From: Ralf Jung Date: Thu, 29 Feb 2024 18:29:58 +0100 Subject: [PATCH] add const test for ptr::metadata --- tests/ui/consts/const-eval/ub-wide-ptr.rs | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/tests/ui/consts/const-eval/ub-wide-ptr.rs b/tests/ui/consts/const-eval/ub-wide-ptr.rs index 4c90d1c98403a..96be698abf563 100644 --- a/tests/ui/consts/const-eval/ub-wide-ptr.rs +++ b/tests/ui/consts/const-eval/ub-wide-ptr.rs @@ -1,7 +1,7 @@ // ignore-tidy-linelength #![allow(unused)] -use std::mem; +use std::{ptr, mem}; // Strip out raw byte dumps to make comparison platform-independent: //@ normalize-stderr-test "(the raw bytes of the constant) \(size: [0-9]*, align: [0-9]*\)" -> "$1 (size: $$SIZE, align: $$ALIGN)" @@ -145,6 +145,8 @@ const RAW_TRAIT_OBJ_VTABLE_NULL: *const dyn Trait = unsafe { mem::transmute((&92 const RAW_TRAIT_OBJ_VTABLE_INVALID: *const dyn Trait = unsafe { mem::transmute((&92u8, &3u64)) }; //~^ ERROR it is undefined behavior to use this value const RAW_TRAIT_OBJ_CONTENT_INVALID: *const dyn Trait = unsafe { mem::transmute::<_, &bool>(&3u8) } as *const dyn Trait; // ok because raw +// Officially blessed way to get the vtable +const DYN_METADATA: DynMetadata = ptr::metadata::(ptr::null::()); // Const eval fails for these, so they need to be statics to error. static mut RAW_TRAIT_OBJ_VTABLE_NULL_THROUGH_REF: *const dyn Trait = unsafe {