1
Fork 0

output tree representation for thir-tree

This commit is contained in:
b-naber 2023-01-17 21:13:33 +01:00
parent e187f8871e
commit 90e4c13409
5 changed files with 893 additions and 4 deletions

View file

@ -439,6 +439,10 @@ fn construct_fn<'tcx>(
let fn_id = tcx.hir().local_def_id_to_hir_id(fn_def.did);
let generator_kind = tcx.generator_kind(fn_def.did);
// The representation of thir for `-Zunpretty=thir-tree` relies on
// the entry expression being the last element of `thir.exprs`.
assert_eq!(expr.as_usize(), thir.exprs.len() - 1);
// Figure out what primary body this item has.
let body_id = tcx.hir().body_owned_by(fn_def.did);
let span_with_body = tcx.hir().span_with_body(fn_id);

View file

@ -54,7 +54,10 @@ pub(crate) fn thir_body(
pub(crate) fn thir_tree(tcx: TyCtxt<'_>, owner_def: ty::WithOptConstParam<LocalDefId>) -> String {
match thir_body(tcx, owner_def) {
Ok((thir, _)) => format!("{:#?}", thir.steal()),
Ok((thir, _)) => {
let thir = thir.steal();
tcx.thir_tree_representation(&thir)
}
Err(_) => "error".into(),
}
}