Fix bad printing of const-eval queries

This commit is contained in:
ThibsG 2020-08-19 12:05:32 +02:00
parent 5b04bbfcbb
commit ccb049387a
5 changed files with 52 additions and 3 deletions

View file

@ -143,6 +143,17 @@ pub struct GlobalId<'tcx> {
pub promoted: Option<mir::Promoted>, 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`. /// Input argument for `tcx.lit_to_const`.
#[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable)] #[derive(Copy, Clone, Debug, Eq, PartialEq, Hash, HashStable)]
pub struct LitToConstInput<'tcx> { pub struct LitToConstInput<'tcx> {

View file

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

View file

@ -32,7 +32,7 @@ note: ...which requires const-evaluating `Tr::B`...
LL | const B: u8 = Self::A; LL | const B: u8 = Self::A;
| ^^^^^^^^^^^^^^^^^^^^^^ | ^^^^^^^^^^^^^^^^^^^^^^
= note: ...which again requires normalizing `<() as Tr>::A`, completing the cycle = 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 --> $DIR/defaults-cyclic-fail.rs:14:1
| |
LL | fn main() { LL | fn main() {

View file

@ -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);
}

View file

@ -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