From a2cd95fd9ea3eb698dc9f8ae7dd29321e5345e96 Mon Sep 17 00:00:00 2001 From: Alexander Regueiro Date: Wed, 30 May 2018 19:27:45 +0100 Subject: [PATCH] Fixed bug with miri const evaluation where allocation is recursively borrowed. --- src/librustc_mir/interpret/memory.rs | 3 ++- src/test/compile-fail/issue-28324.rs | 1 + .../auxiliary/pub_static_array.rs | 0 .../{compile-fail => run-pass}/static-array-across-crate.rs | 6 ------ 4 files changed, 3 insertions(+), 7 deletions(-) rename src/test/{compile-fail => run-pass}/auxiliary/pub_static_array.rs (100%) rename src/test/{compile-fail => run-pass}/static-array-across-crate.rs (70%) diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index daa30fb187ca..8e1f24c3f016 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -305,7 +305,8 @@ impl<'a, 'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'a, 'mir, 'tcx, M> { Some(alloc) => Ok(alloc), None => { // static alloc? - match self.tcx.alloc_map.lock().get(id) { + let alloc = self.tcx.alloc_map.lock().get(id); + match alloc { Some(AllocType::Memory(mem)) => Ok(mem), Some(AllocType::Function(..)) => { Err(EvalErrorKind::DerefFunctionPointer.into()) diff --git a/src/test/compile-fail/issue-28324.rs b/src/test/compile-fail/issue-28324.rs index 4179048b4611..369f919471ca 100644 --- a/src/test/compile-fail/issue-28324.rs +++ b/src/test/compile-fail/issue-28324.rs @@ -16,5 +16,6 @@ extern { pub static BAZ: u32 = *&error_message_count; //~^ ERROR constant evaluation error +//~| tried to read foreign (extern) static fn main() {} diff --git a/src/test/compile-fail/auxiliary/pub_static_array.rs b/src/test/run-pass/auxiliary/pub_static_array.rs similarity index 100% rename from src/test/compile-fail/auxiliary/pub_static_array.rs rename to src/test/run-pass/auxiliary/pub_static_array.rs diff --git a/src/test/compile-fail/static-array-across-crate.rs b/src/test/run-pass/static-array-across-crate.rs similarity index 70% rename from src/test/compile-fail/static-array-across-crate.rs rename to src/test/run-pass/static-array-across-crate.rs index d101432f6d12..732d94cee8ed 100644 --- a/src/test/compile-fail/static-array-across-crate.rs +++ b/src/test/run-pass/static-array-across-crate.rs @@ -15,13 +15,7 @@ extern crate pub_static_array as array; use array::ARRAY; static X: &'static u8 = &ARRAY[0]; -//~^ ERROR: cannot refer to the interior of another static, use a constant - static Y: &'static u8 = &(&ARRAY)[0]; -//~^ ERROR: cannot refer to the interior of another static, use a constant - static Z: u8 = (&ARRAY)[0]; -//~^ ERROR: cannot refer to the interior of another static, use a constant -//~^^ ERROR: cannot refer to other statics by value pub fn main() {}