Skip to content

Commit 46fe8b1

Browse files
author
Alexander Regueiro
committed
Fixed bug with miri const evaluation where allocation is recursively borrowed.
1 parent 57484de commit 46fe8b1

File tree

4 files changed

+3
-7
lines changed

4 files changed

+3
-7
lines changed

src/librustc_mir/interpret/memory.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> {
310310
Some(alloc) => Ok(alloc),
311311
None => {
312312
// static alloc?
313-
match self.tcx.alloc_map.lock().get(id) {
313+
let alloc = self.tcx.alloc_map.lock().get(id);
314+
match alloc {
314315
Some(AllocType::Memory(mem)) => Ok(mem),
315316
Some(AllocType::Function(..)) => {
316317
Err(EvalErrorKind::DerefFunctionPointer.into())

src/test/compile-fail/issue-28324.rs

+1
Original file line numberDiff line numberDiff line change
@@ -16,5 +16,6 @@ extern {
1616

1717
pub static BAZ: u32 = *&error_message_count;
1818
//~^ ERROR constant evaluation error
19+
//~| tried to read foreign (extern) static
1920

2021
fn main() {}

src/test/compile-fail/static-array-across-crate.rs renamed to src/test/run-pass/static-array-across-crate.rs

-6
Original file line numberDiff line numberDiff line change
@@ -15,13 +15,7 @@ extern crate pub_static_array as array;
1515
use array::ARRAY;
1616

1717
static X: &'static u8 = &ARRAY[0];
18-
//~^ ERROR: cannot refer to the interior of another static, use a constant
19-
2018
static Y: &'static u8 = &(&ARRAY)[0];
21-
//~^ ERROR: cannot refer to the interior of another static, use a constant
22-
2319
static Z: u8 = (&ARRAY)[0];
24-
//~^ ERROR: cannot refer to the interior of another static, use a constant
25-
//~^^ ERROR: cannot refer to other statics by value
2620

2721
pub fn main() {}

0 commit comments

Comments
 (0)