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

Thread local try with #43158

Merged
merged 4 commits into from
Jul 13, 2017
Merged

Conversation

PlasmaPower
Copy link
Contributor

rust-lang/rfcs#2030 was turned into this PR (the RFC was closed, but it looks like just a PR should be good).

See also: state stabilization issue: #27716

try_with is used in two places in std: stdio and thread_info. In stdio, it would be better if the result was passed to the closure, but in thread_info, it's better as is where the result is returned from the function call. I'm not sure which is better, but I prefer the current way as it better represents the scope.

@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 @sfackler (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.

@@ -674,20 +674,14 @@ fn print_to<T>(args: fmt::Arguments,
local_s: &'static LocalKey<RefCell<Option<Box<Write+Send>>>>,
global_s: fn() -> T,
label: &str) where T: Write {
let result = match local_s.state() {
LocalKeyState::Uninitialized |
Copy link
Member

Choose a reason for hiding this comment

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

This isn't quite the same behavior as before because Uninitialized would route to the global logger whereas this implementation would lazily run initialization and then route to the global logger.

#[unstable(feature = "thread_local_state",
reason = "state querying was recently added",
issue = "27716")]
pub struct AccessError {
Copy link
Member

Choose a reason for hiding this comment

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

Can you reexport this outside the local module?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but comment not marked as outdated.


impl Drop for Foo {
fn drop(&mut self) {
assert!(FOO.try_with(|_| panic!("`try_with` closure run")).is_err());
Copy link
Member

Choose a reason for hiding this comment

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

Could you add an assertion that this code is run as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, but comment not marked as outdated.

@arielb1 arielb1 assigned alexcrichton and unassigned sfackler Jul 11, 2017
@arielb1 arielb1 added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jul 11, 2017
@alexcrichton
Copy link
Member

Thanks! As one final comment, can you reimplement with in terms of try_with?

@alexcrichton
Copy link
Member

@bors: r+

@bors
Copy link
Contributor

bors commented Jul 12, 2017

📌 Commit a301f84 has been approved by alexcrichton

@bors
Copy link
Contributor

bors commented Jul 12, 2017

⌛ Testing commit a301f84 with merge 98a0110fcc1386ff85373c741108b4967c5cd879...

@Mark-Simulacrum
Copy link
Member

@bors retry -- This won't pass CI anyway due to android disk problems, prioritize the fix

@bors
Copy link
Contributor

bors commented Jul 12, 2017

⌛ Testing commit a301f84 with merge a9859cbe80b561a1334e1e80f681f06673820b79...

@bors
Copy link
Contributor

bors commented Jul 12, 2017

💔 Test failed - status-travis

@alexcrichton
Copy link
Member

alexcrichton commented Jul 13, 2017 via email

@bors
Copy link
Contributor

bors commented Jul 13, 2017

⌛ Testing commit a301f84 with merge b2c0707...

bors added a commit that referenced this pull request Jul 13, 2017
Thread local try with

rust-lang/rfcs#2030 was turned into this PR (the RFC was closed, but it looks like just a PR should be good).

See also: state stabilization issue: #27716

`try_with` is used in two places in std: stdio and thread_info. In stdio, it would be better if the result was passed to the closure, but in thread_info, it's better as is where the result is returned from the function call. I'm not sure which is better, but I prefer the current way as it better represents the scope.
@bors
Copy link
Contributor

bors commented Jul 13, 2017

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

@bors bors merged commit a301f84 into rust-lang:master Jul 13, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-review Status: Awaiting review from the assignee but also interested parties.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

7 participants