Improve deserialization errors of untagged enums#12574
Merged
bors merged 2 commits intorust-lang:masterfrom Aug 28, 2023
Merged
Improve deserialization errors of untagged enums#12574bors merged 2 commits intorust-lang:masterfrom
bors merged 2 commits intorust-lang:masterfrom
Conversation
Collaborator
|
r? @ehuss (rustbot has picked a reviewer for you, use r? to override) |
Contributor
|
Thanks! I'm assuming this will also offer some (slight) performance improvements based on my own profiling with @bors r+ Any thoughts on adding derive support for this? |
Contributor
Contributor
Member
Author
|
Yeah we could potentially add derive support by having the call site tag the type of each of the variants. pub enum SslVersionConfig {
#[serde(string)]
Single(String),
#[serde(map)]
Range(SslVersionConfigRange),
} |
Contributor
|
☀️ Test successful - checks-actions |
bors
added a commit
to rust-lang-ci/rust
that referenced
this pull request
Aug 29, 2023
Update cargo 18 commits in 925280f028db3a322935e040719a0754703947cf..96fe1c9e1aecd8f57063e3753969bb6418fd2fd5 2023-08-25 21:16:44 +0000 to 2023-08-29 20:10:34 +0000 - fix(lints): Fail when overriding inherited lints (rust-lang/cargo#12584) - cargo install: suggest --git when package name is url (rust-lang/cargo#12575) - chore: remove unstable-options for logout (rust-lang/cargo#12588) - Improve logout message for asymmetric tokens (rust-lang/cargo#12587) - fix(update): Remove references to -p in help (rust-lang/cargo#12586) - fix(update): Make `-p` more convenient by being positional (rust-lang/cargo#12545) - Set tracing target for networking messages. (rust-lang/cargo#12582) - Retry docs (rust-lang/cargo#12583) - feat(resolver): **Very** preliminary MSRV resolver support (rust-lang/cargo#12560) - Update git2 (rust-lang/cargo#12580) - Explain how `version` works for `git` dependencies (rust-lang/cargo#12270) - Improve deserialization errors of untagged enums (rust-lang/cargo#12574) - Add support for `target.'cfg(..)'.linker` (rust-lang/cargo#12535) - Improve resolver version mismatch warning (rust-lang/cargo#12573) - Stabilize `--keep-going` (rust-lang/cargo#12568) - Define {{command}} for use in src/doc/man/includes (rust-lang/cargo#12570) - Update serde (rust-lang/cargo#12569) - chore: add missing `windows-sys` features back (rust-lang/cargo#12563) r? ghost
bors
added a commit
that referenced
this pull request
Aug 31, 2023
refactor: Use more serde_untagged ### What does this PR try to resolve? This is a follow up to #12574 that replaces hand-implemented Visitors with `serde_untagged` because I felt it is cleaner code Due to an error reporting limitation in `serde_untagged`, I'm not using this for some `MaybeWorkspace` types because it makes the errors worse. See dtolnay/serde-untagged#2 I also held off on some config visitors because they seemed more complicated and I didn't want to risk that code. ### How should we test and review this PR? The main caveat is we might not have tests for every single error case. ### Additional information
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.
What does this PR try to resolve?
Before:
After:
How should we test and review this PR?
The first commit adds tests showing the pre-existing error messages — mostly just "data did not match any variant of untagged enum T" with no location information. The second commit replaces all
#[derive(Deserialize)] #[serde(untagged)]with Deserialize impls based on https://docs.rs/serde-untagged/0.1, showing the effect on the error messages.Tested with
cargo test, and by handwriting some bad .cargo/config.toml files and looking at the error produced byrust-lang/cargo/target/release/cargo check.