Skip to content

Commit 61948ad

Browse files
authored
Unrolled build for rust-lang#120883
Rollup merge of rust-lang#120883 - RalfJung:extern-static-err, r=oli-obk interpret: rename ReadExternStatic → ExternStatic This error shows up for reads and writes, so `ReadExternStatic` is misleading.
2 parents 980cf08 + d56f3b6 commit 61948ad

File tree

8 files changed

+49
-8
lines changed

8 files changed

+49
-8
lines changed

compiler/rustc_const_eval/messages.ftl

+2-2
Original file line numberDiff line numberDiff line change
@@ -98,6 +98,8 @@ const_eval_error = {$error_kind ->
9898
const_eval_exact_div_has_remainder =
9999
exact_div: {$a} cannot be divided by {$b} without remainder
100100
101+
const_eval_extern_static =
102+
cannot access extern static ({$did})
101103
const_eval_fn_ptr_call =
102104
function pointers need an RFC before allowed to be called in {const_eval_const_context}s
103105
const_eval_for_loop_into_iter_non_const =
@@ -298,8 +300,6 @@ const_eval_raw_ptr_to_int =
298300
.note = at compile-time, pointers do not have an integer value
299301
.note2 = avoiding this restriction via `transmute`, `union`, or raw pointers leads to compile-time undefined behavior
300302
301-
const_eval_read_extern_static =
302-
cannot read from extern static ({$did})
303303
const_eval_read_pointer_as_int =
304304
unable to turn pointer into integer
305305
const_eval_realloc_or_alloc_with_offset =

compiler/rustc_const_eval/src/errors.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -793,7 +793,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
793793
UnsupportedOpInfo::ReadPartialPointer(_) => const_eval_partial_pointer_copy,
794794
UnsupportedOpInfo::ReadPointerAsInt(_) => const_eval_read_pointer_as_int,
795795
UnsupportedOpInfo::ThreadLocalStatic(_) => const_eval_thread_local_static,
796-
UnsupportedOpInfo::ReadExternStatic(_) => const_eval_read_extern_static,
796+
UnsupportedOpInfo::ExternStatic(_) => const_eval_extern_static,
797797
}
798798
}
799799
fn add_args<G: EmissionGuarantee>(self, _: &DiagCtxt, builder: &mut DiagnosticBuilder<'_, G>) {
@@ -812,7 +812,7 @@ impl ReportErrorExt for UnsupportedOpInfo {
812812
OverwritePartialPointer(ptr) | ReadPartialPointer(ptr) => {
813813
builder.arg("ptr", ptr);
814814
}
815-
ThreadLocalStatic(did) | ReadExternStatic(did) => {
815+
ThreadLocalStatic(did) | ExternStatic(did) => {
816816
builder.arg("did", format!("{did:?}"));
817817
}
818818
}

compiler/rustc_const_eval/src/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
557557
if self.tcx.is_foreign_item(def_id) {
558558
// This is unreachable in Miri, but can happen in CTFE where we actually *do* support
559559
// referencing arbitrary (declared) extern statics.
560-
throw_unsup!(ReadExternStatic(def_id));
560+
throw_unsup!(ExternStatic(def_id));
561561
}
562562

563563
// We don't give a span -- statics don't need that, they cannot be generic or associated.

compiler/rustc_middle/src/mir/interpret/error.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,7 @@ pub enum UnsupportedOpInfo {
468468
/// Accessing thread local statics
469469
ThreadLocalStatic(DefId),
470470
/// Accessing an unsupported extern static.
471-
ReadExternStatic(DefId),
471+
ExternStatic(DefId),
472472
}
473473

474474
/// Error information for when the program exhausted the resources granted to it
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
// compile-flags: -Zunleash-the-miri-inside-of-you
2+
#![feature(thread_local)]
3+
#![allow(static_mut_ref)]
4+
5+
extern "C" {
6+
static mut DATA: u8;
7+
}
8+
9+
// Make sure we catch accessing extern static.
10+
static TEST_READ: () = {
11+
unsafe { let _val = DATA; }
12+
//~^ ERROR could not evaluate static initializer
13+
//~| NOTE cannot access extern static
14+
};
15+
static TEST_WRITE: () = {
16+
unsafe { DATA = 0; }
17+
//~^ ERROR could not evaluate static initializer
18+
//~| NOTE cannot access extern static
19+
};
20+
21+
// Just creating a reference is fine, as long as we are not reading or writing.
22+
static TEST_REF: &u8 = unsafe { &DATA };
23+
24+
fn main() {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
error[E0080]: could not evaluate static initializer
2+
--> $DIR/extern-static.rs:11:25
3+
|
4+
LL | unsafe { let _val = DATA; }
5+
| ^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
6+
7+
error[E0080]: could not evaluate static initializer
8+
--> $DIR/extern-static.rs:16:14
9+
|
10+
LL | unsafe { DATA = 0; }
11+
| ^^^^^^^^ cannot access extern static (DefId(0:4 ~ extern_static[c41e]::{extern#0}::DATA))
12+
13+
error: aborting due to 2 previous errors
14+
15+
For more information about this error, try `rustc --explain E0080`.

tests/ui/consts/miri_unleashed/tls.rs

+2
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,8 @@ static TEST_BAD: () = {
1414
};
1515

1616
// Make sure we catch taking a reference to thread-local storage.
17+
// The actual pointer depends on the thread, so even just taking a reference already does not make
18+
// sense at compile-time.
1719
static TEST_BAD_REF: () = {
1820
unsafe { let _val = &A; }
1921
//~^ ERROR could not evaluate static initializer

tests/ui/consts/miri_unleashed/tls.stderr

+2-2
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ LL | unsafe { let _val = A; }
55
| ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
66

77
error[E0080]: could not evaluate static initializer
8-
--> $DIR/tls.rs:18:26
8+
--> $DIR/tls.rs:20:26
99
|
1010
LL | unsafe { let _val = &A; }
1111
| ^ cannot access thread local static (DefId(0:4 ~ tls[ca29]::A))
@@ -18,7 +18,7 @@ help: skipping check that does not even have a feature gate
1818
LL | unsafe { let _val = A; }
1919
| ^
2020
help: skipping check that does not even have a feature gate
21-
--> $DIR/tls.rs:18:26
21+
--> $DIR/tls.rs:20:26
2222
|
2323
LL | unsafe { let _val = &A; }
2424
| ^

0 commit comments

Comments
 (0)