Skip to content

Commit 3a8df87

Browse files
committed
Shorten span of panic failures in const context
Previously, we included a redundant prefix on the panic message and a postfix of the location of the panic. The prefix didn't carry any additional information beyond "something failed", and the location of the panic is redundant with the diagnostic's span, which gets printed out even if its code is not shown. ``` error[E0080]: evaluation of constant value failed --> $DIR/assert-type-intrinsics.rs:11:9 | LL | MaybeUninit::<!>::uninit().assume_init(); | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!` ``` ``` --> $DIR/collect-in-dead-closure.rs:9:19 | LL | const C: () = panic!(); | ^^^^^^^^ explicit panic | = note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info) ``` ``` error[E0080]: evaluation of constant value failed --> $DIR/uninhabited.rs:87:9 | LL | assert!(false); | ^^^^^^^^^^^^^^ assertion failed: false | = note: this error originates in the macro `assert` (in Nightly builds, run with -Z macro-backtrace for more info) ```
1 parent e1f0920 commit 3a8df87

File tree

65 files changed

+98
-102
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

65 files changed

+98
-102
lines changed

compiler/rustc_const_eval/messages.ftl

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -298,8 +298,7 @@ const_eval_overflow_arith =
298298
const_eval_overflow_shift =
299299
overflowing shift by {$shift_amount} in `{$intrinsic}`
300300
301-
const_eval_panic =
302-
the evaluated program panicked at '{$msg}', {$file}:{$line}:{$col}
301+
const_eval_panic = {$msg}
303302
304303
const_eval_panic_non_str = argument to `panic!()` in a const context must have type `&str`
305304

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,11 +48,8 @@ impl MachineStopType for ConstEvalErrKind {
4848
| ModifiedGlobal
4949
| WriteThroughImmutablePointer => {}
5050
AssertFailure(kind) => kind.add_args(adder),
51-
Panic { msg, line, col, file } => {
51+
Panic { msg, .. } => {
5252
adder("msg".into(), msg.into_diag_arg());
53-
adder("file".into(), file.into_diag_arg());
54-
adder("line".into(), line.into_diag_arg());
55-
adder("col".into(), col.into_diag_arg());
5653
}
5754
}
5855
}

src/tools/miri/tests/fail/erroneous_const.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of `PrintName::<i32>::VOID` failed
22
--> tests/fail/erroneous_const.rs:LL:CC
33
|
44
LL | const VOID: ! = panic!();
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', tests/fail/erroneous_const.rs:LL:CC
5+
| ^^^^^^^^ explicit panic
66
|
77
= note: this error originates in the macro `$crate::panic::panic_2021` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

tests/ui/borrowck/issue-81899.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-81899.rs:11:5
33
|
44
LL | panic!()
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:11:5
5+
| ^^^^^^^^ explicit panic
66
|
77
note: inside `f::<{closure@$DIR/issue-81899.rs:4:31: 4:34}>`
88
--> $DIR/issue-81899.rs:11:5

tests/ui/borrowck/issue-88434-minimal-example.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-88434-minimal-example.rs:10:5
33
|
44
LL | panic!()
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
5+
| ^^^^^^^^ explicit panic
66
|
77
note: inside `f::<{closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28}>`
88
--> $DIR/issue-88434-minimal-example.rs:10:5

tests/ui/borrowck/issue-88434-removal-index-should-be-less.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
33
|
44
LL | panic!()
5-
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
5+
| ^^^^^^^^ explicit panic
66
|
77
note: inside `f::<{closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34}>`
88
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5

tests/ui/coherence/const-errs-dont-conflict-103369.stderr

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
33
|
44
LL | panic!("Some error occurred");
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
66
|
77
note: inside `my_fn`
88
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
@@ -20,7 +20,7 @@ error[E0080]: evaluation of constant value failed
2020
--> $DIR/const-errs-dont-conflict-103369.rs:10:5
2121
|
2222
LL | panic!("Some error occurred");
23-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'Some error occurred', $DIR/const-errs-dont-conflict-103369.rs:10:5
23+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Some error occurred
2424
|
2525
note: inside `my_fn`
2626
--> $DIR/const-errs-dont-conflict-103369.rs:10:5

tests/ui/const-ptr/forbidden_slices.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ LL | pub static R0: &[u32] = unsafe { from_ptr_range(ptr::null()..ptr::null()) }
102102
error[E0080]: could not evaluate static initializer
103103
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
104104
|
105-
= note: the evaluated program panicked at 'assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize', $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL
105+
= note: assertion failed: 0 < pointee_size && pointee_size <= isize::MAX as usize
106106
|
107107
note: inside `std::ptr::const_ptr::<impl *const ()>::sub_ptr`
108108
--> $SRC_DIR/core/src/ptr/const_ptr.rs:LL:COL

tests/ui/consts/assert-type-intrinsics.stderr

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,19 +2,19 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/assert-type-intrinsics.rs:11:9
33
|
44
LL | MaybeUninit::<!>::uninit().assume_init();
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to instantiate uninhabited type `!`', $DIR/assert-type-intrinsics.rs:11:36
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to instantiate uninhabited type `!`
66

77
error[E0080]: evaluation of constant value failed
88
--> $DIR/assert-type-intrinsics.rs:15:9
99
|
1010
LL | intrinsics::assert_mem_uninitialized_valid::<&'static i32>();
11-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to leave type `&i32` uninitialized, which is invalid', $DIR/assert-type-intrinsics.rs:15:9
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to leave type `&i32` uninitialized, which is invalid
1212

1313
error[E0080]: evaluation of constant value failed
1414
--> $DIR/assert-type-intrinsics.rs:19:9
1515
|
1616
LL | intrinsics::assert_zero_valid::<&'static i32>();
17-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ the evaluated program panicked at 'aborted execution: attempted to zero-initialize type `&i32`, which is invalid', $DIR/assert-type-intrinsics.rs:19:9
17+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ aborted execution: attempted to zero-initialize type `&i32`, which is invalid
1818

1919
error: aborting due to 3 previous errors
2020

tests/ui/consts/const-eval/const_panic-normalize-tabs-115498.stderr

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@ error[E0080]: evaluation of constant value failed
22
--> $DIR/const_panic-normalize-tabs-115498.rs:3:17
33
|
44
LL | struct Bug([u8; panic!{"\t"}]);
5-
| ^^^^^^^^^^^^ the evaluated program panicked at ' ', $DIR/const_panic-normalize-tabs-115498.rs:3:17
5+
| ^^^^^^^^^^^^
66
|
77
= note: this error originates in the macro `$crate::panic::panic_2015` which comes from the expansion of the macro `panic` (in Nightly builds, run with -Z macro-backtrace for more info)
88

0 commit comments

Comments
 (0)