sync main with upstream/main#1
Merged
Merged
Conversation
…y-tagged shape + flatten on struct variants) (specta-rs#489) * fix: recognize widened-tag and intersection-payload variants in repr-rewrite guard `variant_repr_already_rewritten` decides whether `rewrite_enum_repr_for_phase` should re-process an enum during a subsequent pass. The first pass clears the enum's attributes (line 1412), so any second pass sees `e.attributes.is_empty()` and `EnumRepr::from_attrs` falls through to `EnumRepr::External`. If the guard fails for any variant, the enum gets re-processed under the wrong representation, wrapping each variant in `{ VariantName: payload }` (externally-tagged shape) when the original wire format is internally-tagged. Two variant shapes produced by `transform_internal_variant` were not recognized: 1. The `widen_tag` case (deserialize phase + `#[serde(other)]` variant) leaves the tag as `Primitive::str` rather than a generated string-literal enum. 2. The tuple-variant case wraps the payload in `Intersection<{tag-struct}, payload>` rather than a string-literal field. Both shapes are now recognized as already-rewritten, so the second-pass guard trips correctly and the enum keeps its internally-tagged TS shape across rewrite passes. Snapshot updates reflect the corrected output: variants no longer get externally-tagged wrapping, and the `?: never` exclusion markers are gone for internally-tagged enums. Adds `internally_tagged_enum_with_content_variants_renders_correctly` test that asserts both regression conditions (no `?: never` exclusions, tag literals present). * fix: honor #[serde(flatten)] on struct-variant fields in internally-tagged enums A struct-variant whose field carries #[serde(flatten)] serializes to a top-level merged JSON object alongside the discriminator tag. The TS bindings should mirror that: enum E { A { #[serde(flatten)] inner: T } } // serde wire format // { type: "A", ...T_fields } type E = ({ type: "A" } & T) // correct TS shape In rc.25, transform_internal_variant for Fields::Named cloned the variant's fields verbatim into the result. The flatten attribute on 'inner' survived to the typescript exporter, but the exporter no longer respects flatten on bare named-field collections (only on DataType::Struct, via lower_flattened_struct). Result: the inner type was kept under an 'inner:' key instead of merged. Mirror the unnamed-payload path: when any named field is flattened, build an Intersection of the tag struct, the leftover named fields, and each flattened field's payload type. Returns an unnamed-field variant whose single field is that Intersection -- the same shape the unnamed-payload arm produces. Snapshot diffs across 11 serde-format snapshots all show the same expected change: { type: "X"; inner: T } -> ({ type: "X" } & T). The MyEnumTagged test fixture (issue specta-rs#393) now renders correctly.
…specta-rs#490) Bumps the specta-deps group with 3 updates: [rust_decimal](https://github.com/paupino/rust-decimal), [tokio](https://github.com/tokio-rs/tokio) and [serde_with](https://github.com/jonasbb/serde_with). Updates `rust_decimal` from 1.41.0 to 1.42.0 - [Release notes](https://github.com/paupino/rust-decimal/releases) - [Changelog](https://github.com/paupino/rust-decimal/blob/master/CHANGELOG.md) - [Commits](paupino/rust-decimal@1.41.0...1.42.0) Updates `tokio` from 1.52.2 to 1.52.3 - [Release notes](https://github.com/tokio-rs/tokio/releases) - [Commits](tokio-rs/tokio@tokio-1.52.2...tokio-1.52.3) Updates `serde_with` from 3.19.0 to 3.20.0 - [Release notes](https://github.com/jonasbb/serde_with/releases) - [Commits](jonasbb/serde_with@v3.19.0...v3.20.0) --- updated-dependencies: - dependency-name: rust_decimal dependency-version: 1.42.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: specta-deps - dependency-name: tokio dependency-version: 1.52.3 dependency-type: direct:production update-type: version-update:semver-patch dependency-group: specta-deps - dependency-name: serde_with dependency-version: 3.20.0 dependency-type: direct:production update-type: version-update:semver-minor dependency-group: specta-deps ... Signed-off-by: dependabot[bot] <support@github.com> Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
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.
No description provided.