]> git.lizzy.rs Git - rust.git/commitdiff
Auto merge of #83050 - osa1:issue83048, r=matthewjasper
authorbors <bors@rust-lang.org>
Wed, 24 Mar 2021 12:02:13 +0000 (12:02 +0000)
committerbors <bors@rust-lang.org>
Wed, 24 Mar 2021 12:02:13 +0000 (12:02 +0000)
Run analyses before thir-tree dumps

Fixes #83048

compiler/rustc_driver/src/pretty.rs
compiler/rustc_session/src/config.rs
src/test/ui/issues/issue-83048.rs [new file with mode: 0644]
src/test/ui/issues/issue-83048.stderr [new file with mode: 0644]

index 5512bd74453e54eace3b0bd17fc11847eb464f38..1544c9758387f81ed3312577d77bb34427d32083 100644 (file)
@@ -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(())
 }
index 75078a12311630b4c8fde27b58752b5f3a6cc6a3..8d47ddca18824c5f0fa6752c3c6912627da0bcad 100644 (file)
@@ -2274,7 +2274,7 @@ pub fn needs_ast_map(&self) -> bool {
 
     pub fn needs_analysis(&self) -> bool {
         use PpMode::*;
-        matches!(*self, Mir | MirCFG)
+        matches!(*self, Mir | MirCFG | ThirTree)
     }
 }
 
diff --git a/src/test/ui/issues/issue-83048.rs b/src/test/ui/issues/issue-83048.rs
new file mode 100644 (file)
index 0000000..520ae97
--- /dev/null
@@ -0,0 +1,5 @@
+// compile-flags: -Z unpretty=thir-tree
+
+pub fn main() {
+    break; //~ ERROR: `break` outside of a loop [E0268]
+}
diff --git a/src/test/ui/issues/issue-83048.stderr b/src/test/ui/issues/issue-83048.stderr
new file mode 100644 (file)
index 0000000..62d67d7
--- /dev/null
@@ -0,0 +1,9 @@
+error[E0268]: `break` outside of a loop
+  --> $DIR/issue-83048.rs:4:5
+   |
+LL |     break;
+   |     ^^^^^ cannot `break` outside of a loop
+
+error: aborting due to previous error
+
+For more information about this error, try `rustc --explain E0268`.