Skip to content

Commit 0e4d196

Browse files
authored
Rollup merge of #77493 - hosseind88:ICEs_should_always_print_the_top_of_the_query_stack, r=oli-obk
ICEs should always print the top of the query stack see #76920
2 parents 85dbb03 + 46cc889 commit 0e4d196

12 files changed

+34
-13
lines changed

compiler/rustc_driver/src/lib.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -1258,9 +1258,9 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12581258
// If backtraces are enabled, also print the query stack
12591259
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
12601260

1261-
if backtrace {
1262-
TyCtxt::try_print_query_stack(&handler);
1263-
}
1261+
let num_frames = if backtrace { None } else { Some(2) };
1262+
1263+
TyCtxt::try_print_query_stack(&handler, num_frames);
12641264

12651265
#[cfg(windows)]
12661266
unsafe {

compiler/rustc_middle/src/ty/query/plumbing.rs

+10-3
Original file line numberDiff line numberDiff line change
@@ -124,20 +124,23 @@ impl<'tcx> TyCtxt<'tcx> {
124124
})
125125
}
126126

127-
pub fn try_print_query_stack(handler: &Handler) {
127+
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
128128
eprintln!("query stack during panic:");
129129

130130
// Be careful reyling on global state here: this code is called from
131131
// a panic hook, which means that the global `Handler` may be in a weird
132132
// state if it was responsible for triggering the panic.
133+
let mut i = 0;
133134
ty::tls::with_context_opt(|icx| {
134135
if let Some(icx) = icx {
135136
let query_map = icx.tcx.queries.try_collect_active_jobs();
136137

137138
let mut current_query = icx.query;
138-
let mut i = 0;
139139

140140
while let Some(query) = current_query {
141+
if Some(i) == num_frames {
142+
break;
143+
}
141144
let query_info =
142145
if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
143146
info
@@ -163,7 +166,11 @@ impl<'tcx> TyCtxt<'tcx> {
163166
}
164167
});
165168

166-
eprintln!("end of query stack");
169+
if num_frames == None || num_frames >= Some(i) {
170+
eprintln!("end of query stack");
171+
} else {
172+
eprintln!("we're just showing a limited slice of the query stack");
173+
}
167174
}
168175
}
169176

src/test/ui/proc-macro/invalid-punct-ident-1.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
1010
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
1111
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
12+
// normalize-stderr-test "query stack during panic:\n" -> ""
13+
// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
14+
// normalize-stderr-test "end of query stack\n" -> ""
1215

1316
#[macro_use]
1417
extern crate invalid_punct_ident;

src/test/ui/proc-macro/invalid-punct-ident-1.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: proc macro panicked
2-
--> $DIR/invalid-punct-ident-1.rs:16:1
2+
--> $DIR/invalid-punct-ident-1.rs:19:1
33
|
44
LL | invalid_punct!();
55
| ^^^^^^^^^^^^^^^^^

src/test/ui/proc-macro/invalid-punct-ident-2.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
1010
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
1111
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
12+
// normalize-stderr-test "query stack during panic:\n" -> ""
13+
// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
14+
// normalize-stderr-test "end of query stack\n" -> ""
1215

1316
#[macro_use]
1417
extern crate invalid_punct_ident;

src/test/ui/proc-macro/invalid-punct-ident-2.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: proc macro panicked
2-
--> $DIR/invalid-punct-ident-2.rs:16:1
2+
--> $DIR/invalid-punct-ident-2.rs:19:1
33
|
44
LL | invalid_ident!();
55
| ^^^^^^^^^^^^^^^^^

src/test/ui/proc-macro/invalid-punct-ident-3.rs

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
1010
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
1111
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
12+
// normalize-stderr-test "query stack during panic:\n" -> ""
13+
// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
14+
// normalize-stderr-test "end of query stack\n" -> ""
1215

1316
#[macro_use]
1417
extern crate invalid_punct_ident;

src/test/ui/proc-macro/invalid-punct-ident-3.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
error: proc macro panicked
2-
--> $DIR/invalid-punct-ident-3.rs:16:1
2+
--> $DIR/invalid-punct-ident-3.rs:19:1
33
|
44
LL | invalid_raw_ident!();
55
| ^^^^^^^^^^^^^^^^^^^^^

src/test/ui/proc-macro/load-panic-backtrace.rs

+3
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,9 @@
1010
// normalize-stderr-test "note: we would appreciate a bug report.*\n\n" -> ""
1111
// normalize-stderr-test "note: compiler flags.*\n\n" -> ""
1212
// normalize-stderr-test "note: rustc.*running on.*\n\n" -> ""
13+
// normalize-stderr-test "query stack during panic:\n" -> ""
14+
// normalize-stderr-test "we're just showing a limited slice of the query stack\n" -> ""
15+
// normalize-stderr-test "end of query stack\n" -> ""
1316

1417
#[macro_use]
1518
extern crate test_macros;

src/test/ui/proc-macro/load-panic-backtrace.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
at 'panic-derive', $DIR/auxiliary/test-macros.rs:43:5
22
error: proc-macro derive panicked
3-
--> $DIR/load-panic-backtrace.rs:17:10
3+
--> $DIR/load-panic-backtrace.rs:20:10
44
|
55
LL | #[derive(Panic)]
66
| ^^^^^

src/tools/clippy/src/driver.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -277,9 +277,9 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
277277
// If backtraces are enabled, also print the query stack
278278
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
279279

280-
if backtrace {
281-
TyCtxt::try_print_query_stack(&handler);
282-
}
280+
let num_frames = if backtrace { None } else { Some(2) };
281+
282+
TyCtxt::try_print_query_stack(&handler, num_frames);
283283
}
284284

285285
fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {

src/tools/clippy/tests/ui/custom_ice_message.stderr

+2
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,5 @@ note: we would appreciate a bug report: https://github.com/rust-lang/rust-clippy
99

1010
note: Clippy version: foo
1111

12+
query stack during panic:
13+
end of query stack

0 commit comments

Comments
 (0)