Skip to content

Commit 9283956

Browse files
committed
skip check_static on rvalue::threadlocalref
1 parent 8eef79c commit 9283956

File tree

3 files changed

+66
-1
lines changed

3 files changed

+66
-1
lines changed

compiler/rustc_mir/src/transform/check_consts/validation.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -732,7 +732,11 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
732732
if proj_base.is_empty() {
733733
if let (local, []) = (place_local, proj_base) {
734734
let decl = &self.body.local_decls[local];
735-
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
735+
if let Some(box LocalInfo::StaticRef {
736+
def_id,
737+
is_thread_local: false,
738+
}) = decl.local_info
739+
{
736740
let span = decl.source_info.span;
737741
self.check_static(def_id, span);
738742
return;

src/test/ui/thread-local-static.rs

+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
// edition:2018
2+
3+
#![feature(thread_local)]
4+
#![feature(const_swap)]
5+
#[thread_local]
6+
static mut STATIC_VAR_2: [u32; 8] = [4; 8];
7+
const fn g(x: &mut [u32; 8]) {
8+
//~^ ERROR mutable references are not allowed
9+
std::mem::swap(x, &mut STATIC_VAR_2)
10+
//~^ ERROR thread-local statics cannot be accessed
11+
//~| ERROR dereferencing raw pointers in constant
12+
//~| ERROR mutable references are not allowed
13+
//~| ERROR use of mutable static is unsafe
14+
}
15+
16+
fn main() {}
+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
error[E0658]: mutable references are not allowed in constant functions
2+
--> $DIR/thread-local-static.rs:7:12
3+
|
4+
LL | const fn g(x: &mut [u32; 8]) {
5+
| ^
6+
|
7+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
8+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
9+
10+
error[E0625]: thread-local statics cannot be accessed at compile-time
11+
--> $DIR/thread-local-static.rs:9:28
12+
|
13+
LL | std::mem::swap(x, &mut STATIC_VAR_2)
14+
| ^^^^^^^^^^^^
15+
16+
error[E0658]: dereferencing raw pointers in constant functions is unstable
17+
--> $DIR/thread-local-static.rs:9:23
18+
|
19+
LL | std::mem::swap(x, &mut STATIC_VAR_2)
20+
| ^^^^^^^^^^^^^^^^^
21+
|
22+
= note: see issue #51911 <https://github.com/rust-lang/rust/issues/51911> for more information
23+
= help: add `#![feature(const_raw_ptr_deref)]` to the crate attributes to enable
24+
25+
error[E0658]: mutable references are not allowed in constant functions
26+
--> $DIR/thread-local-static.rs:9:23
27+
|
28+
LL | std::mem::swap(x, &mut STATIC_VAR_2)
29+
| ^^^^^^^^^^^^^^^^^
30+
|
31+
= note: see issue #57349 <https://github.com/rust-lang/rust/issues/57349> for more information
32+
= help: add `#![feature(const_mut_refs)]` to the crate attributes to enable
33+
34+
error[E0133]: use of mutable static is unsafe and requires unsafe function or block
35+
--> $DIR/thread-local-static.rs:9:23
36+
|
37+
LL | std::mem::swap(x, &mut STATIC_VAR_2)
38+
| ^^^^^^^^^^^^^^^^^ use of mutable static
39+
|
40+
= note: mutable statics can be mutated by multiple threads: aliasing violations or data races will cause undefined behavior
41+
42+
error: aborting due to 5 previous errors
43+
44+
Some errors have detailed explanations: E0133, E0658.
45+
For more information about an error, try `rustc --explain E0133`.

0 commit comments

Comments
 (0)