Skip to content

Commit

Permalink
Fix thread_local! macro to be compatible with no_implicit_prelude
Browse files Browse the repository at this point in the history
Fixes issue  rust-lang#95533
  • Loading branch information
niluxv committed Apr 1, 2022
1 parent 0677edc commit 1f232b8
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 8 deletions.
16 changes: 8 additions & 8 deletions library/std/src/thread/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ macro_rules! __thread_local_inner {
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
{
static mut VAL: $t = INIT_EXPR;
Some(&VAL)
$crate::option::Option::Some(&VAL)
}

// If the platform has support for `#[thread_local]`, use it.
Expand All @@ -209,7 +209,7 @@ macro_rules! __thread_local_inner {
// just get going.
if !$crate::mem::needs_drop::<$t>() {
unsafe {
return Some(&VAL)
return $crate::option::Option::Some(&VAL)
}
}

Expand All @@ -223,7 +223,7 @@ macro_rules! __thread_local_inner {
let ptr = ptr as *mut $t;

unsafe {
debug_assert_eq!(STATE, 1);
$crate::debug_assert_eq!(STATE, 1);
STATE = 2;
$crate::ptr::drop_in_place(ptr);
}
Expand All @@ -239,14 +239,14 @@ macro_rules! __thread_local_inner {
destroy,
);
STATE = 1;
Some(&VAL)
$crate::option::Option::Some(&VAL)
}
// 1 == the destructor is registered and the value
// is valid, so return the pointer.
1 => Some(&VAL),
1 => $crate::option::Option::Some(&VAL),
// otherwise the destructor has already run, so we
// can't give access.
_ => None,
_ => $crate::option::Option::None,
}
}
}
Expand All @@ -269,7 +269,7 @@ macro_rules! __thread_local_inner {
if let $crate::option::Option::Some(value) = init.take() {
return value;
} else if $crate::cfg!(debug_assertions) {
unreachable!("missing initial value");
$crate::unreachable!("missing initial value");
}
}
__init()
Expand Down Expand Up @@ -344,7 +344,7 @@ macro_rules! __thread_local_inner {
if let $crate::option::Option::Some(value) = init.take() {
return value;
} else if $crate::cfg!(debug_assertions) {
unreachable!("missing default value");
$crate::unreachable!("missing default value");
}
}
__init()
Expand Down
8 changes: 8 additions & 0 deletions src/test/ui/macros/issue-95533.rs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
// check-pass

#![no_implicit_prelude]
// the macro should not rely on the prelude being imported
::std::thread_local! { static P: () = (); }
::std::thread_local! { static Q: () = const { () }; }

fn main () {}

0 comments on commit 1f232b8

Please sign in to comment.