Skip to content

Commit 6c3b33d

Browse files
authored
Rollup merge of rust-lang#95557 - niluxv:issue-95533, r=dtolnay
Fix `thread_local!` macro to be compatible with `no_implicit_prelude` Fixes issue rust-lang#95533.
2 parents 0092110 + 1f232b8 commit 6c3b33d

File tree

2 files changed

+16
-8
lines changed

2 files changed

+16
-8
lines changed

library/std/src/thread/local.rs

+8-8
Original file line numberDiff line numberDiff line change
@@ -193,7 +193,7 @@ macro_rules! __thread_local_inner {
193193
#[cfg(all(target_family = "wasm", not(target_feature = "atomics")))]
194194
{
195195
static mut VAL: $t = INIT_EXPR;
196-
Some(&VAL)
196+
$crate::option::Option::Some(&VAL)
197197
}
198198

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

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

225225
unsafe {
226-
debug_assert_eq!(STATE, 1);
226+
$crate::debug_assert_eq!(STATE, 1);
227227
STATE = 2;
228228
$crate::ptr::drop_in_place(ptr);
229229
}
@@ -239,14 +239,14 @@ macro_rules! __thread_local_inner {
239239
destroy,
240240
);
241241
STATE = 1;
242-
Some(&VAL)
242+
$crate::option::Option::Some(&VAL)
243243
}
244244
// 1 == the destructor is registered and the value
245245
// is valid, so return the pointer.
246-
1 => Some(&VAL),
246+
1 => $crate::option::Option::Some(&VAL),
247247
// otherwise the destructor has already run, so we
248248
// can't give access.
249-
_ => None,
249+
_ => $crate::option::Option::None,
250250
}
251251
}
252252
}
@@ -269,7 +269,7 @@ macro_rules! __thread_local_inner {
269269
if let $crate::option::Option::Some(value) = init.take() {
270270
return value;
271271
} else if $crate::cfg!(debug_assertions) {
272-
unreachable!("missing initial value");
272+
$crate::unreachable!("missing initial value");
273273
}
274274
}
275275
__init()
@@ -344,7 +344,7 @@ macro_rules! __thread_local_inner {
344344
if let $crate::option::Option::Some(value) = init.take() {
345345
return value;
346346
} else if $crate::cfg!(debug_assertions) {
347-
unreachable!("missing default value");
347+
$crate::unreachable!("missing default value");
348348
}
349349
}
350350
__init()

src/test/ui/macros/issue-95533.rs

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
// check-pass
2+
3+
#![no_implicit_prelude]
4+
// the macro should not rely on the prelude being imported
5+
::std::thread_local! { static P: () = (); }
6+
::std::thread_local! { static Q: () = const { () }; }
7+
8+
fn main () {}

0 commit comments

Comments
 (0)