-
Notifications
You must be signed in to change notification settings - Fork 13.1k
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
trying to get pointer to extern typed field causes runtime panic #126800
Comments
The code you want cannot be allowed because the offset of the extern type field depends on the alignment of the extern type, which is unknowable. |
hmm, this is an odd situation. it does seem like this should be impossible, since the alignment cannot be known, but it is also one of the primary usecases laid out in the RFC (see the perhaps there should be some way to explicitly "opt in" to the extern type having a known alignment (maybe just by using |
behavior of trailing extern type fields should be added to the list of unresolved questions in the tracking issue #43467 |
You can feel free to comment on the tracking issue, but the behavior you are observing here is very intentional and not a bug in the implementation. We even have a test that the above code pattern panics: https://github.com/rust-lang/rust/blob/c1b336cb6b491b3be02cd821774f03af4992f413/tests/ui/extern/extern-types-field-offset.rs |
then i would contend that the RFC was merged before it was ready, since it contains contradictory examples. indeed, the "Detailed Design" section does not contain many details at all. |
I get an similar error when I use
Correct me if I'm wrong, but |
I tried this code:
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
:Backtrace
The text was updated successfully, but these errors were encountered: