fix(macros): only take an integer type from repr in the Type derive - #4403
Open
LckyLke wants to merge 1 commit into
Open
fix(macros): only take an integer type from repr in the Type derive#4403LckyLke wants to merge 1 commit into
repr in the Type derive#4403LckyLke wants to merge 1 commit into
Conversation
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.
Fixes #4366.
#[derive(sqlx::Type)]reads the enum's#[repr(...)]to find the integer type of a weak enum. It took the first plain identifier in the list, so#[repr(C)]producedMyEnum::Variant as Cand bounds likeC: Encode<'q, DB>, which do not compile.The derive now only accepts an integer type from
repr:i8toi128,u8tou128,isize, andusize. Markers such asC,transparent, andpackedare ignored. An enum with only#[repr(C)]is therefore a strong enum, mapped by variant name, the same as an enum without anyrepr. For an enum without fields that is the only formrepr(C)can take, because Rust rejectsrepr(C)combined with an integer repr on such enums.A side effect is that a struct with a non-integer
repr, for example#[repr(transparent)]on a#[sqlx(transparent)]newtype, no longer fails with "unexpected #[repr(..)]". That check only makes sense for an integerrepr.Added two cases to
tests/sqlite/derives.rs: a#[repr(C)]enum round-trips as text, and a#[repr(transparent)]transparent struct round-trips as an integer. Ran with: