Skip to content

Commit

Permalink
Rollup merge of #75710 - ThibsG:FixBadPrinting75447, r=oli-obk
Browse files Browse the repository at this point in the history
Fix bad printing of const-eval queries

Fixes: #75447

r? @RalfJung

cc @oli-obk
  • Loading branch information
cuviper committed Aug 20, 2020
2 parents 7ac126e + bd71675 commit 6a3425e
Show file tree
Hide file tree
Showing 5 changed files with 53 additions and 3 deletions.
11 changes: 11 additions & 0 deletions src/librustc_middle/mir/interpret/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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> {
Expand Down
4 changes: 2 additions & 2 deletions src/librustc_middle/query/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand All @@ -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
Expand Down
2 changes: 1 addition & 1 deletion src/test/ui/associated-const/defaults-cyclic-fail.stderr
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
21 changes: 21 additions & 0 deletions src/test/ui/consts/const-eval/const-eval-query-stack.rs
Original file line number Diff line number Diff line change
@@ -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);
}
18 changes: 18 additions & 0 deletions src/test/ui/consts/const-eval/const-eval-query-stack.stderr
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 6a3425e

Please sign in to comment.