diff options
| author | joboet <jonasboettiger@icloud.com> | 2024-05-25 00:19:47 +0200 |
|---|---|---|
| committer | joboet <jonasboettiger@icloud.com> | 2024-05-25 00:19:47 +0200 |
| commit | 1052d2931cbc32ffb6e1b648f4d7e248d5fdd889 (patch) | |
| tree | c838846f39f3ef270192c7b51691afedd87beaef /library/std/src/thread | |
| parent | 9e297bf54d31eb3b30067208ff9af4416945a2ed (diff) | |
| download | rust-1052d2931cbc32ffb6e1b648f4d7e248d5fdd889.tar.gz rust-1052d2931cbc32ffb6e1b648f4d7e248d5fdd889.zip | |
std: make TLS accessors closures that return pointers
Diffstat (limited to 'library/std/src/thread')
| -rw-r--r-- | library/std/src/thread/local.rs | 12 |
1 files changed, 4 insertions, 8 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs index c1b4440e560..aed185637fd 100644 --- a/library/std/src/thread/local.rs +++ b/library/std/src/thread/local.rs @@ -123,7 +123,7 @@ pub struct LocalKey<T: 'static> { // trivially devirtualizable by LLVM because the value of `inner` never // changes and the constant should be readonly within a crate. This mainly // only runs into problems when TLS statics are exported across crates. - inner: unsafe fn(Option<&mut Option<T>>) -> Option<&'static T>, + inner: fn(Option<&mut Option<T>>) -> *const T, } #[stable(feature = "std_debug", since = "1.16.0")] @@ -238,9 +238,7 @@ impl<T: 'static> LocalKey<T> { issue = "none" )] #[rustc_const_unstable(feature = "thread_local_internals", issue = "none")] - pub const unsafe fn new( - inner: unsafe fn(Option<&mut Option<T>>) -> Option<&'static T>, - ) -> LocalKey<T> { + pub const unsafe fn new(inner: fn(Option<&mut Option<T>>) -> *const T) -> LocalKey<T> { LocalKey { inner } } @@ -281,8 +279,7 @@ impl<T: 'static> LocalKey<T> { where F: FnOnce(&T) -> R, { - // SAFETY: `inner` is safe to call within the lifetime of the thread - let thread_local = unsafe { (self.inner)(None).ok_or(AccessError)? }; + let thread_local = unsafe { (self.inner)(None).as_ref().ok_or(AccessError)? }; Ok(f(thread_local)) } @@ -304,9 +301,8 @@ impl<T: 'static> LocalKey<T> { { let mut init = Some(init); - // SAFETY: `inner` is safe to call within the lifetime of the thread let reference = unsafe { - (self.inner)(Some(&mut init)).expect( + (self.inner)(Some(&mut init)).as_ref().expect( "cannot access a Thread Local Storage value \ during or after destruction", ) |
