Open
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?