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

Derive Hash for ThreadId + better example #41008

Merged
merged 2 commits into from
Apr 12, 2017
Merged

Conversation

sagebind
Copy link
Contributor

@sagebind sagebind commented Apr 2, 2017

Derive Hash for ThreadId (see comments in #21507). Useful for making maps based on thread, e.g. HashMap<ThreadId, ?>. Also update example code for thread IDs to be more useful.

@rust-highfive
Copy link
Collaborator

Thanks for the pull request, and welcome! The Rust team is excited to review your changes, and you should hear from @alexcrichton (or someone else) soon.

If any changes to this PR are deemed necessary, please add them as extra commits. This ensures that the reviewer can see what has changed since they last reviewed the code. Due to the way GitHub handles out-of-date commits, this should also make it reasonably obvious what issues have or haven't been addressed. Large or tricky changes may require several passes of review and changes.

Please see the contribution instructions for more information.

@frewsxcv frewsxcv added A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools T-libs-api Relevant to the library API team, which will review and decide on the PR/issue. labels Apr 2, 2017
@sfackler
Copy link
Member

sfackler commented Apr 2, 2017

Looks like the doctests are failing:

failures:
[01:02:27] 
[01:02:27] ---- thread/mod.rs - thread::Thread::id (line 791) stdout ----
[01:02:27] 	error: no method named `unwrap` found for type `std::thread::JoinHandle<std::thread::ThreadId>` in the current scope
[01:02:27]   --> <anon>:10:4
[01:02:27]    |
[01:02:27] 10 | }).unwrap();
[01:02:27]    |    ^^^^^^
[01:02:27] 
[01:02:27] error: aborting due to previous error(s)
[01:02:27] 
[01:02:27] thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc/session/mod.rs:203
[01:02:27] note: Run with `RUST_BACKTRACE=1` for a backtrace.
[01:02:27] 
[01:02:27] ---- thread/mod.rs - thread::ThreadId (line 660) stdout ----
[01:02:27] 	error: no method named `unwrap` found for type `std::thread::JoinHandle<std::thread::ThreadId>` in the current scope
[01:02:27]   --> <anon>:10:4
[01:02:27]    |
[01:02:27] 10 | }).unwrap();
[01:02:27]    |    ^^^^^^
[01:02:27] 
[01:02:27] error: aborting due to previous error(s)
[01:02:27] 
[01:02:27] thread 'rustc' panicked at 'Box<Any>', /checkout/src/librustc/session/mod.rs:203
[01:02:27] 
[01:02:27] 
[01:02:27] failures:
[01:02:27]     thread/mod.rs - thread::Thread::id (line 791)
[01:02:27]     thread/mod.rs - thread::ThreadId (line 660)
[01:02:27] 
[01:02:27] test result: FAILED. 776 passed; 2 failed; 22 ignored; 0 measured
[01:02:27] 
[01:02:27] error: test failed

Could you add Debug into the derive list while you're in there?

@nrc
Copy link
Member

nrc commented Apr 2, 2017

Could you add Debug into the derive list while you're in there?

Note that there is already a Debug impl, it just prints ThreadId { .. } rather than the more useful, obvious solution. If we do want to derive Debug, then we would need to remove the explicit impl.

@sfackler
Copy link
Member

sfackler commented Apr 2, 2017

Oh, that's weird. I have no problem with a derived implementation that actually shows the value.

@sagebind
Copy link
Contributor Author

sagebind commented Apr 3, 2017

I think we originally did not derive Debug because we did not want to expose the actual value in any way, even for debugging. I see no issue with displaying it though, for debugging purposes anyway. Would probably be really helpful for identifying threads for logs, etc.

@alexcrichton
Copy link
Member

Yeah hiding the value from the Debug impl seems like it's trying to hard to me, I'd also expect #[derive(Debug)] here (and would be ok with it)

@nrc
Copy link
Member

nrc commented Apr 3, 2017

hiding the value from the Debug impl seems like it's trying to hard to me

it is irritating but also useless - you can always just transmute

@sfackler
Copy link
Member

sfackler commented Apr 3, 2017

You monster!

@alexcrichton
Copy link
Member

@rfcbot fcp merge

@rfcbot
Copy link

rfcbot commented Apr 4, 2017

Team member @alexcrichton has proposed to merge this. The next step is review by the rest of the tagged teams:

No concerns currently listed.

Once these reviewers reach consensus, this will enter its final comment period. If you spot a major issue that hasn't been raised at any point in this process, please speak up!

See this document for info about what commands tagged team members can give me.

@frewsxcv
Copy link
Member

frewsxcv commented Apr 4, 2017

I don't remember why I tagged this T-doc, but here's my checkmark anyways.

@sagebind
Copy link
Contributor Author

sagebind commented Apr 4, 2017

@frewsxcv Perhaps because the example code is updated for the ThreadId type?

@peschkaj
Copy link

peschkaj commented Apr 5, 2017

@rfcbot reviewed

2 similar comments
@sophiajt
Copy link
Contributor

sophiajt commented Apr 5, 2017

@rfcbot reviewed

@GuillaumeGomez
Copy link
Member

@rfcbot reviewed

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Apr 11, 2017

📌 Commit cd14a32 has been approved by alexcrichton

frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 12, 2017
Derive Hash for ThreadId + better example

Derive `Hash` for `ThreadId` (see comments in rust-lang#21507). Useful for making maps based on thread, e.g. `HashMap<ThreadId, ?>`. Also update example code for thread IDs to be more useful.
frewsxcv added a commit to frewsxcv/rust that referenced this pull request Apr 12, 2017
Derive Hash for ThreadId + better example

Derive `Hash` for `ThreadId` (see comments in rust-lang#21507). Useful for making maps based on thread, e.g. `HashMap<ThreadId, ?>`. Also update example code for thread IDs to be more useful.
@bors
Copy link
Contributor

bors commented Apr 12, 2017

⌛ Testing commit cd14a32 with merge d62179c...

@bors
Copy link
Contributor

bors commented Apr 12, 2017

💔 Test failed - status-appveyor

@TimNN
Copy link
Contributor

TimNN commented Apr 12, 2017

@bors
Copy link
Contributor

bors commented Apr 12, 2017

⌛ Testing commit cd14a32 with merge 4a78fc0...

@bors
Copy link
Contributor

bors commented Apr 12, 2017

💔 Test failed - status-appveyor

@TimNN
Copy link
Contributor

TimNN commented Apr 12, 2017

@bors
Copy link
Contributor

bors commented Apr 12, 2017

⌛ Testing commit cd14a32 with merge 14481f7...

bors added a commit that referenced this pull request Apr 12, 2017
Derive Hash for ThreadId + better example

Derive `Hash` for `ThreadId` (see comments in #21507). Useful for making maps based on thread, e.g. `HashMap<ThreadId, ?>`. Also update example code for thread IDs to be more useful.
@bors
Copy link
Contributor

bors commented Apr 12, 2017

☀️ Test successful - status-appveyor, status-travis
Approved by: alexcrichton
Pushing 14481f7 to master...

@bors bors merged commit cd14a32 into rust-lang:master Apr 12, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
A-docs Area: Documentation for any part of the project, including the compiler, standard library, and tools 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.