Skip to content

const-eval error: always say in which item the error occurred #142008

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jun 9, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 3 additions & 5 deletions compiler/rustc_const_eval/messages.ftl
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,9 @@ const_eval_division_overflow =
const_eval_dyn_call_not_a_method =
`dyn` call trying to call something that is not a method

const_eval_error = {$error_kind ->
[static] evaluation of static initializer failed here
[const] evaluation of constant value failed here
[const_with_path] evaluation of `{$instance}` failed here
*[other] {""}
const_eval_error = evaluation of `{$instance}` failed {$num_frames ->
[0] here
*[other] inside this call
}

const_eval_exact_div_has_remainder =
Expand Down
18 changes: 3 additions & 15 deletions compiler/rustc_const_eval/src/const_eval/eval_queries.rs
Original file line number Diff line number Diff line change
Expand Up @@ -430,27 +430,15 @@ fn report_eval_error<'tcx>(
let (error, backtrace) = error.into_parts();
backtrace.print_backtrace();

let (kind, instance) = if ecx.tcx.is_static(cid.instance.def_id()) {
("static", String::new())
} else {
// If the current item has generics, we'd like to enrich the message with the
// instance and its args: to show the actual compile-time values, in addition to
// the expression, leading to the const eval error.
let instance = &cid.instance;
if !instance.args.is_empty() {
let instance = with_no_trimmed_paths!(instance.to_string());
("const_with_path", instance)
} else {
("const", String::new())
}
};
let instance = with_no_trimmed_paths!(cid.instance.to_string());
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@RalfJung would it be possible to reuse some of the machinery from #137201 to ensure that long types aren't printed to the terminal, and instead get written to disk?

I saw a test with content like "evaluation of <() as ConstGenericTrait<{my_fn(2)}>>::{constant#0} failed inside this call" and I'm concerned that we could easily end up with really verbose output unnecessarily.

p-low

Copy link
Member Author

@RalfJung RalfJung Jul 14, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Possible? Probably. But it might be very hard...
And I am sure const-eval is not the only component putting types into the output, so this seems to me to demand a more fundamental solution than playing whack-a-mole with compiler components putting types into their diagnostics.

Please file an issue.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do note that structured errors can display anything that implements IntoDiagArg as text, so a structured error that has a Ty<'_> field then it gets evaluated by the long type trimming logic, so we get that behavior for free when using structured errors.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, maybe there's a way to use that here... but generally structured errors have caused huge amounts of pain and boilerplate in const-eval so we have some loose plans to get rid of them again.


super::report(
*ecx.tcx,
error,
DUMMY_SP,
|| super::get_span_and_frames(ecx.tcx, ecx.stack()),
|diag, span, frames| {
let num_frames = frames.len();
// FIXME(oli-obk): figure out how to use structured diagnostics again.
diag.code(E0080);
diag.span_label(span, crate::fluent_generated::const_eval_error);
Expand All @@ -459,7 +447,7 @@ fn report_eval_error<'tcx>(
}
// Add after the frame rendering above, as it adds its own `instance` args.
diag.arg("instance", instance);
diag.arg("error_kind", kind);
diag.arg("num_frames", num_frames);
},
)
}
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/const-ub-checks.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: accessing memory based on pointer with alignment ALIGN, but alignm
--> tests/fail/const-ub-checks.rs:LL:CC
|
LL | ptr.read();
| ^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^ evaluation of `UNALIGNED_READ` failed here

note: erroneous constant encountered
--> tests/fail/const-ub-checks.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion src/tools/miri/tests/fail/erroneous_const2.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: attempt to compute `5_u32 - 6_u32`, which would overflow
--> tests/fail/erroneous_const2.rs:LL:CC
|
LL | const FOO: u32 = [X - Y, Y - X][(X < Y) as usize];
| ^^^^^ evaluation of constant value failed here
| ^^^^^ evaluation of `FOO` failed here

