Skip to content

Commit 1b7fe09

Browse files
committed
add comment and bless some tests
1 parent a6c4cbd commit 1b7fe09

11 files changed

+241
-139
lines changed

compiler/rustc_mir/src/const_eval/machine.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,11 @@ impl<'mir, 'tcx> InterpCx<'mir, 'tcx, CompileTimeInterpreter<'mir, 'tcx>> {
3838
if instance.def.requires_caller_location(self.tcx()) {
3939
return Ok(false);
4040
}
41-
// only memoize instrinsics
41+
// Only memoize instrinsics. This was added in #79594 while adding the `const_allocate` intrinsic.
42+
// We only memoize intrinsics because it would be unsound to memoize functions
43+
// which might interact with the heap.
44+
// Additionally, const_allocate intrinsic is impure and thus should not be memoized;
45+
// it will not be memoized because it has non-ZST args
4246
if !matches!(instance.def, InstanceDef::Intrinsic(_)) {
4347
return Ok(false);
4448
}

src/test/ui/const-generics/const-argument-if-length.full.stderr

+2-9
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,6 @@ LL | if std::mem::size_of::<T>() == 0 {
1111
LL | pub const fn size_of<T>() -> usize {
1212
| - required by this bound in `std::mem::size_of`
1313

14-
error[E0080]: evaluation of constant value failed
15-
--> $DIR/const-argument-if-length.rs:19:15
16-
|
17-
LL | pad: [u8; is_zst::<T>()],
18-
| ^^^^^^^^^^^^^ referenced constant has errors
19-
2014
error[E0277]: the size for values of type `T` cannot be known at compilation time
2115
--> $DIR/const-argument-if-length.rs:17:12
2216
|
@@ -36,7 +30,6 @@ help: the `Box` type always has a statically known size and allocates its conten
3630
LL | value: Box<T>,
3731
| ^^^^ ^
3832

39-
error: aborting due to 3 previous errors
33+
error: aborting due to 2 previous errors
4034

41-
Some errors have detailed explanations: E0080, E0277.
42-
For more information about an error, try `rustc --explain E0080`.
35+
For more information about this error, try `rustc --explain E0277`.

src/test/ui/const-generics/const-argument-if-length.rs

-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,6 @@ pub struct AtLeastByte<T: ?Sized> {
1818
//~^ ERROR the size for values of type `T` cannot be known at compilation time
1919
pad: [u8; is_zst::<T>()],
2020
//[min]~^ ERROR generic parameters may not be used in const operations
21-
//[full]~^^ ERROR evaluation of constant value failed
2221
}
2322

2423
fn main() {}

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

+8-8
Original file line numberDiff line numberDiff line change
@@ -24,18 +24,18 @@ note: the lint level is defined here
2424
LL | #![warn(const_err, unconditional_panic)]
2525
| ^^^^^^^^^
2626

27-
error[E0080]: evaluation of constant value failed
27+
error[E0080]: could not evaluate static initializer
2828
--> $DIR/erroneous-const.rs:12:17
2929
|
3030
LL | let _ = PrintName::<T>::VOID;
31-
| ^^^^^^^^^^^^^^^^^^^^ referenced constant has errors
32-
33-
error[E0080]: could not evaluate static initializer
34-
--> $DIR/erroneous-const.rs:16:22
35-
|
31+
| ^^^^^^^^^^^^^^^^^^^^
32+
| |
33+
| referenced constant has errors
34+
| inside `no_codegen::<i32>` at $DIR/erroneous-const.rs:12:17
35+
...
3636
LL | pub static FOO: () = no_codegen::<i32>();
37-
| ^^^^^^^^^^^^^^^^^^^ referenced constant has errors
37+
| ------------------- inside `FOO` at $DIR/erroneous-const.rs:16:22
3838

39-
error: aborting due to 2 previous errors; 2 warnings emitted
39+
error: aborting due to previous error; 2 warnings emitted
4040

4141
For more information about this error, try `rustc --explain E0080`.

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,10 @@
22

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

8-
const _: () = foo(); //~ any use of this value will cause an error
8+
const _: () = foo();
99
// Ensure that the CTFE engine handles calls to `#[unwind(aborts)]` gracefully
1010

1111
fn main() {
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,18 @@
1-
error[E0080]: evaluation of constant value failed
1+
error: any use of this value will cause an error
22
--> $DIR/unwind-abort.rs:5:5
33
|
44
LL | panic!()
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:5:5
6-
|
7-
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
8-
9-
error: any use of this value will cause an error
10-
--> $DIR/unwind-abort.rs:8:15
11-
|
5+
| ^^^^^^^^
6+
| |
7+
| the evaluated program panicked at 'explicit panic', $DIR/unwind-abort.rs:5:5
8+
| inside `foo` at $SRC_DIR/std/src/macros.rs:LL:COL
9+
| inside `_` at $DIR/unwind-abort.rs:8:15
10+
...
1211
LL | const _: () = foo();
13-
| --------------^^^^^-
14-
| |
15-
| referenced constant has errors
12+
| --------------------
1613
|
1714
= note: `#[deny(const_err)]` on by default
15+
= note: this error originates in a macro (in Nightly builds, run with -Z macro-backtrace for more info)
1816

19-
error: aborting due to 2 previous errors
17+
error: aborting due to previous error
2018

21-
For more information about this error, try `rustc --explain E0080`.

src/test/ui/consts/const-size_of-cycle.stderr

-5
Original file line numberDiff line numberDiff line change
@@ -14,11 +14,6 @@ note: ...which requires const-evaluating + checking `Foo::bytes::{constant#0}`..
1414
|
1515
LL | bytes: [u8; std::mem::size_of::<Foo>()]
1616
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
17-
note: ...which requires const-evaluating + checking `std::mem::size_of`...
18-
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
19-
|
20-
LL | pub const fn size_of<T>() -> usize {
21-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
2217
= note: ...which requires computing layout of `Foo`...
2318
= note: ...which requires normalizing `[u8; _]`...
2419
= note: ...which again requires simplifying constant for the type system `Foo::bytes::{constant#0}`, completing the cycle

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

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

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

77
pub const unsafe fn hint_unreachable() -> ! {
8-
fake_type() //~ ERROR evaluation of constant value failed
8+
fake_type()
99
}
1010

1111
trait Const {
12-
const CONSTANT: i32 = unsafe { fake_type() }; //~ ERROR any use of this value will cause an err
12+
const CONSTANT: i32 = unsafe { fake_type() };
1313
}
1414

1515
impl<T> Const for T {}

0 commit comments

Comments
 (0)