Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 3a5f871

Browse files
authoredJan 22, 2025
Rollup merge of rust-lang#135596 - compiler-errors:stack, r=oli-obk
Properly note when query stack is being cut off cc rust-lang#70953 also, i'm not certain whether we should even limit this at all. i don't see the problem with printing the full query stack, apparently it was limited b/c we used to ICE? but we're already printing the full stack to disk since rust-lang#108714. r? oli-obk
2 parents 5ce6ad6 + be56f10 commit 3a5f871

File tree

7 files changed

+20
-15
lines changed

7 files changed

+20
-15
lines changed
 

‎compiler/rustc_driver_impl/src/lib.rs

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

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

1533-
interface::try_print_query_stack(dcx, num_frames, file);
1533+
interface::try_print_query_stack(dcx, limit_frames, file);
15341534

15351535
// We don't trust this callback not to panic itself, so run it at the end after we're sure we've
15361536
// 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
}

‎tests/ui/const-generics/generic_const_exprs/issue-80742.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Box<dyn Any>
66
query stack during panic:
77
#0 [eval_to_allocation_raw] const-evaluating + checking `<impl at $DIR/issue-80742.rs:26:1: 28:32>::{constant#0}`
88
#1 [eval_to_valtree] evaluating type-level constant
9-
end of query stack
9+
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
1010
error: aborting due to 1 previous error
1111

‎tests/ui/layout/valid_range_oob.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,4 @@ error: the compiler unexpectedly panicked. this is a bug.
55
query stack during panic:
66
#0 [layout_of] computing layout of `Foo`
77
#1 [eval_to_allocation_raw] const-evaluating + checking `FOO`
8-
end of query stack
8+
... and 2 other queries... use `env RUST_BACKTRACE=1` to see the full query stack

‎tests/ui/resolve/multiple_definitions_attribute_merging.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ Box<dyn Any>
2121
query stack during panic:
2222
#0 [mir_built] building MIR for `<impl at $DIR/multiple_definitions_attribute_merging.rs:15:10: 15:19>::eq`
2323
#1 [check_unsafety] unsafety-checking `<impl at $DIR/multiple_definitions_attribute_merging.rs:15:10: 15:19>::eq`
24-
end of query stack
24+
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
2525
error: aborting due to 2 previous errors
2626

2727
For more information about this error, try `rustc --explain E0428`.

‎tests/ui/resolve/proc_macro_generated_packed.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,6 @@ Box<dyn Any>
1212
query stack during panic:
1313
#0 [mir_built] building MIR for `<impl at $DIR/proc_macro_generated_packed.rs:15:10: 15:19>::eq`
1414
#1 [check_unsafety] unsafety-checking `<impl at $DIR/proc_macro_generated_packed.rs:15:10: 15:19>::eq`
15-
end of query stack
15+
... and 1 other queries... use `env RUST_BACKTRACE=1` to see the full query stack
1616
error: aborting due to 1 previous error
1717

0 commit comments

Comments
 (0)
Please sign in to comment.