From ccb049387afae7772ca16c1ff876d38a9d0c53c9 Mon Sep 17 00:00:00 2001 From: ThibsG Date: Wed, 19 Aug 2020 12:05:32 +0200 Subject: [PATCH] Fix bad printing of const-eval queries --- src/librustc_middle/mir/interpret/mod.rs | 11 ++++++++++ src/librustc_middle/query/mod.rs | 4 ++-- .../defaults-cyclic-fail.stderr | 2 +- .../const-eval/const-eval-query-stack.rs | 20 +++++++++++++++++++ .../const-eval/const-eval-query-stack.stderr | 18 +++++++++++++++++ 5 files changed, 52 insertions(+), 3 deletions(-) create mode 100644 src/test/ui/consts/const-eval/const-eval-query-stack.rs create mode 100644 src/test/ui/consts/const-eval/const-eval-query-stack.stderr diff --git a/src/librustc_middle/mir/interpret/mod.rs b/src/librustc_middle/mir/interpret/mod.rs index fb7269f648f..0dc3d6e344a 100644 --- a/src/librustc_middle/mir/interpret/mod.rs +++ b/src/librustc_middle/mir/interpret/mod.rs @@ -143,6 +143,17 @@ pub struct GlobalId<'tcx> { pub promoted: Option, } +impl GlobalId<'tcx> { + pub fn display(self, tcx: TyCtxt<'tcx>) -> String { + let instance_name = tcx.def_path_str(self.instance.def.def_id()); + if let Some(promoted) = self.promoted { + format!("{}::{:?}", instance_name, promoted) + } else { + instance_name + } + } +} + /// Input argument for `tcx.lit_to_const`. #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable)] pub struct LitToConstInput<'tcx> { diff --git a/src/librustc_middle/query/mod.rs b/src/librustc_middle/query/mod.rs index d874edf6274..f5029eb7404 100644 --- a/src/librustc_middle/query/mod.rs +++ b/src/librustc_middle/query/mod.rs @@ -679,7 +679,7 @@ rustc_queries! { -> ConstEvalRawResult<'tcx> { desc { |tcx| "const-evaluating `{}`", - tcx.def_path_str(key.value.instance.def.def_id()) + key.value.display(tcx) } } @@ -695,7 +695,7 @@ rustc_queries! { -> ConstEvalResult<'tcx> { desc { |tcx| "const-evaluating + checking `{}`", - tcx.def_path_str(key.value.instance.def.def_id()) + key.value.display(tcx) } cache_on_disk_if(_, opt_result) { // Only store results without errors diff --git a/src/test/ui/associated-const/defaults-cyclic-fail.stderr b/src/test/ui/associated-const/defaults-cyclic-fail.stderr index 6b2fbe5be4e..e6075f74577 100644 --- a/src/test/ui/associated-const/defaults-cyclic-fail.stderr +++ b/src/test/ui/associated-const/defaults-cyclic-fail.stderr @@ -32,7 +32,7 @@ note: ...which requires const-evaluating `Tr::B`... LL | const B: u8 = Self::A; | ^^^^^^^^^^^^^^^^^^^^^^ = note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle -note: cycle used when const-evaluating `main` +note: cycle used when const-evaluating `main::promoted[2]` --> $DIR/defaults-cyclic-fail.rs:14:1 | LL | fn main() { diff --git a/src/test/ui/consts/const-eval/const-eval-query-stack.rs b/src/test/ui/consts/const-eval/const-eval-query-stack.rs new file mode 100644 index 00000000000..aae8233665a --- /dev/null +++ b/src/test/ui/consts/const-eval/const-eval-query-stack.rs @@ -0,0 +1,20 @@ +// compile-flags: -Ztreat-err-as-bug +// build-fail +// failure-status: 101 +// normalize-stderr-test "\nerror: internal compiler error.*\n\n" -> "" +// normalize-stderr-test "note:.*unexpectedly panicked.*\n\n" -> "" +// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> "" +// normalize-stderr-test "note: compiler flags.*\n\n" -> "" +// normalize-stderr-test "note: rustc.*running on.*\n\n" -> "" +// normalize-stderr-test "thread.*panicked.*\n" -> "" +// normalize-stderr-test "stack backtrace:\n" -> "" +// normalize-stderr-test " \d{1,}: .*\n" -> "" +// normalize-stderr-test ".*note: Some details.*\n" -> "" + +#![allow(unconditional_panic)] + +fn main() { + let x: &'static i32 = &(1 / 0); + //~^ ERROR reaching this expression at runtime will panic or abort [const_err] + println!("x={}", x); +} diff --git a/src/test/ui/consts/const-eval/const-eval-query-stack.stderr b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr new file mode 100644 index 00000000000..44b3c56b393 --- /dev/null +++ b/src/test/ui/consts/const-eval/const-eval-query-stack.stderr @@ -0,0 +1,18 @@ +error: reaching this expression at runtime will panic or abort + --> $DIR/const-eval-query-stack.rs:17:28 + | +LL | let x: &'static i32 = &(1 / 0); + | -^^^^^^^ + | | + | dividing by zero + | + = note: `#[deny(const_err)]` on by default + +query stack during panic: +#0 [const_eval_raw] const-evaluating `main::promoted[1]` +#1 [const_eval_validated] const-evaluating + checking `main::promoted[1]` +#2 [const_eval_validated] const-evaluating + checking `main::promoted[1]` +#3 [normalize_generic_arg_after_erasing_regions] normalizing `main::promoted[1]` +#4 [optimized_mir] optimizing MIR for `main` +#5 [collect_and_partition_mono_items] collect_and_partition_mono_items +end of query stack