-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Tracking issue for thread_local_state
stabilization
#27716
Comments
Nominating for stabilization in 1.6. |
The libs team decided to not move this into FCP, some worries around this being:
|
Although I nominated this for 1.8, libs decided to remove the nomination as I forgot that the reason this is not in FCP yet is because you hit TLS twice when querying the state. |
I think this would be better expressed like |
See also: rust-lang/rfcs#2030 |
PR for |
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.
The documenation for
But then it also mentions:
Do we really want to make the first guarantee? Is it not reasonable for |
+1 to that. |
@stjepang sounds reasonable to me! |
This issue should be resolved now that we have
|
In #43491, I proposed adding a fourth |
…initialized, r=alexcrichton Docs: a LocalKey might start in the Valid state Add a comment to the docs for `LocalKey::state` explaining that some keys might skip the `Uninitialized` state and start in the `Valid` state. cc rust-lang#27716 r? @alexcrichton
Until we decide what to do with |
Nominating. I propose that we stabilize the cc @rust-lang/libs |
I agree with @Mark-Simulacrum's assessment and would be ok stabilizing @rfcbot fcp merge |
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. |
🔔 This is now entering its final comment period, as per the review above. 🔔 |
The final comment period is now complete. |
…h, r=alexcrichton Stabilize LocalKey::try_with The `LocalKey::try_with` method is now stabilized. `LocalKey::state` and `LocalKeyState` marked as deprecated. Although, is there any reason to keep them - should we perhaps remove them completely? Closes rust-lang#27716 r? @alexcrichton
I regret stabilizing So the signature of pub fn try_with<F, R>(&'static self, f: F) -> Result<R, AccessError>
where
F: FnOnce(&T) -> R; We should've gone with the following instead: pub fn try_with<F, R>(&'static self, f: F) -> R
where
F: FnOnce(Result<&T, AccessError>) -> R; Why? I have a situation with this helper function: pub fn with_context<F, R>(f: F) -> R
where
F: FnOnce(&Arc<Context>) -> R,
{
CONTEXT.try_with(|cx| f(cx)).unwrap_or_else(|_| f(&Context::new()))
} Unfortunately, the helper function doesn't compile: error[E0382]: capture of moved value: `f`
--> src/internal/context.rs:162:53
|
162 | CONTEXT.try_with(|cx| f(cx)).unwrap_or_else(|_| f(&Context::new()))
| ---- ^ value captured here after move
| |
| value moved (into closure) here
|
= note: move occurs because `f` has type `F`, which does not implement the `Copy` trait So Had we gone with the other signature for pub fn with_context<F, R>(f: F) -> R
where
F: FnOnce(&Arc<Context>) -> R,
{
CONTEXT.try_with(|cx| {
match cx {
Ok(cx) => f(cx),
Err(..) => f(&Context::new()),
}
})
} |
This feature allows you to query a thread-local variable for its state: http://static.rust-lang.org/doc/master/std/thread/enum.LocalKeyState.html, which will then tell you what may happen if you try to read from the variable.
The functionality is somewhat niche, but occasionally essential. The APIs appear to be in pretty decent shape as-is.
cc @alexcrichton
The text was updated successfully, but these errors were encountered: