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

Handle constants of nested transparent types #958

Merged
merged 1 commit into from
May 26, 2024

Conversation

scovich
Copy link
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
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
2 checks passed
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.

None yet

2 participants