about summary refs log tree commit diff
path: root/compiler/rustc_driver/src
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2021-03-24 12:02:13 +0000
committerbors <bors@rust-lang.org>2021-03-24 12:02:13 +0000
commit2e012ce681b4d116c2ce2d285d09e03a794482cb (patch)
tree41f333b1d22ff9d329d53d6ea38830b065bd7867 /compiler/rustc_driver/src
parent680d9fcac1dec4b671707e0ffc6bf95ac7115ebe (diff)
parentb24902ea18e53fde6ec1814953e68be62e71b8ee (diff)
downloadrust-2e012ce681b4d116c2ce2d285d09e03a794482cb.tar.gz
rust-2e012ce681b4d116c2ce2d285d09e03a794482cb.zip
Auto merge of #83050 - osa1:issue83048, r=matthewjasper
Run analyses before thir-tree dumps

Fixes #83048
Diffstat (limited to 'compiler/rustc_driver/src')
-rw-r--r--compiler/rustc_driver/src/pretty.rs53
1 files changed, 30 insertions, 23 deletions
diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs
index 5512bd74453..1544c975838 100644
--- a/compiler/rustc_driver/src/pretty.rs
+++ b/compiler/rustc_driver/src/pretty.rs
@@ -471,21 +471,6 @@ pub fn print_after_hir_lowering<'tcx>(
             format!("{:#?}", krate)
         }),
 
-        ThirTree => {
-            let mut out = String::new();
-            abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
-            debug!("pretty printing THIR tree");
-            for did in tcx.body_owners() {
-                let hir = tcx.hir();
-                let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
-                let arena = thir::Arena::default();
-                let thir =
-                    thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
-                let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
-            }
-            out
-        }
-
         _ => unreachable!(),
     };
 
@@ -501,18 +486,40 @@ fn print_with_analysis(
     ppm: PpMode,
     ofile: Option<&Path>,
 ) -> Result<(), ErrorReported> {
-    let mut out = Vec::new();
-
     tcx.analysis(LOCAL_CRATE)?;
 
-    match ppm {
-        Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
-        MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
+    let out = match ppm {
+        Mir => {
+            let mut out = Vec::new();
+            write_mir_pretty(tcx, None, &mut out).unwrap();
+            String::from_utf8(out).unwrap()
+        }
+
+        MirCFG => {
+            let mut out = Vec::new();
+            write_mir_graphviz(tcx, None, &mut out).unwrap();
+            String::from_utf8(out).unwrap()
+        }
+
+        ThirTree => {
+            let mut out = String::new();
+            abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
+            debug!("pretty printing THIR tree");
+            for did in tcx.body_owners() {
+                let hir = tcx.hir();
+                let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
+                let arena = thir::Arena::default();
+                let thir =
+                    thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
+                let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
+            }
+            out
+        }
+
         _ => unreachable!(),
-    }
+    };
 
-    let out = std::str::from_utf8(&out).unwrap();
-    write_or_print(out, ofile);
+    write_or_print(&out, ofile);
 
     Ok(())
 }