Skip to content

Commit 2e012ce

Browse files
committed
Auto merge of #83050 - osa1:issue83048, r=matthewjasper
Run analyses before thir-tree dumps Fixes #83048
2 parents 680d9fc + b24902e commit 2e012ce

File tree

4 files changed

+45
-24
lines changed

4 files changed

+45
-24
lines changed

compiler/rustc_driver/src/pretty.rs

+30-23
Original file line numberDiff line numberDiff line change
@@ -471,21 +471,6 @@ pub fn print_after_hir_lowering<'tcx>(
471471
format!("{:#?}", krate)
472472
}),
473473

474-
ThirTree => {
475-
let mut out = String::new();
476-
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
477-
debug!("pretty printing THIR tree");
478-
for did in tcx.body_owners() {
479-
let hir = tcx.hir();
480-
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
481-
let arena = thir::Arena::default();
482-
let thir =
483-
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
484-
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
485-
}
486-
out
487-
}
488-
489474
_ => unreachable!(),
490475
};
491476

@@ -501,18 +486,40 @@ fn print_with_analysis(
501486
ppm: PpMode,
502487
ofile: Option<&Path>,
503488
) -> Result<(), ErrorReported> {
504-
let mut out = Vec::new();
505-
506489
tcx.analysis(LOCAL_CRATE)?;
507490

508-
match ppm {
509-
Mir => write_mir_pretty(tcx, None, &mut out).unwrap(),
510-
MirCFG => write_mir_graphviz(tcx, None, &mut out).unwrap(),
491+
let out = match ppm {
492+
Mir => {
493+
let mut out = Vec::new();
494+
write_mir_pretty(tcx, None, &mut out).unwrap();
495+
String::from_utf8(out).unwrap()
496+
}
497+
498+
MirCFG => {
499+
let mut out = Vec::new();
500+
write_mir_graphviz(tcx, None, &mut out).unwrap();
501+
String::from_utf8(out).unwrap()
502+
}
503+
504+
ThirTree => {
505+
let mut out = String::new();
506+
abort_on_err(rustc_typeck::check_crate(tcx), tcx.sess);
507+
debug!("pretty printing THIR tree");
508+
for did in tcx.body_owners() {
509+
let hir = tcx.hir();
510+
let body = hir.body(hir.body_owned_by(hir.local_def_id_to_hir_id(did)));
511+
let arena = thir::Arena::default();
512+
let thir =
513+
thir::build_thir(tcx, ty::WithOptConstParam::unknown(did), &arena, &body.value);
514+
let _ = writeln!(out, "{:?}:\n{:#?}\n", did, thir);
515+
}
516+
out
517+
}
518+
511519
_ => unreachable!(),
512-
}
520+
};
513521

514-
let out = std::str::from_utf8(&out).unwrap();
515-
write_or_print(out, ofile);
522+
write_or_print(&out, ofile);
516523

517524
Ok(())
518525
}

compiler/rustc_session/src/config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2274,7 +2274,7 @@ impl PpMode {
22742274

22752275
pub fn needs_analysis(&self) -> bool {
22762276
use PpMode::*;
2277-
matches!(*self, Mir | MirCFG)
2277+
matches!(*self, Mir | MirCFG | ThirTree)
22782278
}
22792279
}
22802280

src/test/ui/issues/issue-83048.rs

+5
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
// compile-flags: -Z unpretty=thir-tree
2+
3+
pub fn main() {
4+
break; //~ ERROR: `break` outside of a loop [E0268]
5+
}

src/test/ui/issues/issue-83048.stderr

+9
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
error[E0268]: `break` outside of a loop
2+
--> $DIR/issue-83048.rs:4:5
3+
|
4+
LL | break;
5+
| ^^^^^ cannot `break` outside of a loop
6+
7+
error: aborting due to previous error
8+
9+
For more information about this error, try `rustc --explain E0268`.

0 commit comments

Comments
 (0)