-
Notifications
You must be signed in to change notification settings - Fork 13k
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
Provide better names for builtin deriving-generated attributes #49986
Conversation
Thanks for the PR! Highfive failed to assign a reviewer for you, so I'm picking one randomly from the compiler team. |
Manish was mentoring me on this one so I think it makes sense for them to be the one to review this? r? @Manishearth |
src/libsyntax_ext/deriving/debug.rs
Outdated
@@ -40,7 +40,7 @@ pub fn expand_deriving_debug(cx: &mut ExtCtxt, | |||
name: "fmt", | |||
generics: LifetimeBounds::empty(), | |||
explicit_self: borrowed_explicit_self(), | |||
args: vec![fmtr], | |||
args: vec![(fmtr, "_f")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
probs should be fmt
(check what the trait uses)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The trait uses "f" (I took all the names from the traits)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah. Probably should be fmt then
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Oh, I know why it's short; it's to encourage implementors to keep it short. Leave it f
then.
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))), | ||
Borrowed(None, Mutability::Mutable))], | ||
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))), | ||
Borrowed(None, Mutability::Mutable)), "d")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"decoder"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also from the trait. Relatedly... are these (decodable/encodable) even used? I couldn't find any references to these in the docs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
They are, they're from a deprecated builtin thing. See the rustc_serialize crate.
args: vec![Ptr(Box::new(Literal(Path::new_local(typaram))), | ||
Borrowed(None, Mutability::Mutable))], | ||
args: vec![(Ptr(Box::new(Literal(Path::new_local(typaram))), | ||
Borrowed(None, Mutability::Mutable)), "s")], |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
"encoder"?
Looking good so far. Get rid of the underscores and cherry pick d5a304e instead, that should fix the unused variables warning. |
If you want, can you also try and replace the underscores with hygenic thingies for Also, we should have a test ensuring the following compiles: pub const __arg_0: u8 = 1;
#[derive(PartialEq)]
struct Foo; |
I'll make all the suggested changes. Let me know what you think regarding the names that are in doubt. :) |
Yeah just keep the names as is, mirroring the traits. |
I take it
I'm not really sure why these are all named self in the first place. How about |
There's a |
Yeah ideally they should tack on to the argument name. They're called self because the type is Self, but i don't like that much. If you want to tackle that go ahead ( but it's acceptable to land this with just the arguments and lint fixed) |
Also, can you add some tests that ensure consts don't clash? |
There are two instances of |
Yeah, we want to ideally fix all underscores and make everything hygenic. I'll have a look and get back to you. |
I think there you just want to store the argument ident in self.args and use that? You need to carry around the gensymed ident if you need to reuse it. |
pub const state: u8 = 1; | ||
pub const cmp: u8 = 1; | ||
|
||
#[derive(Ord,Eq,PartialOrd,PartialEq,Debug,Decodable,Encodable,Hash)] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: spaces between commas
(also change the commit message to just "test deriving hygiene")
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
(noted, although I was advised on IRC that I should squash the commits before merging anyway so I've been giving the commit messages a little less care – let me know if that's not the case)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're free to, but I personally prefer them to stay logically separate if possible, provided they build individually.
So squash the fixups together into logical changes, but you can leave them separate otherwise. Or just squash it all if you want, either way.
Sorting out the comments is... confusing. The I made a first stab at testing this. Do you want separate tests for each trait, or all at once like this? When it comes to the __args in format, I'm lost. I can't figure out how to get that code emitted in the first place (e.g. not showing up with --pretty=expanded, not conflicting with any consts I declare). I tried:
|
All at once is fine. |
@@ -543,6 +543,10 @@ impl<'a, 'b> Context<'a, 'b> { | |||
let mut pats = Vec::new(); | |||
let mut heads = Vec::new(); | |||
|
|||
let names_pos: Vec<_> = (0..self.args.len()).map(|i| { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This had to go all the way up here because... something to do with E0382. Self gets moved into the expression below with pieces
? This can go further down if we have a mutable array in the loop and push names onto it, but I assumed we would prefer to avoid mutability.
@@ -543,6 +543,10 @@ impl<'a, 'b> Context<'a, 'b> { | |||
let mut pats = Vec::new(); | |||
let mut heads = Vec::new(); | |||
|
|||
let names_pos: Vec<_> = (0..self.args.len()).map(|i| { | |||
self.ecx.ident_of(&format!("arg{}", i)).gensym() |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Bikeshed opportunity: arg0
or arg_0
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
shrug this is never exposed so it doesn't matter
@bors r+ thanks! |
📌 Commit 27b0f1e has been approved by |
Wait, there's more! (Sorry, was still working on the tests, didn't think this was r+ material yet) |
Oh, right, the format stuff can also break things. @bors r+ |
📌 Commit d6feab6 has been approved by |
Awesome! It's good to get this in, but just FYI there's still some more to be done - the __self bits turned out to also be tricky to handle, and a bunch of comments in the code are now wrong. I'll try to improve those and file new PRs for them (although I don't mind if someone else does them, of course) – can I bug you for help if I need it? :) |
Yeah, I'd prefer that be done in a followup. Feel free to ask me stuff! |
⌛ Testing commit d6feab6 with merge 4e4efe01cc8c74e20fd15662efdca48b3a50d42c... |
💔 Test failed - status-travis |
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
1 similar comment
The job Click to expand the log.
I'm a bot! I can only do what humans tell me to, so if this was not helpful or you have suggestions for improvements, please ping or otherwise contact |
@bors: retry
* crates.io was down
…On Tue, Apr 24, 2018 at 7:44 PM, bors ***@***.***> wrote:
💔 Test failed - status-travis
<https://travis-ci.org/rust-lang/rust/builds/370824219?utm_source=github_status&utm_medium=notification>
—
You are receiving this because you are subscribed to this thread.
Reply to this email directly, view it on GitHub
<#49986 (comment)>, or mute
the thread
<https://github.com/notifications/unsubscribe-auth/AaPN0FSQgZ1g8e8U21ofL5bjXzqvSu-aks5tr8bxgaJpZM4TVn34>
.
--
You received this message because you are subscribed to the Google Groups
"rust-ops" group.
To unsubscribe from this group and stop receiving emails from it, send an
email to ***@***.***
To post to this group, send email to ***@***.***
To view this discussion on the web visit https://groups.google.com/d/
msgid/rust-ops/rust-lang/rust/pull/49986/c384124495%40github.com
<https://groups.google.com/d/msgid/rust-ops/rust-lang/rust/pull/49986/c384124495%40github.com?utm_medium=email&utm_source=footer>
.
For more options, visit https://groups.google.com/d/optout.
|
@nagbot-rs: 🔑 Insufficient privileges: not in try users |
@bors retry @rust-lang/infra, yer bot be broken |
…earth Provide better names for builtin deriving-generated attributes First attempt at fixing #49967 Not in love with any choices here, don't be shy if you aren't happy with anything :) I've tested that this produces nicer names in documentation, and that it no longer has issues conflicting with constants with the same name. (I guess we _could_ make a test for that... unsure if that would be valuable) In all cases I took the names from the methods as declared in the relevant trait. In some cases I had to prepend the names with _ otherwise there were errors about un-used variables. I'm uneasy with the inconsistency... do they all need to be like that? Is there a way to generate an alternate impl or use a different name (`_`?) in the cases where the arguments are not used? Lastly the gensym addition to Ident I implemented largely as suggested, but I want to point out it's a little circuitous (at least, as far as I understand it). `cx.ident_of(name)` is just `Ident::from_str`, so we create an Ident then another Ident from it. `Ident::with_empty_ctxt(Symbol::gensym(string))` may or may not be equivalent, I don't know if it's important to intern it _then_ gensym it. It seems like either we could use that, or if we do want a new method to make this convenient, it could be on Ident instead (`from_str_gensymed`?)
☀️ Test successful - status-appveyor, status-travis |
First attempt at fixing #49967
Not in love with any choices here, don't be shy if you aren't happy with anything :)
I've tested that this produces nicer names in documentation, and that it no longer has issues conflicting with constants with the same name. (I guess we could make a test for that... unsure if that would be valuable)
In all cases I took the names from the methods as declared in the relevant trait.
In some cases I had to prepend the names with _ otherwise there were errors about un-used variables. I'm uneasy with the inconsistency... do they all need to be like that? Is there a way to generate an alternate impl or use a different name (
_
?) in the cases where the arguments are not used?Lastly the gensym addition to Ident I implemented largely as suggested, but I want to point out it's a little circuitous (at least, as far as I understand it).
cx.ident_of(name)
is justIdent::from_str
, so we create an Ident then another Ident from it.Ident::with_empty_ctxt(Symbol::gensym(string))
may or may not be equivalent, I don't know if it's important to intern it then gensym it. It seems like either we could use that, or if we do want a new method to make this convenient, it could be on Ident instead (from_str_gensymed
?)