-
Notifications
You must be signed in to change notification settings - Fork 13.6k
Open
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.
Description
While trying to play around with raw::TraitObject
I found this thread internals.rust-lang.org/... and in particular this code example play.rust-lang.org/... which does not work anymore.
Code
I tried this code:
#![feature(raw)]
use std::{mem, ptr, raw};
pub trait Trait {}
struct Struct;
impl Trait for Struct {}
#[allow(dead_code)]
const STRUCT_AS_DYN_TRAIT_VTABLE: *mut () =
unsafe { mem::transmute::<*const dyn Trait, raw::TraitObject>(ptr::null::<Struct>()).vtable };
I expected to see this happen:
I get the vtable as a const.
Instead, this happened:
error: untyped pointers are not allowed in constant
Version it worked on
Probably before c400f75
Edit: added PR number #71665
Version with regression
rustc 1.49.0-nightly (e160e5c 2020-10-14)
Any chance we can get the example code to compile again?
Is there a different way to get the vtable?
Metadata
Metadata
Assignees
Labels
A-const-evalArea: Constant evaluation, covers all const contexts (static, const fn, ...)Area: Constant evaluation, covers all const contexts (static, const fn, ...)A-raw-pointersArea: raw pointers, MaybeUninit, NonNullArea: raw pointers, MaybeUninit, NonNullA-trait-systemArea: Trait systemArea: Trait systemC-bugCategory: This is a bug.Category: This is a bug.T-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.requires-nightlyThis issue requires a nightly compiler in some way.This issue requires a nightly compiler in some way.