Skip to content

Commit 330847e

Browse files
Properly note when query stack is being cut off
1 parent d8a6409 commit 330847e

File tree

3 files changed

+16
-11
lines changed

3 files changed

+16
-11
lines changed

compiler/rustc_driver_impl/src/lib.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1530,9 +1530,9 @@ fn report_ice(
15301530
// If backtraces are enabled, also print the query stack
15311531
let backtrace = env::var_os("RUST_BACKTRACE").is_some_and(|x| &x != "0");
15321532

1533-
let num_frames = if backtrace { None } else { Some(2) };
1533+
let limit_frames = if backtrace { None } else { Some(2) };
15341534

1535-
interface::try_print_query_stack(dcx, num_frames, file);
1535+
interface::try_print_query_stack(dcx, limit_frames, file);
15361536

15371537
// We don't trust this callback not to panic itself, so run it at the end after we're sure we've
15381538
// printed all the relevant info.

compiler/rustc_interface/src/interface.rs

+11-6
Original file line numberDiff line numberDiff line change
@@ -533,31 +533,36 @@ pub fn run_compiler<R: Send>(config: Config, f: impl FnOnce(&Compiler) -> R + Se
533533

534534
pub fn try_print_query_stack(
535535
dcx: DiagCtxtHandle<'_>,
536-
num_frames: Option<usize>,
536+
limit_frames: Option<usize>,
537537
file: Option<std::fs::File>,
538538
) {
539539
eprintln!("query stack during panic:");
540540

541541
// Be careful relying on global state here: this code is called from
542542
// a panic hook, which means that the global `DiagCtxt` may be in a weird
543543
// state if it was responsible for triggering the panic.
544-
let i = ty::tls::with_context_opt(|icx| {
544+
let all_frames = ty::tls::with_context_opt(|icx| {
545545
if let Some(icx) = icx {
546546
ty::print::with_no_queries!(print_query_stack(
547547
QueryCtxt::new(icx.tcx),
548548
icx.query,
549549
dcx,
550-
num_frames,
550+
limit_frames,
551551
file,
552552
))
553553
} else {
554554
0
555555
}
556556
});
557557

558-
if num_frames == None || num_frames >= Some(i) {
559-
eprintln!("end of query stack");
558+
if let Some(limit_frames) = limit_frames
559+
&& all_frames > limit_frames
560+
{
561+
eprintln!(
562+
"... and {} other queries... use `env RUST_BACKTRACE=1` to see the full query stack",
563+
all_frames - limit_frames
564+
);
560565
} else {
561-
eprintln!("we're just showing a limited slice of the query stack");
566+
eprintln!("end of query stack");
562567
}
563568
}

compiler/rustc_query_system/src/query/job.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -567,7 +567,7 @@ pub fn print_query_stack<Qcx: QueryContext>(
567567
qcx: Qcx,
568568
mut current_query: Option<QueryJobId>,
569569
dcx: DiagCtxtHandle<'_>,
570-
num_frames: Option<usize>,
570+
limit_frames: Option<usize>,
571571
mut file: Option<std::fs::File>,
572572
) -> usize {
573573
// Be careful relying on global state here: this code is called from
@@ -584,7 +584,7 @@ pub fn print_query_stack<Qcx: QueryContext>(
584584
let Some(query_info) = query_map.get(&query) else {
585585
break;
586586
};
587-
if Some(count_printed) < num_frames || num_frames.is_none() {
587+
if Some(count_printed) < limit_frames || limit_frames.is_none() {
588588
// Only print to stderr as many stack frames as `num_frames` when present.
589589
// FIXME: needs translation
590590
#[allow(rustc::diagnostic_outside_of_impl)]
@@ -615,5 +615,5 @@ pub fn print_query_stack<Qcx: QueryContext>(
615615
if let Some(ref mut file) = file {
616616
let _ = writeln!(file, "end of query stack");
617617
}
618-
count_printed
618+
count_total
619619
}

0 commit comments

Comments
 (0)