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

impl Hash for ! #51404

Merged
merged 1 commit into from
Jun 18, 2018
Merged

impl Hash for ! #51404

merged 1 commit into from
Jun 18, 2018

Conversation

clarfonthey
Copy link
Contributor

This was missing in some generic code I was writing and I figured that it would be worthwhile to add this. Blanket-requiring these traits to allow usage of errors in HashSets and HashMaps isn't too unreasonable of a use case, and a prerequisite for allowing ! as an error in such situations is this impl.

@rust-highfive
Copy link
Collaborator

r? @KodrAus

(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 Jun 6, 2018
@rust-highfive
Copy link
Collaborator

The job x86_64-gnu-llvm-3.9 of your PR failed on Travis (raw log). Through arcane magic we have determined that the following fragments from the build log may contain information about the problem.

Click to expand the log.
[00:03:25]    Compiling rustc_tsan v0.0.0 (file:///checkout/src/librustc_tsan)
[00:03:26] warning: unused variable: `state`
[00:03:26]    --> libcore/hash/mod.rs:608:35
[00:03:26]     |
[00:03:26] 608 |         fn hash<H: Hasher>(&self, state: &mut H) {
[00:03:26]     |                                   ^^^^^ help: consider using `_state` instead
[00:03:26]     = note: #[warn(unused_variables)] on by default
[00:03:26] 
[00:03:27]    Compiling rustc_asan v0.0.0 (file:///checkout/src/librustc_asan)
[00:03:39]    Compiling libc v0.0.0 (file:///checkout/src/rustc/libc_shim)

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 @TimNN. (Feature Requests)

#[stable(feature = "never_hash", since = "1.29.0")]
impl Hash for ! {
fn hash<H: Hasher>(&self, _: &mut H) {
unreachable!()
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It doesn't seem that important, but using *self instead of unreachable!() is more consistent with how other impls for ! are defined.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@varkor I was under the impression that impls for ! which return a value of another type generally do *self, but ones which return unit do unreachable!(). Although this seems pretty arbitrary and I may have just misremembered what I saw of existing impls.

I can change it to *self if that seems more reasonable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All the implementations I can see in libstd use *self, though there are a couple in rustc that use other methods. I don't think it's hugely important though — it's fairly obvious what's going on with either method.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I like *self just so that it's trivial to translate -- no need to emit a bunch of panic call HIR+MIR+IR only for LLVM to figure out that it's unneeded again and remove it all.

@kennytm kennytm added the T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. label Jun 12, 2018
@clarfonthey
Copy link
Contributor Author

Rebased and replaced unreachable!() with *self.

@KodrAus
Copy link
Contributor

KodrAus commented Jun 17, 2018

Sorry for taking a while to get to this! It looks good to me.

@bors r+

@bors
Copy link
Contributor

bors commented Jun 17, 2018

📌 Commit 570590f has been approved by KodrAus

@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 Jun 17, 2018
@bors
Copy link
Contributor

bors commented Jun 17, 2018

⌛ Testing commit 570590f with merge 4f29363...

bors added a commit that referenced this pull request Jun 17, 2018
impl Hash for !

This was missing in some generic code I was writing and I figured that it would be worthwhile to add this. Blanket-requiring these traits to allow usage of errors in `HashSet`s and `HashMap`s isn't too unreasonable of a use case, and a prerequisite for allowing `!` as an error in such situations is this impl.
@bors
Copy link
Contributor

bors commented Jun 18, 2018

☀️ Test successful - status-appveyor, status-travis
Approved by: KodrAus
Pushing 4f29363 to master...

@bors bors merged commit 570590f into rust-lang:master Jun 18, 2018
@clarfonthey clarfonthey deleted the never_hash branch June 22, 2018 20:51
Dylan-DPC-zz pushed a commit to Dylan-DPC-zz/rust that referenced this pull request Apr 1, 2020
Implement Hash for Infallible

https://www.reddit.com/r/rust/comments/fmllgx/never_crate_stable_alternative_to/ lists not implementing `Hash` as a reason for the `never` crate. I see no reason not to implement `Hash` for `Infallible`, so might as well do it.

No changes necessary for `!`, because `!` already implements `Hash` (see rust-lang#51404).
Centril added a commit to Centril/rust that referenced this pull request Apr 2, 2020
Implement Hash for Infallible

https://www.reddit.com/r/rust/comments/fmllgx/never_crate_stable_alternative_to/ lists not implementing `Hash` as a reason for the `never` crate. I see no reason not to implement `Hash` for `Infallible`, so might as well do it.

No changes necessary for `!`, because `!` already implements `Hash` (see rust-lang#51404).
Centril added a commit to Centril/rust that referenced this pull request Apr 2, 2020
Implement Hash for Infallible

https://www.reddit.com/r/rust/comments/fmllgx/never_crate_stable_alternative_to/ lists not implementing `Hash` as a reason for the `never` crate. I see no reason not to implement `Hash` for `Infallible`, so might as well do it.

No changes necessary for `!`, because `!` already implements `Hash` (see rust-lang#51404).
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. T-libs-api Relevant to the library API team, which will review and decide on the PR/issue.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants