-
Notifications
You must be signed in to change notification settings - Fork 13.3k
Fixing json decoding for enums, global type constraints, pretty printing debug!, and other fixes #5578
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
Closed
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
Because the json::Decoder uses the string variant name, we need a way to correlate the string to the enum index. This passes in a static &[&str] to read_enum_variant, which allows the json::Decoder to know which branch it's trying to process.
bors
added a commit
that referenced
this pull request
Mar 28, 2013
Hey folks, This patch series does some work on the json decoder, specifically with auto decoding of enums. Previously, we would take this code: ``` enum A { B, C(~str, uint) } ``` and would encode a value of this enum to either `["B", []]` or `["C", ["D", 123]]`. I've changed this to `"B"` or `["C", "D", 123]`. This matches the style of the O'Caml json library [json-wheel](http://mjambon.com/json-wheel.html). I've added tests to make sure all this work. In order to make this change, I added passing a `&[&str]` vec to `Decode::emit_enum_variant` so the json decoder can convert the name of a variant into it's position. I also changed the impl of `Encodable` for `Option<T>` to have the right upper casing. I also did some work on the parser, which allows for `fn foo<T: ::cmp::Eq>() { ... }` statements (#5572), fixed the pretty printer properly expanding `debug!("...")` expressions, and removed `ast::expr_vstore_fixed`, which doesn't appear to be used anymore.
tesuji
pushed a commit
to tesuji/rustc
that referenced
this pull request
Jun 4, 2020
…nsch New lint: Use Reverse with sort_by_key Implements rust-lang#5578 changelog: New lint: [`unnecessary_sort_by`]
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.
Hey folks,
This patch series does some work on the json decoder, specifically with auto decoding of enums. Previously, we would take this code:
and would encode a value of this enum to either
["B", []]
or["C", ["D", 123]]
. I've changed this to"B"
or["C", "D", 123]
. This matches the style of the O'Caml json library json-wheel. I've added tests to make sure all this work.In order to make this change, I added passing a
&[&str]
vec toDecode::emit_enum_variant
so the json decoder can convert the name of a variant into it's position. I also changed the impl ofEncodable
forOption<T>
to have the right upper casing.I also did some work on the parser, which allows for
fn foo<T: ::cmp::Eq>() { ... }
statements (#5572), fixed the pretty printer properly expandingdebug!("...")
expressions, and removedast::expr_vstore_fixed
, which doesn't appear to be used anymore.