Skip to content

Commit 0d4bbc5

Browse files
authored
Rollup merge of #85880 - csmoe:ice-85768, r=oli-obk
convert assertion on rvalue::threadlocalref to delay bug Closes #85768 r? ``@oli-obk``
2 parents bd18686 + 521d9ab commit 0d4bbc5

File tree

3 files changed

+63
-4
lines changed

3 files changed

+63
-4
lines changed

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

+3-4
Original file line numberDiff line numberDiff line change
@@ -356,10 +356,9 @@ impl Validator<'mir, 'tcx> {
356356
}
357357

358358
fn check_static(&mut self, def_id: DefId, span: Span) {
359-
assert!(
360-
!self.tcx.is_thread_local_static(def_id),
361-
"tls access is checked in `Rvalue::ThreadLocalRef"
362-
);
359+
if self.tcx.is_thread_local_static(def_id) {
360+
self.tcx.sess.delay_span_bug(span, "tls access is checked in `Rvalue::ThreadLocalRef");
361+
}
363362
self.check_op_spanned(ops::StaticAccess, span)
364363
}
365364

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

0 commit comments

Comments
 (0)