about summary refs log tree commit diff
diff options
context:
space:
mode:
authorhosseind75 <dindar95@bk.ru>2020-09-19 18:37:58 +0430
committerhosseind88 <hosseind88@mail.ru>2020-10-09 20:57:45 +0330
commit20ea9290ed152b0c25cf4f54dbe2c4a269ecace7 (patch)
tree5f376cf5560ef35c0cc08d06baebed432e638d57
parent17eb8d8b34a733640a0565e5ae589711f28c6e7a (diff)
downloadrust-20ea9290ed152b0c25cf4f54dbe2c4a269ecace7.tar.gz
rust-20ea9290ed152b0c25cf4f54dbe2c4a269ecace7.zip
run full query stack print just when RUST_BACKTRACE is set
-rw-r--r--compiler/rustc_driver/src/lib.rs5
-rw-r--r--compiler/rustc_middle/src/ty/query/plumbing.rs10
-rw-r--r--src/tools/clippy/src/driver.rs5
3 files changed, 15 insertions, 5 deletions
diff --git a/compiler/rustc_driver/src/lib.rs b/compiler/rustc_driver/src/lib.rs
index a6648639509..177256008f8 100644
--- a/compiler/rustc_driver/src/lib.rs
+++ b/compiler/rustc_driver/src/lib.rs
@@ -1211,7 +1211,10 @@ pub fn report_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
         handler.note_without_error(&note);
     }
 
-    TyCtxt::try_print_query_stack(&handler, Some(2));
+    // If backtraces are enabled, also print the query stack
+    let backtrace = env::var_os("RUST_BACKTRACE").map(|x| &x != "0").unwrap_or(false);
+
+    TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace));
 
     #[cfg(windows)]
     unsafe {
diff --git a/compiler/rustc_middle/src/ty/query/plumbing.rs b/compiler/rustc_middle/src/ty/query/plumbing.rs
index 6debd0cc7f3..239d5bce607 100644
--- a/compiler/rustc_middle/src/ty/query/plumbing.rs
+++ b/compiler/rustc_middle/src/ty/query/plumbing.rs
@@ -124,7 +124,11 @@ impl<'tcx> TyCtxt<'tcx> {
         })
     }
 
-    pub fn try_print_query_stack(handler: &Handler, num_frames: Option<usize>) {
+    pub fn try_print_query_stack(
+        handler: &Handler,
+        num_frames: Option<usize>,
+        backtrace: Option<bool>,
+    ) {
         eprintln!("query stack during panic:");
 
         // Be careful reyling on global state here: this code is called from
@@ -138,9 +142,9 @@ impl<'tcx> TyCtxt<'tcx> {
                 let mut i = 0;
 
                 while let Some(query) = current_query {
-                    if i == num_frames.unwrap() {
+                    if backtrace.unwrap() == false && i == num_frames.unwrap() {
                         break;
-                    } 
+                    }
                     let query_info =
                         if let Some(info) = query_map.as_ref().and_then(|map| map.get(&query)) {
                             info
diff --git a/src/tools/clippy/src/driver.rs b/src/tools/clippy/src/driver.rs
index c88dffc88f4..0b324775b0d 100644
--- a/src/tools/clippy/src/driver.rs
+++ b/src/tools/clippy/src/driver.rs
@@ -274,7 +274,10 @@ fn report_clippy_ice(info: &panic::PanicInfo<'_>, bug_report_url: &str) {
         handler.note_without_error(&note);
     }
 
-    TyCtxt::try_print_query_stack(&handler, Some(2));
+    // If backtraces are enabled, also print the query stack
+    let backtrace = env::var_os("RUST_BACKTRACE").map_or(false, |x| &x != "0");
+
+    TyCtxt::try_print_query_stack(&handler, Some(2), Some(backtrace));
 }
 
 fn toolchain_path(home: Option<String>, toolchain: Option<String>) -> Option<PathBuf> {