kani icon indicating copy to clipboard operation
kani copied to clipboard

DST example fails to codegen

Open adpaco-aws opened this issue 4 years ago • 1 comments

The following example from The Rustonomicon/Data Layout/Exotically Sized Types/47.rs shown below

// compile-flags: --edition 2018
#![allow(unused)]
struct MySuperSliceable<T: ?Sized> {
    info: u32,
    data: T,
}

pub fn main() {
    let sized: MySuperSliceable<[u8; 8]> = MySuperSliceable {
        info: 17,
        data: [0; 8],
    };

    let dynamic: &MySuperSliceable<[u8]> = &sized;

    // prints: "17 [0, 0, 0, 0, 0, 0, 0, 0]"
    println!("{} {:?}", dynamic.info, &dynamic.data);
}

fails to codegen with

thread 'rustc' panicked at 'Only an array can be cast to a slice.  Found types Adt(MySuperSliceable, [[u8; 8]]) and Adt(MySuperSliceable, [[u8]])', compiler/rustc_codegen_rmc/src/codegen/rvalue.rs:1076:37
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace

adpaco-aws avatar Oct 19 '21 20:10 adpaco-aws

Still crashes with the same signature as of af11d38d93a.

zhassan-aws avatar Mar 16 '22 23:03 zhassan-aws