#[repr(transparent)] initial implementation#4650
Open
Polygonalr wants to merge 2 commits into
Open
Conversation
gcc/rust/ChangeLog: * typecheck/rust-tyty.h (TyTy::ADTType::ReprKind): Add TRANSPARENT variant. * typecheck/rust-hir-type-check-base.cc (TypeCheckBase::parse_repr_options): Add parsing of transparent repr, throw error for invalid repr. * typecheck/rust-hir-type-check-item.cc (TypeCheckItem::visit (StructStruct)): Throw error if #[repr(transparent)] struct/enum has more than 1 field. Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
gcc/rust/ChangeLog: * backend/rust-compile-expr.h (CompileExpr::compile_transparent_field_access): New helper function. * backend/rust-compile-expr.cc (CompileExpr::compile_transparent_field_access): Implement helper function for accessing the field of #[repr(transparent)] ADTs. (CompileExpr::visit (HIR::StructExprStructFields)): Support struct field construction properly for #[repr(transparent)] structs. (CompileExpr::visit (HIR::FieldAccessExpr)): Implement proper compilation of field access for #[repr(transparent)] ADTs. * backend/rust-compile-type.cc (TyTyResolveCompile::visit (TyTy::ADTType)): Implement proper compilation of typing for #[repr(transparent)] ADTs. Signed-Off-By: Yap Zhi Heng <yapzhhg@gmail.com>
Collaborator
|
rust-lang/rust#77841 Seems like at most one field can be non-1-ZST (zero sized type with alignment 1). That non-1-ZST type can itself be a ZST. If there are no non-1-ZST types, it acts like Also, it looks like much more recent versions of rustc warn/error when the user tries to rely on certain types being 1-ZSTs. I'd figure that could be left for later though. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This is needed for for #4565, because#4565 got merged, this PR will also include a fix for a mistake I made there.CStris implemented with#[repr(transparent)]attribute.Note 1: Type-checking doesn't support extra zero-sized members yet, e.g.
Uniquestruct incore/src/ptr/unique.rs:I can open an issue for this after this gets merged.
Note 2: I need someone who's more experienced in Rust to confirm the behavior of transparent structs with 0 fields, since 0-field transparent structs are present in both
coreandkernel. Added a comment regarding in my commit that for now.