note: erroneous constant encountered
--> tests/fail/erroneous_const2.rs:LL:CC
Expand Down
2 changes: 1 addition & 1 deletion tests/rustdoc-ui/const-evalutation-ice.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: attempt to compute `0_usize - 1_usize`, which would overflow
--> $DIR/const-evalutation-ice.rs:10:22
|
LL | pub const N: usize = 0 - (mem::size_of::<S>() != 400) as usize;
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `N` failed here

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/array-slice-vec/array_const_index-0.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: index out of bounds: the length is 0 but the index is 1
--> $DIR/array_const_index-0.rs:2:16
|
LL | const B: i32 = (&A)[1];
| ^^^^^^^ evaluation of constant value failed here
| ^^^^^^^ evaluation of `B` failed here

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/array-slice-vec/array_const_index-1.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: index out of bounds: the length is 0 but the index is 1
--> $DIR/array_const_index-1.rs:2:16
|
LL | const B: i32 = A[1];
| ^^^^ evaluation of constant value failed here
| ^^^^ evaluation of `B` failed here

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-81899.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic
--> $DIR/issue-81899.rs:6:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^ evaluation of `_CONST` failed inside this call
|
note: inside `f::<{closure@$DIR/issue-81899.rs:6:31: 6:34}>`
--> $DIR/issue-81899.rs:13:5
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/borrowck/issue-88434-minimal-example.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic
--> $DIR/issue-88434-minimal-example.rs:5:22
|
LL | const _CONST: &() = &f(&|_| {});
| ^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^ evaluation of `_CONST` failed inside this call
|
note: inside `f::<{closure@$DIR/issue-88434-minimal-example.rs:5:25: 5:28}>`
--> $DIR/issue-88434-minimal-example.rs:12:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: explicit panic
--> $DIR/issue-88434-removal-index-should-be-less.rs:5:24
|
LL | const _CONST: &[u8] = &f(&[], |_| {});
| ^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^ evaluation of `_CONST` failed inside this call
|
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:5:31: 5:34}>`
--> $DIR/issue-88434-removal-index-should-be-less.rs:12:5
Expand Down
4 changes: 2 additions & 2 deletions tests/ui/coherence/const-errs-dont-conflict-103369.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: evaluation panicked: Some error occurred
--> $DIR/const-errs-dont-conflict-103369.rs:5:25
|
LL | impl ConstGenericTrait<{my_fn(1)}> for () {}
| ^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^ evaluation of `<() as ConstGenericTrait<{my_fn(1)}>>::{constant#0}` failed inside this call
|
note: inside `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
Expand All @@ -14,7 +14,7 @@ error[E0080]: evaluation panicked: Some error occurred
--> $DIR/const-errs-dont-conflict-103369.rs:7:25
|
LL | impl ConstGenericTrait<{my_fn(2)}> for () {}
| ^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^ evaluation of `<() as ConstGenericTrait<{my_fn(2)}>>::{constant#0}` failed inside this call
|
note: inside `my_fn`
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: attempt to compute `u8::MAX + 1_u8`, which would overflow
--> $DIR/default-param-wf-concrete.rs:4:28
|
LL | struct Foo<const N: u8 = { 255 + 1 }>;
| ^^^^^^^ evaluation of constant value failed here
| ^^^^^^^ evaluation of `Foo::{constant#0}` failed here

error: aborting due to 1 previous error

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: attempt to compute `u8::MAX + 1_u8`, which would overflow
--> $DIR/default-param-wf-concrete.rs:4:28
|
LL | struct Foo<const N: u8 = { 255 + 1 }>;
| ^^^^^^^ evaluation of constant value failed here
| ^^^^^^^ evaluation of `Foo::{constant#0}` failed here

error: aborting due to 1 previous error

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/defaults/wfness.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: attempt to compute `u8::MAX + 1_u8`, which would overflow
--> $DIR/wfness.rs:1:33
|
LL | struct Ooopsies<const N: u8 = { u8::MAX + 1 }>;
| ^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^ evaluation of `Ooopsies::{constant#0}` failed here

error[E0277]: the trait bound `(): Trait<2>` is not satisfied
--> $DIR/wfness.rs:8:9
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/const-generics/issues/issue-100313.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: writing to ALLOC0 which is read-only
--> $DIR/issue-100313.rs:18:5
|
LL | x.set_false();
| ^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^ evaluation of `_` failed inside this call
|
note: inside `T::<&true>::set_false`
--> $DIR/issue-100313.rs:11:13
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: using uninitialized data, but this operation requires initialized
--> $DIR/invalid-patterns.rs:40:32
|
LL | get_flag::<false, { unsafe { char_raw.character } }>();
| ^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#7}` failed here

error[E0080]: constructing invalid value: encountered 0x42, but expected a boolean
--> $DIR/invalid-patterns.rs:42:14
Expand Down Expand Up @@ -30,7 +30,7 @@ error[E0080]: using uninitialized data, but this operation requires initialized
--> $DIR/invalid-patterns.rs:44:58
|
LL | get_flag::<{ unsafe { bool_raw.boolean } }, { unsafe { char_raw.character } }>();
| ^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#11}` failed here

error[E0308]: mismatched types
--> $DIR/invalid-patterns.rs:31:21
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: using uninitialized data, but this operation requires initialized
--> $DIR/invalid-patterns.rs:40:32
|
LL | get_flag::<false, { unsafe { char_raw.character } }>();
| ^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#7}` failed here

error[E0080]: constructing invalid value: encountered 0x42, but expected a boolean
--> $DIR/invalid-patterns.rs:42:14
Expand Down Expand Up @@ -30,7 +30,7 @@ error[E0080]: using uninitialized data, but this operation requires initialized
--> $DIR/invalid-patterns.rs:44:58
|
LL | get_flag::<{ unsafe { bool_raw.boolean } }, { unsafe { char_raw.character } }>();
| ^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^ evaluation of `main::{constant#11}` failed here

error[E0308]: mismatched types
--> $DIR/invalid-patterns.rs:31:21
Expand Down
10 changes: 5 additions & 5 deletions tests/ui/const-ptr/forbidden_slices.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -103,13 +103,13 @@ error[E0080]: evaluation panicked: assertion failed: 0 < pointee_size && pointee
--> $DIR/forbidden_slices.rs:50:33
|
LL | pub static R1: &[()] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }; // errors inside libcore
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of static initializer failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `R1` failed here

error[E0080]: in-bounds pointer arithmetic failed: attempting to offset pointer by 8 bytes, but got ALLOC10 which is only 4 bytes from the end of the allocation
--> $DIR/forbidden_slices.rs:54:25
|
LL | from_ptr_range(ptr..ptr.add(2)) // errors inside libcore
| ^^^^^^^^^^ evaluation of static initializer failed here
| ^^^^^^^^^^ evaluation of `R2` failed here

error[E0080]: constructing invalid value at .<deref>[0]: encountered uninitialized memory, but expected an integer
--> $DIR/forbidden_slices.rs:57:1
Expand Down Expand Up @@ -161,19 +161,19 @@ error[E0080]: in-bounds pointer arithmetic failed: attempting to offset pointer
--> $DIR/forbidden_slices.rs:79:25
|
LL | from_ptr_range(ptr..ptr.add(1))
| ^^^^^^^^^^ evaluation of static initializer failed here
| ^^^^^^^^^^ evaluation of `R8` failed here

error[E0080]: `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
--> $DIR/forbidden_slices.rs:85:34
|
LL | pub static R9: &[u32] = unsafe { from_ptr_range(&D0..(&D0 as *const u32).add(1)) };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of static initializer failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `R9` failed here

error[E0080]: `ptr_offset_from_unsigned` called on two different pointers that are not both derived from the same allocation
--> $DIR/forbidden_slices.rs:87:35
|
LL | pub static R10: &[u32] = unsafe { from_ptr_range(&D0..&D0) };
| ^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of static initializer failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `R10` failed here

error: aborting due to 18 previous errors

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/const-ptr/out_of_bounds_read.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ error[E0080]: memory access failed: attempting to access 4 bytes, but got ALLOC0
--> $DIR/out_of_bounds_read.rs:8:33
|
LL | const _READ: u32 = unsafe { ptr::read(PAST_END_PTR) };
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_READ` failed here

error[E0080]: memory access failed: attempting to access 4 bytes, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
--> $DIR/out_of_bounds_read.rs:10:39
|
LL | const _CONST_READ: u32 = unsafe { PAST_END_PTR.read() };
| ^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^ evaluation of `main::_CONST_READ` failed here

error[E0080]: memory access failed: attempting to access 4 bytes, but got ALLOC0+0x4 which is at or beyond the end of the allocation of size 4 bytes
--> $DIR/out_of_bounds_read.rs:12:37
|
LL | const _MUT_READ: u32 = unsafe { (PAST_END_PTR as *mut u32).read() };
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_MUT_READ` failed here

error: aborting due to 3 previous errors

Expand Down
6 changes: 3 additions & 3 deletions tests/ui/consts/assert-type-intrinsics.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,19 @@ error[E0080]: evaluation panicked: aborted execution: attempted to instantiate u
--> $DIR/assert-type-intrinsics.rs:11:9
|
LL | MaybeUninit::<!>::uninit().assume_init();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_BAD1` failed here

error[E0080]: evaluation panicked: aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
--> $DIR/assert-type-intrinsics.rs:15:9
|
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_BAD2` failed here

error[E0080]: evaluation panicked: aborted execution: attempted to zero-initialize type `&i32`, which is invalid
--> $DIR/assert-type-intrinsics.rs:19:9
|
LL | intrinsics::assert_zero_valid::<&'static i32>();
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::_BAD3` failed here

error: aborting due to 3 previous errors

Expand Down
4 changes: 2 additions & 2 deletions tests/ui/consts/const-array-oob.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ error[E0080]: index out of bounds: the length is 3 but the index is 4
--> $DIR/const-array-oob.rs:5:19
|
LL | const BLUB: [u32; FOO[4]] = [5, 6];
| ^^^^^^ evaluation of constant value failed here
| ^^^^^^ evaluation of `BLUB::{constant#0}` failed here

error[E0080]: index out of bounds: the length is 3 but the index is 5
--> $DIR/const-array-oob.rs:2:20
|
LL | const BAR: usize = FOO[5];
| ^^^^^^ evaluation of constant value failed here
| ^^^^^^ evaluation of `BAR` failed here

error: aborting due to 2 previous errors

Expand Down
2 changes: 1 addition & 1 deletion tests/ui/consts/const-assert-unchecked-ub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ error[E0080]: `assume` called with `false`
--> $DIR/const-assert-unchecked-ub.rs:3:5
|
LL | std::hint::assert_unchecked(n < 32);
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `_` failed here

error: aborting due to 1 previous error

Expand Down
16 changes: 8 additions & 8 deletions tests/ui/consts/const-compare-bytes-ub.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -2,49 +2,49 @@ error[E0080]: memory access failed: attempting to access 1 byte, but got null po
--> $DIR/const-compare-bytes-ub.rs:9:9
|
LL | compare_bytes(0 as *const u8, 2 as *const u8, 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::LHS_NULL` failed here

error[E0080]: memory access failed: attempting to access 1 byte, but got 0x1[noalloc] which is a dangling pointer (it has no provenance)
--> $DIR/const-compare-bytes-ub.rs:13:9
|
LL | compare_bytes(1 as *const u8, 0 as *const u8, 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::RHS_NULL` failed here

error[E0080]: memory access failed: attempting to access 1 byte, but got 0x1[noalloc] which is a dangling pointer (it has no provenance)
--> $DIR/const-compare-bytes-ub.rs:17:9
|
LL | compare_bytes(1 as *const u8, 2 as *const u8, 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::DANGLING_PTR_NON_ZERO_LENGTH` failed here

error[E0080]: memory access failed: attempting to access 4 bytes, but got ALLOC0 which is only 3 bytes from the end of the allocation
--> $DIR/const-compare-bytes-ub.rs:21:9
|
LL | compare_bytes([1, 2, 3].as_ptr(), [1, 2, 3, 4].as_ptr(), 4)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::LHS_OUT_OF_BOUNDS` failed here

error[E0080]: memory access failed: attempting to access 4 bytes, but got ALLOC1 which is only 3 bytes from the end of the allocation
--> $DIR/const-compare-bytes-ub.rs:25:9
|
LL | compare_bytes([1, 2, 3, 4].as_ptr(), [1, 2, 3].as_ptr(), 4)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::RHS_OUT_OF_BOUNDS` failed here

error[E0080]: reading memory at ALLOC2[0x0..0x1], but memory is uninitialized at [0x0..0x1], and this operation requires initialized memory
--> $DIR/const-compare-bytes-ub.rs:29:9
|
LL | compare_bytes(MaybeUninit::uninit().as_ptr(), [1].as_ptr(), 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::LHS_UNINIT` failed here

error[E0080]: reading memory at ALLOC3[0x0..0x1], but memory is uninitialized at [0x0..0x1], and this operation requires initialized memory
--> $DIR/const-compare-bytes-ub.rs:33:9
|
LL | compare_bytes([1].as_ptr(), MaybeUninit::uninit().as_ptr(), 1)
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::RHS_UNINIT` failed here

error[E0080]: unable to turn pointer into integer
--> $DIR/const-compare-bytes-ub.rs:37:9
|
LL | compare_bytes([&1].as_ptr().cast(), [&2].as_ptr().cast(), std::mem::size_of::<usize>())
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of constant value failed here
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ evaluation of `main::WITH_PROVENANCE` failed here
|
= help: this code performed an operation that depends on the underlying bytes representing a pointer
= help: the absolute address of a pointer is not known at compile-time, so such operations are not supported
Expand Down
Loading
Loading