Skip to content

Commit 132c9ef

Browse files
committed
run full query stack print just when RUST_BACKTRACE is set
1 parent 5fd6301 commit 132c9ef

File tree

3 files changed

+15
-5
lines changed

3 files changed

+15
-5
lines changed

compiler/rustc_driver/src/lib.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1202,7 +1202,10 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
12021202
handler.note_without_error(&note);
12031203
}
12041204

1205-
TyCtxt::try_print_query_stack(&handler, Some(2));
1205+
// If backtraces are enabled, also print the query stack
1206+
let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
1207+
1208+
TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace));
12061209

12071210
#[cfg(windows)]
12081211
unsafe {

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

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,11 @@ impl<'tcx> TyCtxt<'tcx> {
124124
})
125125
}
126126

127-
pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
127+
pub fn try_print_query_stack(
128+
handler: &Handler,
129+
num_frames: Option<usize>,
130+
backtrace: Option<bool>,
131+
) {
128132
eprintln!("query stack during panic:");
129133

130134
// Be careful reyling on global state here: this code is called from
@@ -138,9 +142,9 @@ impl<'tcx> TyCtxt<'tcx> {
138142
let mut i = 0;
139143

140144
while let Some(query) = current_query {
141-
if i == num_frames.unwrap() {
145+
if backtrace.unwrap() == false && i == num_frames.unwrap() {
142146
break;
143-
}
147+
}
144148
let query_info =
145149
if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
146150
info

src/tools/clippy/src/driver.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,10 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
274274
handler.note_without_error(&note);
275275
}
276276

277-
TyCtxt::try_print_query_stack(&handler, Some(2));
277+
// If backtraces are enabled, also print the query stack
278+
let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
279+
280+
TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace));
278281
}
279282

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

0 commit comments

Comments
 (0)