-
- Notifications
You must be signed in to change notification settings - Fork 14.2k
Open
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-extern_types`#![feature(extern_types)]``#![feature(extern_types)]`
Description
I tried this code:
#![feature(extern_types)] extern { type Opaque; } struct Thing { _pad: u8, o: Opaque, } fn main() { let v = b"a"; let x: &Thing = unsafe { std::mem::transmute(&v) }; let field_ptr = &x.o as *const Opaque; println!("{:X}", field_ptr as usize) }I expected to see this happen: printing a stack address
Instead, this happened: panic: attempted to compute the size or alignment of extern type
Context
one of the main usecases for extern types is representing trailing fields of variable size for C ffi. this bug completely makes this impossible. it also panics during a piece of safe code that should be infallible. this panic does not occur if the extern type is the only field.
Meta
rustc --version --verbose:
rustc 1.80.0-nightly (debd22da6 2024-05-29) binary: rustc commit-hash: debd22da66cfa97c74040ebf68e420672ac8560e commit-date: 2024-05-29 host: x86_64-unknown-linux-gnu release: 1.80.0-nightly LLVM version: 18.1.6 Backtrace
Compiling playground v0.0.1 (/playground) Finished `dev` profile [unoptimized + debuginfo] target(s) in 0.48s Running `target/debug/playground` thread 'main' panicked at library/core/src/panicking.rs:221:5: attempted to compute the size or alignment of extern type `Opaque` stack backtrace: 0: rust_begin_unwind at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/std/src/panicking.rs:661:5 1: core::panicking::panic_nounwind_fmt::runtime at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/panicking.rs:112:18 2: core::panicking::panic_nounwind_fmt at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/panicking.rs:122:5 3: core::panicking::panic_nounwind at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/panicking.rs:221:5 4: playground::main at ./[src/main.rs:14](https://play.rust-lang.org/?version=nightly&mode=debug&edition=2021#):21 5: core::ops::function::FnOnce::call_once at /rustc/684b3553f70148ded97a80371c2405984d4f6aa7/library/core/src/ops/function.rs:250:5 note: Some details are omitted, run with `RUST_BACKTRACE=full` for a verbose backtrace. thread caused non-unwinding panic. aborting. Metadata
Metadata
Assignees
Labels
C-discussionCategory: Discussion or questions that doesn't represent real issues.Category: Discussion or questions that doesn't represent real issues.F-extern_types`#![feature(extern_types)]``#![feature(extern_types)]`