Skip to content

Commit f2d94c1

Browse files
committed
unpretty=thir-tree: don't require the final expr to be the entrypoint
1 parent 444a627 commit f2d94c1

File tree

2 files changed

+4
-9
lines changed

2 files changed

+4
-9
lines changed

compiler/rustc_mir_build/src/builder/mod.rs

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -451,10 +451,6 @@ fn construct_fn<'tcx>(
451451
let span = tcx.def_span(fn_def);
452452
let fn_id = tcx.local_def_id_to_hir_id(fn_def);
453453

454-
// The representation of thir for `-Zunpretty=thir-tree` relies on
455-
// the entry expression being the last element of `thir.exprs`.
456-
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);
457-
458454
// Figure out what primary body this item has.
459455
let body = tcx.hir_body_owned_by(fn_def);
460456
let span_with_body = tcx.hir_span_with_body(fn_id);

compiler/rustc_mir_build/src/thir/print.rs

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -8,10 +8,10 @@ use rustc_span::def_id::LocalDefId;
88
/// Create a THIR tree for debugging.
99
pub fn thir_tree(tcx: TyCtxt<'_>, owner_def: LocalDefId) -> String {
1010
match super::cx::thir_body(tcx, owner_def) {
11-
Ok((thir, _)) => {
11+
Ok((thir, expr)) => {
1212
let thir = thir.steal();
1313
let mut printer = ThirPrinter::new(&thir);
14-
printer.print();
14+
printer.print(expr);
1515
printer.into_buffer()
1616
}
1717
Err(_) => "error".into(),
@@ -58,16 +58,15 @@ impl<'a, 'tcx> ThirPrinter<'a, 'tcx> {
5858
}
5959
}
6060

61-
fn print(&mut self) {
61+
fn print(&mut self, body_expr: ExprId) {
6262
print_indented!(self, "params: [", 0);
6363
for param in self.thir.params.iter() {
6464
self.print_param(param, 1);
6565
}
6666
print_indented!(self, "]", 0);
6767

6868
print_indented!(self, "body:", 0);
69-
let expr = ExprId::from_usize(self.thir.exprs.len() - 1);
70-
self.print_expr(expr, 1);
69+
self.print_expr(body_expr, 1);
7170
}
7271

7372
fn into_buffer(self) -> String {

0 commit comments

Comments
 (0)