Skip to content

Commit 99348a5

Browse files
committed
Change CTFE backtraces to use note instead of label to preserve their order
labels are reordered within the file in which they are reported, which can mess up the stack trace
1 parent fa99459 commit 99348a5

29 files changed

+1860
-644
lines changed

compiler/rustc_const_eval/src/const_eval/error.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -123,14 +123,14 @@ impl<'tcx> ConstEvalErr<'tcx> {
123123
// Helper closure to print duplicated lines.
124124
let mut flush_last_line = |last_frame, times| {
125125
if let Some((line, span)) = last_frame {
126-
err.span_label(span, &line);
126+
err.span_note(span, &line);
127127
// Don't print [... additional calls ...] if the number of lines is small
128128
if times < 3 {
129129
for _ in 0..times {
130-
err.span_label(span, &line);
130+
err.span_note(span, &line);
131131
}
132132
} else {
133-
err.span_label(
133+
err.span_note(
134134
span,
135135
format!("[... {} additional calls {} ...]", times, &line),
136136
);

src/test/ui/borrowck/issue-81899.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-81899.rs:11:5
33
|
4-
LL | const _CONST: &[u8] = &f(&[], |_| {});
5-
| -------------- inside `_CONST`
6-
...
4+
LL | panic!()
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:11:5
6+
|
7+
note: inside `f::<[closure@$DIR/issue-81899.rs:4:31: 4:34]>`
8+
--> $DIR/issue-81899.rs:11:5
9+
|
710
LL | panic!()
811
| ^^^^^^^^
9-
| |
10-
| the evaluated program panicked at 'explicit panic', $DIR/issue-81899.rs:11:5
11-
| inside `f::<[closure@$DIR/issue-81899.rs:4:31: 4:34]>`
12+
note: inside `_CONST`
13+
--> $DIR/issue-81899.rs:4:24
1214
|
15+
LL | const _CONST: &[u8] = &f(&[], |_| {});
16+
| ^^^^^^^^^^^^^^
1317
= 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)
1418

1519
note: erroneous constant used

src/test/ui/borrowck/issue-88434-minimal-example.stderr

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-88434-minimal-example.rs:10:5
33
|
4-
LL | const _CONST: &() = &f(&|_| {});
5-
| ---------- inside `_CONST`
6-
...
4+
LL | panic!()
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
6+
|
7+
note: inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28]>`
8+
--> $DIR/issue-88434-minimal-example.rs:10:5
9+
|
710
LL | panic!()
811
| ^^^^^^^^
9-
| |
10-
| the evaluated program panicked at 'explicit panic', $DIR/issue-88434-minimal-example.rs:10:5
11-
| inside `f::<[closure@$DIR/issue-88434-minimal-example.rs:3:25: 3:28]>`
12+
note: inside `_CONST`
13+
--> $DIR/issue-88434-minimal-example.rs:3:22
1214
|
15+
LL | const _CONST: &() = &f(&|_| {});
16+
| ^^^^^^^^^^
1317
= 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)
1418

1519
note: erroneous constant used

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

Lines changed: 10 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,19 @@
11
error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
33
|
4-
LL | const _CONST: &[u8] = &f(&[], |_| {});
5-
| -------------- inside `_CONST`
6-
...
4+
LL | panic!()
5+
| ^^^^^^^^ the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
6+
|
7+
note: inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34]>`
8+
--> $DIR/issue-88434-removal-index-should-be-less.rs:10:5
9+
|
710
LL | panic!()
811
| ^^^^^^^^
9-
| |
10-
| the evaluated program panicked at 'explicit panic', $DIR/issue-88434-removal-index-should-be-less.rs:10:5
11-
| inside `f::<[closure@$DIR/issue-88434-removal-index-should-be-less.rs:3:31: 3:34]>`
12+
note: inside `_CONST`
13+
--> $DIR/issue-88434-removal-index-should-be-less.rs:3:24
1214
|
15+
LL | const _CONST: &[u8] = &f(&[], |_| {});
16+
| ^^^^^^^^^^^^^^
1317
= 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)
1418

1519
note: erroneous constant used

src/test/ui/const-generics/generic_const_exprs/issue-80742.stderr

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -2,15 +2,18 @@ error[E0080]: evaluation of `Inline::<dyn std::fmt::Debug>::{constant#0}` failed
22
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
33
|
44
LL | intrinsics::size_of::<T>()
5-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| size_of called on unsized type `dyn Debug`
8-
| inside `std::mem::size_of::<dyn Debug>`
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ size_of called on unsized type `dyn Debug`
6+
|
7+
note: inside `std::mem::size_of::<dyn Debug>`
8+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
99
|
10-
::: $DIR/issue-80742.rs:22:10
10+
LL | intrinsics::size_of::<T>()
11+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
12+
note: inside `Inline::<dyn Debug>::{constant#0}`
13+
--> $DIR/issue-80742.rs:22:10
1114
|
1215
LL | [u8; size_of::<T>() + 1]: ,
13-
| -------------- inside `Inline::<dyn Debug>::{constant#0}`
16+
| ^^^^^^^^^^^^^^
1417

1518
error[E0599]: the function or associated item `new` exists for struct `Inline<dyn Debug>`, but its trait bounds were not satisfied
1619
--> $DIR/issue-80742.rs:30:36
@@ -33,15 +36,18 @@ error[E0080]: evaluation of `Inline::<dyn std::fmt::Debug>::{constant#0}` failed
3336
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
3437
|
3538
LL | intrinsics::size_of::<T>()
36-
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
37-
| |
38-
| size_of called on unsized type `dyn Debug`
39-
| inside `std::mem::size_of::<dyn Debug>`
39+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^ size_of called on unsized type `dyn Debug`
40+
|
41+
note: inside `std::mem::size_of::<dyn Debug>`
42+
--> $SRC_DIR/core/src/mem/mod.rs:LL:COL
4043
|
41-
::: $DIR/issue-80742.rs:14:10
44+
LL | intrinsics::size_of::<T>()
45+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^
46+
note: inside `Inline::<dyn Debug>::{constant#0}`
47+
--> $DIR/issue-80742.rs:14:10
4248
|
4349
LL | [u8; size_of::<T>() + 1]: ,
44-
| -------------- inside `Inline::<dyn Debug>::{constant#0}`
50+
| ^^^^^^^^^^^^^^
4551

4652
error[E0277]: the size for values of type `dyn Debug` cannot be known at compilation time
4753
--> $DIR/issue-80742.rs:30:15

src/test/ui/const-generics/issues/issue-100313.stderr

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,19 @@
11
error[E0080]: evaluation of constant value failed
22
--> $DIR/issue-100313.rs:10:13
33
|
4+
LL | *(B as *const bool as *mut bool) = false;
5+
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ writing to alloc7 which is read-only
6+
|
7+
note: inside `T::<&true>::set_false`
8+
--> $DIR/issue-100313.rs:10:13
9+
|
410
LL | *(B as *const bool as *mut bool) = false;
511
| ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
6-
| |
7-
| writing to alloc7 which is read-only
8-
| inside `T::<&true>::set_false`
9-
...
12+
note: inside `_`
13+
--> $DIR/issue-100313.rs:18:5
14+
|
1015
LL | x.set_false();
11-
| ------------- inside `_`
16+
| ^^^^^^^^^^^^^
1217

1318
error: aborting due to previous error
1419

0 commit comments

Comments
 (0)