Skip to content

Handle constants of nested transparent types#958

Merged
emilio merged 1 commit intomozilla:masterfrom
scovich:nested-transparent-const
May 26, 2024
Merged

Handle constants of nested transparent types#958
emilio merged 1 commit intomozilla:masterfrom
scovich:nested-transparent-const

Conversation

@scovich
Copy link
Copy Markdown
Contributor

@scovich scovich commented May 17, 2024

When defining a constant of multiply-nested transparent struct type, the struct is reduced to typedefs and so the extra layers of constant initializer need to be removed. The existing code only removed one layer. Fixed by changing the check to a loop.

Without the fix, a declaration like this:

#[repr(transparent)]
struct TransparentStruct { field: u8 }

#[repr(transparent)]
struct Foo<T> { field: T }

#[repr(transparent)]
struct Bar<T> {
    field: Foo<T>,
}

pub const BAR: Bar<TransparentStruct> =
    Bar { field: Foo { field: TransparentStruct { field: 7 } } };

exports as

constexpr static const Bar<TransparentStruct> BAR =
    Foo { /* .field = */ TransparentStruct{ /* .field = */ 7 } };

instead of the desired

constexpr static const Bar<TransparentStruct> BAR = 7;

Copy link
Copy Markdown
Collaborator

@emilio emilio left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@emilio emilio added this pull request to the merge queue May 26, 2024
Merged via the queue into mozilla:master with commit 9c10488 May 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants