Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix bad printing of const-eval queries #75710

Merged
merged 2 commits into from
Aug 20, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 {
RalfJung marked this conversation as resolved.
Show resolved Hide resolved
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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice job on this testcase. :)