Skip to content
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

Deprecate the FxHashMap() and FxHashSet() constructor function hack #55114

Merged
merged 9 commits into from
Oct 20, 2018

Conversation

oli-obk
Copy link
Contributor

@oli-obk oli-obk commented Oct 16, 2018

No description provided.

@rust-highfive
Copy link
Collaborator

r? @nikomatsakis

(rust_highfive has picked a reviewer for you, use r? to override)

@rust-highfive rust-highfive added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Oct 16, 2018
@petrochenkov
Copy link
Contributor

Nit: I'd personally use Default::default() instead of SpecificMapOrSetType::default() where possible, types change from time to time and with Default::default() you don't have to adjust initializers.
Also, fewer imports.

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 16, 2018

This is possible in struct construction cases but not when local variables are initialized and immediately used by calling e.g. insert.

I will adjust all use sites accordingly

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 16, 2018

Also, imports won't get fewer, as most of the time you need the type name for the struct fields

@RalfJung
Copy link
Member

RalfJung commented Oct 16, 2018

I'd personally use Default::default() instead of SpecificMapOrSetType::default() where possible, types change from time to time and with Default::default() you don't have to adjust initializers.

Uh, I'd prefer if you wouldn't do that change. That's throwing away useful type information, which can already be hard to get by with all the inference we are doing. It doesn't make code more readable.

We should optimize for reading the code, which happens all the time, not changing the type, which only happens rarely.

@RalfJung
Copy link
Member

So, is this fully replacing #52591? Looks to be just a partial successor?

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 16, 2018

Looks to be just a partial successor?

Yes that's on purpose. Otherwise I'll never stay ahead of the bitrot curve

@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 16, 2018

So... how do I continue? 😆

@petrochenkov are you fine with not changing everything to Default::default? (well, everything that can be changed, which is around 3/4th I guess)

@petrochenkov
Copy link
Contributor

@oli-obk
Can you do it in field initializers?
That's where it doesn't mess with type inference and is not harmful for readability.

@RalfJung
Copy link
Member

is not harmful for readability.

I still think this does more harm then good -- now I have to scroll to the struct definition to figure out the types. That can be arbitrarily far away.

But I won't fight over this.

@nikomatsakis
Copy link
Contributor

FWIW, in my own projects, the rule I follow is usually:

  • When implementing Default (or a new function) I use Default::default()
    • this is partially because it lets me write simpler Rust macros, emacs macros, or otherwise move quickly through this boilerplate stuff
  • Otherwise, I prefer Type::default() for the reasons @RalfJung and @oli-obk gave -- I find it more readable, and I don't get surprises when I tweak the code and no longer have sufficient type hints

@nikomatsakis
Copy link
Contributor

r=me with whichever conclusion we reach.

@nikomatsakis nikomatsakis added S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 16, 2018
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

src/bootstrap/cache.rs Show resolved Hide resolved
@rust-highfive

This comment has been minimized.

@rust-highfive

This comment has been minimized.

@bors
Copy link
Contributor

bors commented Oct 17, 2018

☔ The latest upstream changes (presumably #54671) made this pull request unmergeable. Please resolve the merge conflicts.

@rust-highfive

This comment has been minimized.

@sanmai-NL
Copy link

Ad @nikomatsakis in #55114 (comment):
These kinds of idiom conventions are ephemeral if they’re not written down in https://github.com/rust-lang-nursery/api-guidelines. Discussing it in pull requests won’t capture the knowledge very well and discoverably.

@nikomatsakis
Copy link
Contributor

@sanmai-NL true. But that particular comment was just giving my preferences. In any case, I think such docs might be appropriate for rustc-guide -- feels like it doesn't belong in the API guidelines (particularly since these decisions don't affect the API very much).

(That said, I do think there is an API decision here, in that I've come to favor implementing Default over implementing a zero-argument new fn.)

@nikomatsakis
Copy link
Contributor

@bors r+

@bors
Copy link
Contributor

bors commented Oct 17, 2018

📌 Commit 8892efb25d88d37da63ae434d3150da4c405e1d5 has been approved by nikomatsakis

@bors bors removed the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Oct 17, 2018
@oli-obk
Copy link
Contributor Author

oli-obk commented Oct 19, 2018

@bors r=nikomatsakis p=1

bitrot priority

@bors
Copy link
Contributor

bors commented Oct 19, 2018

📌 Commit 53e92f4 has been approved by nikomatsakis

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. labels Oct 19, 2018
@bors
Copy link
Contributor

bors commented Oct 19, 2018

⌛ Testing commit 53e92f4 with merge 81b0c05...

bors added a commit that referenced this pull request Oct 19, 2018
Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack
@bors
Copy link
Contributor

bors commented Oct 19, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 19, 2018
@RalfJung
Copy link
Member

Looks like it timed out after 3h.

@bors retry

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 19, 2018
@bors
Copy link
Contributor

bors commented Oct 19, 2018

⌛ Testing commit 53e92f4 with merge 528939ce01557bc516a4993e81be9d0ff8a19e85...

@bors
Copy link
Contributor

bors commented Oct 19, 2018

💔 Test failed - status-appveyor

@bors bors added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. and removed S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. labels Oct 19, 2018
@kennytm
Copy link
Member

kennytm commented Oct 20, 2018

@bors retry AWS S3 Outage in US-WEST-1.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Oct 20, 2018
@bors
Copy link
Contributor

bors commented Oct 20, 2018

⌛ Testing commit 53e92f4 with merge 94273f4...

bors added a commit that referenced this pull request Oct 20, 2018
Deprecate the `FxHashMap()` and `FxHashSet()` constructor function hack
@bors
Copy link
Contributor

bors commented Oct 20, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: nikomatsakis
Pushing 94273f4 to master...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants