Skip to content

Commit 899a59e

Browse files
committed
rename MemoryKind::Heap to ConstHeap; bless test
1 parent 1b7fe09 commit 899a59e

9 files changed

+27
-14
lines changed

compiler/rustc_mir/src/interpret/intern.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,10 @@ fn intern_shallow<'rt, 'mir, 'tcx, M: CompileTimeMachine<'mir, 'tcx>>(
104104
// This match is just a canary for future changes to `MemoryKind`, which most likely need
105105
// changes in this function.
106106
match kind {
107-
MemoryKind::Stack | MemoryKind::Heap | MemoryKind::Vtable | MemoryKind::CallerLocation => {}
107+
MemoryKind::Stack
108+
| MemoryKind::ConstHeap
109+
| MemoryKind::Vtable
110+
| MemoryKind::CallerLocation => {}
108111
}
109112
// Set allocation mutability as appropriate. This is used by LLVM to put things into
110113
// read-only memory, and also by Miri when evaluating other globals that

compiler/rustc_mir/src/interpret/intrinsics.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -347,8 +347,11 @@ impl<'mir, 'tcx: 'mir, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
347347
Err(err) => throw_ub_format!("align has to be a power of 2, {}", err),
348348
};
349349

350-
let ptr =
351-
self.memory.allocate(Size::from_bytes(size as u64), align, MemoryKind::Heap);
350+
let ptr = self.memory.allocate(
351+
Size::from_bytes(size as u64),
352+
align,
353+
MemoryKind::ConstHeap,
354+
);
352355
self.write_scalar(Scalar::Ptr(ptr), dest)?;
353356
}
354357
sym::offset => {

compiler/rustc_mir/src/interpret/memory.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub enum MemoryKind<T> {
2828
/// Stack memory. Error if deallocated except during a stack pop.
2929
Stack,
3030
/// Heap memory.
31-
Heap,
31+
ConstHeap,
3232
/// Memory backing vtables. Error if ever deallocated.
3333
Vtable,
3434
/// Memory allocated by `caller_location` intrinsic. Error if ever deallocated.
@@ -42,7 +42,7 @@ impl<T: MayLeak> MayLeak for MemoryKind<T> {
4242
fn may_leak(self) -> bool {
4343
match self {
4444
MemoryKind::Stack => false,
45-
MemoryKind::Heap => false,
45+
MemoryKind::ConstHeap => false,
4646
MemoryKind::Vtable => true,
4747
MemoryKind::CallerLocation => true,
4848
MemoryKind::Machine(k) => k.may_leak(),
@@ -54,7 +54,7 @@ impl<T: fmt::Display> fmt::Display for MemoryKind<T> {
5454
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
5555
match self {
5656
MemoryKind::Stack => write!(f, "stack variable"),
57-
MemoryKind::Heap => write!(f, "heap allocation"),
57+
MemoryKind::ConstHeap => write!(f, "heap allocation"),
5858
MemoryKind::Vtable => write!(f, "vtable"),
5959
MemoryKind::CallerLocation => write!(f, "caller location"),
6060
MemoryKind::Machine(m) => write!(f, "{}", m),

src/test/ui/consts/const-eval/erroneous-const.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ impl<T> PrintName<T> {
99

1010
const fn no_codegen<T>() {
1111
if false {
12-
let _ = PrintName::<T>::VOID; //~ERROR evaluation of constant value failed
12+
let _ = PrintName::<T>::VOID; //~ERROR could not evaluate static initializer
1313
}
1414
}
1515

16-
pub static FOO: () = no_codegen::<i32>(); //~ERROR could not evaluate static initializer
16+
pub static FOO: () = no_codegen::<i32>();
1717

1818
fn main() {
1919
FOO
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
// run-pass
21
#![feature(core_intrinsics)]
32
#![feature(const_heap)]
43
#![feature(const_raw_ptr_deref)]
54
#![feature(const_mut_refs)]
65
use std::intrinsics;
76

8-
const FOO: &i32 = foo();
7+
const FOO: *const i32 = foo();
8+
//~^ ERROR untyped pointers are not allowed in constant
99

1010
const fn foo() -> &'static i32 {
1111
let t = unsafe {
@@ -16,5 +16,4 @@ const fn foo() -> &'static i32 {
1616
unsafe { &*t }
1717
}
1818
fn main() {
19-
assert_eq!(*FOO, 20)
2019
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
error: untyped pointers are not allowed in constant
2+
--> $DIR/alloc_intrinsic_nontransient_fail.rs:7:1
3+
|
4+
LL | const FOO: *const i32 = foo();
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6+
7+
error: aborting due to previous error
8+

src/test/ui/consts/const-eval/unwind-abort.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
#[unwind(aborts)]
44
const fn foo() {
5-
panic!() //~ 5:13: any use of this value will cause an error [const_err]
5+
panic!() //~ ERROR any use of this value will cause an error [const_err]
66
}
77

88
const _: () = foo();

src/test/ui/consts/uninhabited-const-issue-61744.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
// build-fail
22

33
pub const unsafe fn fake_type<T>() -> T {
4-
hint_unreachable() //~ 4:23: any use of this value will cause an error [const_err]
4+
hint_unreachable() //~ ERROR any use of this value will cause an error [const_err]
55
}
66

77
pub const unsafe fn hint_unreachable() -> ! {

src/test/ui/infinite/infinite-recursion-const-fn.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
//https://github.com/rust-lang/rust/issues/31364
22

33
const fn a() -> usize {
4-
b() //~ 4:8: evaluation of constant value failed [E0080]
4+
b() //~ ERROR evaluation of constant value failed [E0080]
55
}
66
const fn b() -> usize {
77
a()

0 commit comments

Comments
 (0)