-
-
Notifications
You must be signed in to change notification settings - Fork 15.5k
Simplify Encodable derives #161137
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
Merged
Merged
Simplify Encodable derives #161137
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
c92b4fd
remove unused variable
panstromek df3231a
add comment explaining why we generate two match statements in Encoda…
panstromek 71d2bed
add test to capture Encodable derive output
panstromek 26ec2ac
Don't generate empty match for fieldless enums in Encodable derive
panstromek e5f1dea
remove redundant variable
panstromek 3efc459
Avoid generating match for structs in Encodable derive
panstromek 50804da
don't generate empty match for fieldless enums in Encodable derive
panstromek 93510b8
Don't generate code in for all Unit-like types Encodable derive
panstromek File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,43 @@ | ||
| //@ edition: 2024 | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded | ||
|
|
||
| #![crate_type = "rlib"] | ||
| #![feature(rustc_private)] | ||
|
|
||
| extern crate rustc_macros; | ||
| extern crate rustc_serialize; | ||
| extern crate rustc_span; | ||
|
|
||
| use rustc_macros::Encodable; | ||
|
|
||
| #[derive(Encodable)] | ||
| struct UnitStruct; | ||
|
|
||
| #[derive(Encodable)] | ||
| struct EmptyStruct {} | ||
|
|
||
| #[derive(Encodable)] | ||
| enum EmptyEnum {} | ||
|
|
||
| #[derive(Encodable)] | ||
| enum SingleFieldlessEnum { | ||
| A, | ||
| } | ||
|
|
||
| #[derive(Encodable)] | ||
| enum SingleEnum { | ||
| A(u32), | ||
| } | ||
|
|
||
| #[derive(Encodable)] | ||
| enum FieldlessEnum { | ||
| A, | ||
| B, | ||
| } | ||
|
|
||
| #[derive(Encodable)] | ||
| enum PartlyFieldlessEnum { | ||
| A, | ||
| B(u32), | ||
| } |
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,104 @@ | ||
| #![feature(prelude_import)] | ||
| //@ edition: 2024 | ||
| //@ check-pass | ||
| //@ compile-flags: -Zunpretty=expanded | ||
|
|
||
| #![crate_type = "rlib"] | ||
| #![feature(rustc_private)] | ||
| extern crate std; | ||
| #[prelude_import] | ||
| use std::prelude::rust_2024::*; | ||
|
|
||
| extern crate rustc_macros; | ||
| extern crate rustc_serialize; | ||
| extern crate rustc_span; | ||
|
|
||
| use rustc_macros::Encodable; | ||
|
|
||
| struct UnitStruct; | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for UnitStruct { | ||
| fn encode(&self, __encoder: &mut __E) {} | ||
| } | ||
| }; | ||
|
|
||
| struct EmptyStruct {} | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for EmptyStruct { | ||
| fn encode(&self, __encoder: &mut __E) {} | ||
| } | ||
| }; | ||
|
|
||
| enum EmptyEnum {} | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for EmptyEnum { | ||
| fn encode(&self, __encoder: &mut __E) {} | ||
| } | ||
| }; | ||
|
|
||
| enum SingleFieldlessEnum { A, } | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for SingleFieldlessEnum { | ||
| fn encode(&self, __encoder: &mut __E) {} | ||
| } | ||
| }; | ||
|
|
||
| enum SingleEnum { A(u32), } | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for SingleEnum { | ||
| fn encode(&self, __encoder: &mut __E) { | ||
| let SingleEnum::A(ref __binding_0) = *self; | ||
| ::rustc_serialize::Encodable::<__E>::encode(__binding_0, | ||
| __encoder); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| enum FieldlessEnum { A, B, } | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for FieldlessEnum { | ||
| fn encode(&self, __encoder: &mut __E) { | ||
| let disc = | ||
| match *self { | ||
| FieldlessEnum::A => { 0usize } | ||
| FieldlessEnum::B => { 1usize } | ||
| }; | ||
| ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8); | ||
| } | ||
| } | ||
| }; | ||
|
|
||
| enum PartlyFieldlessEnum { A, B(u32), } | ||
| const _: () = | ||
| { | ||
| impl<__E: ::rustc_span::SpanEncoder> ::rustc_serialize::Encodable<__E> | ||
| for PartlyFieldlessEnum { | ||
| fn encode(&self, __encoder: &mut __E) { | ||
| let disc = | ||
| match *self { | ||
| PartlyFieldlessEnum::A => { 0usize } | ||
| PartlyFieldlessEnum::B(ref __binding_0) => { 1usize } | ||
| }; | ||
| ::rustc_serialize::Encoder::emit_u8(__encoder, disc as u8); | ||
| match *self { | ||
| PartlyFieldlessEnum::A => {} | ||
| PartlyFieldlessEnum::B(ref __binding_0) => { | ||
| ::rustc_serialize::Encodable::<__E>::encode(__binding_0, | ||
| __encoder); | ||
| } | ||
| } | ||
| } | ||
| } | ||
| }; |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.