Skip to content

Commit ccb0493

Browse files
committed
Fix bad printing of const-eval queries
1 parent 5b04bbf commit ccb0493

File tree

5 files changed

+52
-3
lines changed

5 files changed

+52
-3
lines changed

src/librustc_middle/mir/interpret/mod.rs

+11
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,17 @@ pub struct GlobalId<'tcx> {
143143
pub promoted: Option<mir::Promoted>,
144144
}
145145

146+
impl GlobalId<'tcx> {
147+
pub fn display(self, tcx: TyCtxt<'tcx>) -> String {
148+
let instance_name = tcx.def_path_str(self.instance.def.def_id());
149+
if let Some(promoted) = self.promoted {
150+
format!("{}::{:?}", instance_name, promoted)
151+
} else {
152+
instance_name
153+
}
154+
}
155+
}
156+
146157
/// Input argument for `tcx.lit_to_const`.
147158
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable)]
148159
pub struct LitToConstInput<'tcx> {

src/librustc_middle/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,7 @@ rustc_queries! {
679679
-> ConstEvalRawResult<'tcx> {
680680
desc { |tcx|
681681
"const-evaluating `{}`",
682-
tcx.def_path_str(key.value.instance.def.def_id())
682+
key.value.display(tcx)
683683
}
684684
}
685685

@@ -695,7 +695,7 @@ rustc_queries! {
695695
-> ConstEvalResult<'tcx> {
696696
desc { |tcx|
697697
"const-evaluating + checking `{}`",
698-
tcx.def_path_str(key.value.instance.def.def_id())
698+
key.value.display(tcx)
699699
}
700700
cache_on_disk_if(_, opt_result) {
701701
// Only store results without errors

src/test/ui/associated-const/defaults-cyclic-fail.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ note: ...which requires const-evaluating `Tr::B`...
3232
LL | const B: u8 = Self::A;
3333
| ^^^^^^^^^^^^^^^^^^^^^^
3434
= note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle
35-
note: cycle used when const-evaluating `main`
35+
note: cycle used when const-evaluating `main::promoted[2]`
3636
--> $DIR/defaults-cyclic-fail.rs:14:1
3737
|
3838
LL | fn main() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// compile-flags: -Ztreat-err-as-bug
2+
// build-fail
3+
// failure-status: 101
4+
// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> ""
5+
// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> ""
6+
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
7+
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
8+
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
9+
// normalize-stderr-test "thread.*panicked.*\n" -> ""
10+
// normalize-stderr-test "stack backtrace:\n" -> ""
11+
// normalize-stderr-test " \d{1,}: .*\n" -> ""
12+
// normalize-stderr-test ".*note: Some details.*\n" -> ""
13+
14+
#![allow(unconditional_panic)]
15+
16+
fn main() {
17+
let x: &'static i32 = &(1 / 0);
18+
//~^ ERROR reaching this expression at runtime will panic or abort [const_err]
19+
println!("x={}", x);
20+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
error: reaching this expression at runtime will panic or abort
2+
--> $DIR/const-eval-query-stack.rs:17:28
3+
|
4+
LL | let x: &'static i32 = &(1 / 0);
5+
| -^^^^^^^
6+
| |
7+
| dividing by zero
8+
|
9+
= note: `#[deny(const_err)]` on by default
10+
11+
query stack during panic:
12+
#0 [const_eval_raw] const-evaluating `main::promoted[1]`
13+
#1 [const_eval_validated] const-evaluating + checking `main::promoted[1]`
14+
#2 [const_eval_validated] const-evaluating + checking `main::promoted[1]`
15+
#3 [normalize_generic_arg_after_erasing_regions] normalizing `main::promoted[1]`
16+
#4 [optimized_mir] optimizing MIR for `main`
17+
#5 [collect_and_partition_mono_items] collect_and_partition_mono_items
18+
end of query stack

0 commit comments

Comments
 (0)