about summary refs log tree commit diff
diff options
context:
space:
mode:
authorJosh Stone <cuviper@gmail.com>2020-08-20 10:07:27 -0700
committerGitHub <noreply@github.com>2020-08-20 10:07:27 -0700
commit6a3425eb08a1a53d3fd7581f824c3f1934fcf466 (patch)
tree257bc9cd489e32dad12fd8ddf2ca1ad7041968fb
parent7ac126ec563cd1b987dd1aa49d4a3b9288c03771 (diff)
parentbd716753f400faa2651f6a81e38e04ee64a8624a (diff)
downloadrust-6a3425eb08a1a53d3fd7581f824c3f1934fcf466.tar.gz
rust-6a3425eb08a1a53d3fd7581f824c3f1934fcf466.zip
Rollup merge of #75710 - ThibsG:FixBadPrinting75447, r=oli-obk
Fix bad printing of const-eval queries

Fixes: #75447

r? @RalfJung

cc @oli-obk
-rw-r--r--src/librustc_middle/mir/interpret/mod.rs11
-rw-r--r--src/librustc_middle/query/mod.rs4
-rw-r--r--src/test/ui/associated-const/defaults-cyclic-fail.stderr2
-rw-r--r--src/test/ui/consts/const-eval/const-eval-query-stack.rs21
-rw-r--r--src/test/ui/consts/const-eval/const-eval-query-stack.stderr18
5 files changed, 53 insertions, 3 deletions
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<mir::Promoted>,
 }
 
+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..6962ccdec73
--- /dev/null
+++ b/src/test/ui/consts/const-eval/const-eval-query-stack.rs
@@ -0,0 +1,21 @@
+// compile-flags: -Ztreat-err-as-bug
+// build-fail
+// failure-status: 101
+// rustc-env:RUST_BACKTRACE=1
+// 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..32233a0f6ee
--- /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:18: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