Skip to content

Commit 521d9ab

Browse files
committedJun 2, 2021
convert Rvalue::threadlocalref assertion to delay bug
1 parent 9283956 commit 521d9ab

File tree

3 files changed

+11
-17
lines changed

3 files changed

+11
-17
lines changed
 

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

+4-9
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

@@ -732,11 +731,7 @@ impl Visitor<'tcx> for Validator<'mir, 'tcx> {
732731
if proj_base.is_empty() {
733732
if let (local, []) = (place_local, proj_base) {
734733
let decl = &self.body.local_decls[local];
735-
if let Some(box LocalInfo::StaticRef {
736-
def_id,
737-
is_thread_local: false,
738-
}) = decl.local_info
739-
{
734+
if let Some(box LocalInfo::StaticRef { def_id, .. }) = decl.local_info {
740735
let span = decl.source_info.span;
741736
self.check_static(def_id, span);
742737
return;

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ const fn g(x: &mut [u32; 8]) {
88
//~^ ERROR mutable references are not allowed
99
std::mem::swap(x, &mut STATIC_VAR_2)
1010
//~^ ERROR thread-local statics cannot be accessed
11-
//~| ERROR dereferencing raw pointers in constant
1211
//~| ERROR mutable references are not allowed
1312
//~| ERROR use of mutable static is unsafe
13+
//~| constant functions cannot refer to statics
1414
}
1515

1616
fn main() {}

‎src/test/ui/thread-local-static.stderr

+6-7
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,13 @@ error[E0625]: thread-local statics cannot be accessed at compile-time
1313
LL | std::mem::swap(x, &mut STATIC_VAR_2)
1414
| ^^^^^^^^^^^^
1515

16-
error[E0658]: dereferencing raw pointers in constant functions is unstable
17-
--> $DIR/thread-local-static.rs:9:23
16+
error[E0013]: constant functions cannot refer to statics
17+
--> $DIR/thread-local-static.rs:9:28
1818
|
1919
LL | std::mem::swap(x, &mut STATIC_VAR_2)
20-
| ^^^^^^^^^^^^^^^^^
20+
| ^^^^^^^^^^^^
2121
|
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
22+
= help: consider extracting the value of the `static` to a `const`, and referring to that
2423

2524
error[E0658]: mutable references are not allowed in constant functions
2625
--> $DIR/thread-local-static.rs:9:23
@@ -41,5 +40,5 @@ LL | std::mem::swap(x, &mut STATIC_VAR_2)
4140

4241
error: aborting due to 5 previous errors
4342

44-
Some errors have detailed explanations: E0133, E0658.
45-
For more information about an error, try `rustc --explain E0133`.
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)
Please sign in to comment.