Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Incorrect std::mem::size_of_var for extern types #106577

Closed
OpatrilPeter opened this issue Jan 7, 2023 · 3 comments
Closed

Incorrect std::mem::size_of_var for extern types #106577

OpatrilPeter opened this issue Jan 7, 2023 · 3 comments
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` requires-nightly This issue requires a nightly compiler in some way.

Comments

@OpatrilPeter
Copy link

Hello, following code on nightly playground returns zero, indicating extern type behaving like ZST, while in comparison, size_of fails to compile. According to the RFC, panicking or compilation failure should happen, so this behavior seem incorrect.

#![feature(extern_types)]

extern {
    type Foo;
}

pub fn test() -> usize {
    let ptr: *mut Foo = std::ptr::null_mut();
    unsafe{std::mem::size_of_val::<Foo>(&*ptr)}
}
@OpatrilPeter OpatrilPeter added the C-bug Category: This is a bug. label Jan 7, 2023
@clubby789
Copy link
Contributor

@rustbot label +F-extern_types

@rustbot rustbot added the F-extern_types `#![feature(extern_types)]` label Jan 8, 2023
@krtab
Copy link
Contributor

krtab commented Jan 9, 2023

I think this issue is known and discussed here:
#43467 (comment)

@scottmcm scottmcm added the requires-nightly This issue requires a nightly compiler in some way. label Jan 13, 2023
@tmiasko
Copy link
Contributor

tmiasko commented Jul 5, 2024

#118534 turned this into a panic:

thread 'main' panicked at library/core/src/panicking.rs:221:5:
attempted to compute the size or alignment of extern type `Foo`
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
thread caused non-unwinding panic. aborting.
Aborted

@tmiasko tmiasko closed this as completed Jul 5, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
C-bug Category: This is a bug. F-extern_types `#![feature(extern_types)]` requires-nightly This issue requires a nightly compiler in some way.
Projects
None yet
Development

No branches or pull requests

6 participants