Join GitHub today
GitHub is home to over 31 million developers working together to host and review code, manage projects, and build software together.
Sign upProvide better names for builtin deriving-generated attributes #49986
Conversation
pietroalbini
added
the
S-waiting-on-review
label
Apr 16, 2018
This comment has been minimized.
This comment has been minimized.
|
Thanks for the PR! Highfive failed to assign a reviewer for you, so I'm picking one randomly from the compiler team. |
rust-highfive
assigned
petrochenkov
Apr 16, 2018
This comment has been minimized.
This comment has been minimized.
|
Manish was mentoring me on this one so I think it makes sense for them to be the one to review this? r? @Manishearth |
rust-highfive
assigned
Manishearth
and unassigned
petrochenkov
Apr 16, 2018
Manishearth
referenced this pull request
Apr 16, 2018
Closed
Don't use underscores in argument names for derive output #49676
Manishearth
approved these changes
Apr 16, 2018
| @@ -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")], | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 16, 2018
Member
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")], |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
zofrex
Apr 16, 2018
•
Author
Contributor
Also from the trait. Relatedly... are these (decodable/encodable) even used? I couldn't find any references to these in the docs.
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 16, 2018
Member
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")], |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
|
Looking good so far. Get rid of the underscores and cherry pick d5a304e instead, that should fix the unused variables warning. |
This comment has been minimized.
This comment has been minimized.
|
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; |
This comment has been minimized.
This comment has been minimized.
|
I'll make all the suggested changes. Let me know what you think regarding the names that are in doubt. :) |
pietroalbini
added
S-waiting-on-author
and removed
S-waiting-on-review
labels
Apr 16, 2018
This comment has been minimized.
This comment has been minimized.
|
Yeah just keep the names as is, mirroring the traits. |
Manishearth
and others
added some commits
Apr 5, 2018
This comment has been minimized.
This comment has been minimized.
|
I take it
I'm not really sure why these are all named self in the first place. How about |
This comment has been minimized.
This comment has been minimized.
|
There's a |
This comment has been minimized.
This comment has been minimized.
|
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) |
This comment has been minimized.
This comment has been minimized.
|
Also, can you add some tests that ensure consts don't clash? |
This comment has been minimized.
This comment has been minimized.
|
There are two instances of |
This comment has been minimized.
This comment has been minimized.
|
Yeah, we want to ideally fix all underscores and make everything hygenic. I'll have a look and get back to you. |
This comment has been minimized.
This comment has been minimized.
|
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. |
zofrex
added some commits
Apr 19, 2018
Manishearth
reviewed
Apr 19, 2018
| pub const state: u8 = 1; | ||
| pub const cmp: u8 = 1; | ||
|
|
||
| #[derive(Ord,Eq,PartialOrd,PartialEq,Debug,Decodable,Encodable,Hash)] |
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 19, 2018
Member
nit: spaces between commas
(also change the commit message to just "test deriving hygiene")
This comment has been minimized.
This comment has been minimized.
zofrex
Apr 19, 2018
Author
Contributor
(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)
This comment has been minimized.
This comment has been minimized.
Manishearth
Apr 19, 2018
Member
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.
Manishearth
approved these changes
Apr 19, 2018
This comment has been minimized.
This comment has been minimized.
|
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:
|
This comment has been minimized.
This comment has been minimized.
|
All at once is fine. |
zofrex
reviewed
Apr 24, 2018
| @@ -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| { | |||
This comment has been minimized.
This comment has been minimized.
zofrex
Apr 24, 2018
Author
Contributor
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.
zofrex
reviewed
Apr 24, 2018
| @@ -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() | |||
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Manishearth
approved these changes
Apr 24, 2018
This comment has been minimized.
This comment has been minimized.
|
@bors r+ thanks! |
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-bors
and removed
S-waiting-on-author
labels
Apr 24, 2018
This comment has been minimized.
This comment has been minimized.
|
Wait, there's more! (Sorry, was still working on the tests, didn't think this was r+ material yet) |
This comment has been minimized.
This comment has been minimized.
|
Oh, right, the format stuff can also break things. @bors r+ |
This comment has been minimized.
This comment has been minimized.
|
|
This comment has been minimized.
This comment has been minimized.
|
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? :) |
This comment has been minimized.
This comment has been minimized.
|
Yeah, I'd prefer that be done in a followup. Feel free to ask me stuff! |
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Apr 24, 2018
This comment has been minimized.
This comment has been minimized.
|
|
bors
added
S-waiting-on-review
and removed
S-waiting-on-bors
labels
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
|
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
This comment has been minimized.
This comment has been minimized.
|
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 |
This comment has been minimized.
This comment has been minimized.
nagbot-rs
commented
Apr 25, 2018
|
@bors: retry
* crates.io was down
…On Tue, Apr 24, 2018 at 7:44 PM, bors ***@***.***> wrote:
|
This comment has been minimized.
This comment has been minimized.
|
@nagbot-rs: |
This comment has been minimized.
This comment has been minimized.
|
@bors retry @rust-lang/infra, yer bot be broken |
bors
added
S-waiting-on-bors
and removed
S-waiting-on-review
labels
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
bors
added a commit
that referenced
this pull request
Apr 25, 2018
This comment has been minimized.
This comment has been minimized.
|
|
zofrex commentedApr 15, 2018
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?)