Repository navigation
fix(macros): ignore #[repr(C)] and other non-integer reprs in derive(Type) for enums - #4508
Open
thelastbackspace wants to merge 1 commit into
Open
thelastbackspace wants to merge 1 commit into
thelastbackspace wants to merge 1 commit into
Conversation
… for enums The derive took the first path-only item of #[repr(..)] as the integer type, so #[repr(C)] produced `as C` casts that don't compile. Only use integer reprs; anything else is treated like an enum without a repr.
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.
Does your PR solve an issue?
fixes #4366
The enum derive picked the first path-only item in
#[repr(..)]as the integer type to encode through. With#[repr(C)]that ended up asC, so the expansion hadMyEnum::A as CandC: Encode<..>bounds and failed to compile.Now only integer reprs (
u8..u128,i8..i128,usize,isize) are picked up. Anything else (C,Rust,transparent) is skipped, so an enum with just#[repr(C)]is handled the same way as one with no repr, which means it's a string enum. Integer-repr enums work like before.I added a sqlite derive test with a
#[repr(C)]enum. Before the change it doesn't compile (unexpected #[sqlx(c = ..)]plus the missing trait impls), and with the change it round-trips as text.Is this a breaking change?
No. Before this change these enums didn't compile at all.