diff --git a/compiler/rustc_driver/src/pretty.rs b/compiler/rustc_driver/src/pretty.rs index 5512bd74453e..1544c9758387 100644 --- a/compiler/rustc_driver/src/pretty.rs +++ b/compiler/rustc_driver/src/pretty.rs @@ -471,6 +471,36 @@ pub fn print_after_hir_lowering<'tcx>( format!("{:#?}", krate) }), + _ => unreachable!(), + }; + + write_or_print(&out, ofile); +} + +// In an ideal world, this would be a public function called by the driver after +// analysis is performed. However, we want to call `phase_3_run_analysis_passes` +// with a different callback than the standard driver, so that isn't easy. +// Instead, we call that function ourselves. +fn print_with_analysis( + tcx: TyCtxt<'_>, + ppm: PpMode, + ofile: Option<&Path>, +) -> Result<(), ErrorReported> { + tcx.analysis(LOCAL_CRATE)?; + + 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); @@ -490,29 +520,6 @@ pub fn print_after_hir_lowering<'tcx>( }; write_or_print(&out, ofile); -} - -// In an ideal world, this would be a public function called by the driver after -// analysis is performed. However, we want to call `phase_3_run_analysis_passes` -// with a different callback than the standard driver, so that isn't easy. -// Instead, we call that function ourselves. -fn print_with_analysis( - tcx: TyCtxt<'_>, - 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(), - _ => unreachable!(), - } - - let out = std::str::from_utf8(&out).unwrap(); - write_or_print(out, ofile); Ok(()) } diff --git a/compiler/rustc_session/src/config.rs b/compiler/rustc_session/src/config.rs index 75078a123116..8d47ddca1882 100644 --- a/compiler/rustc_session/src/config.rs +++ b/compiler/rustc_session/src/config.rs @@ -2274,7 +2274,7 @@ impl PpMode { 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 index 000000000000..520ae974398b --- /dev/null +++ b/src/test/ui/issues/issue-83048.rs @@ -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 index 000000000000..62d67d75844a --- /dev/null +++ b/src/test/ui/issues/issue-83048.stderr @@ -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`.