about summary refs log tree commit diff
diff options
context:
space:
mode:
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>2022-04-02 03:34:25 +0200
committerGitHub <noreply@github.com>2022-04-02 03:34:25 +0200
commitdc11de63e087542e41c5cb8fa1bc51d550c25b69 (patch)
treeaa89538b1abe69b2e9fd0a84cb7afea9c1ca7807
parentd6f6084b24923f14bff0cf31ef78da9383cfb397 (diff)
parent1f232b8e6de8ef170e896a2a98734dd54273349b (diff)
downloadrust-dc11de63e087542e41c5cb8fa1bc51d550c25b69.tar.gz
rust-dc11de63e087542e41c5cb8fa1bc51d550c25b69.zip
Rollup merge of #95557 - niluxv:issue-95533, r=dtolnay
Fix `thread_local!` macro to be compatible with `no_implicit_prelude`

Fixes issue  #95533.
-rw-r--r--library/std/src/thread/local.rs16
-rw-r--r--src/test/ui/macros/issue-95533.rs8
2 files changed, 16 insertions, 8 deletions
diff --git a/library/std/src/thread/local.rs b/library/std/src/thread/local.rs
index ca29261b1c9..587e453ceef 100644
--- a/library/std/src/thread/local.rs
+++ b/library/std/src/thread/local.rs
@@ -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.
@@ -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)
                     }
                 }
 
@@ -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);
                     }
@@ -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,
                     }
                 }
             }
@@ -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()
@@ -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()
diff --git a/src/test/ui/macros/issue-95533.rs b/src/test/ui/macros/issue-95533.rs
new file mode 100644
index 00000000000..905c14dc5fd
--- /dev/null
+++ b/src/test/ui/macros/issue-95533.rs
@@ -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 () {}