2018-11-27 02:59:49 +00:00
|
|
|
//! The various pretty-printing routines.
|
2014-08-11 10:59:35 +00:00
|
|
|
|
2020-04-27 17:56:11 +00:00
|
|
|
use std::cell::Cell;
|
|
|
|
use std::fmt::Write;
|
2024-07-28 22:13:50 +00:00
|
|
|
|
2023-10-09 23:01:52 +00:00
|
|
|
use rustc_ast_pretty::pprust as pprust_ast;
|
2023-10-10 21:49:24 +00:00
|
|
|
use rustc_middle::bug;
|
2021-01-05 18:53:07 +00:00
|
|
|
use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
|
2020-03-29 15:19:48 +00:00
|
|
|
use rustc_middle::ty::{self, TyCtxt};
|
2025-01-31 03:42:19 +00:00
|
|
|
use rustc_mir_build::thir::print::{thir_flat, thir_tree};
|
2020-03-11 11:49:08 +00:00
|
|
|
use rustc_session::Session;
|
2023-10-10 01:17:06 +00:00
|
|
|
use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
|
2023-11-08 09:37:26 +00:00
|
|
|
use rustc_smir::rustc_internal::pretty::write_smir_pretty;
|
2024-12-12 23:29:23 +00:00
|
|
|
use rustc_span::{FileName, Ident};
|
2024-04-29 06:24:06 +00:00
|
|
|
use tracing::debug;
|
2023-10-09 23:01:52 +00:00
|
|
|
use {rustc_ast as ast, rustc_hir_pretty as pprust_hir};
|
2014-08-11 10:59:35 +00:00
|
|
|
|
2018-11-27 02:59:49 +00:00
|
|
|
pub use self::PpMode::*;
|
|
|
|
pub use self::PpSourceMode::*;
|
2018-12-08 19:30:23 +00:00
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
struct AstNoAnn;
|
|
|
|
|
|
|
|
impl pprust_ast::PpAnn for AstNoAnn {}
|
|
|
|
|
|
|
|
struct AstIdentifiedAnn;
|
2014-08-11 10:59:35 +00:00
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
impl pprust_ast::PpAnn for AstIdentifiedAnn {
|
2023-10-09 23:01:52 +00:00
|
|
|
fn pre(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
|
|
|
|
if let pprust_ast::AnnNode::Expr(_) = node {
|
2020-03-22 12:36:56 +00:00
|
|
|
s.popen();
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-10 01:58:12 +00:00
|
|
|
|
2023-10-09 23:01:52 +00:00
|
|
|
fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
|
2014-08-11 10:59:35 +00:00
|
|
|
match node {
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Crate(_)
|
|
|
|
| pprust_ast::AnnNode::Ident(_)
|
|
|
|
| pprust_ast::AnnNode::Name(_) => {}
|
2014-08-11 12:01:37 +00:00
|
|
|
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Item(item) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2014-08-11 10:59:35 +00:00
|
|
|
s.synth_comment(item.id.to_string())
|
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::SubItem(id) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2015-03-24 01:52:55 +00:00
|
|
|
s.synth_comment(id.to_string())
|
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Block(blk) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2014-08-11 10:59:35 +00:00
|
|
|
s.synth_comment(format!("block {}", blk.id))
|
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Expr(expr) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
|
|
|
s.synth_comment(expr.id.to_string());
|
2014-08-11 10:59:35 +00:00
|
|
|
s.pclose()
|
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Pat(pat) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
|
|
|
s.synth_comment(format!("pat {}", pat.id));
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
struct HirIdentifiedAnn<'tcx> {
|
|
|
|
tcx: TyCtxt<'tcx>,
|
|
|
|
}
|
|
|
|
|
|
|
|
impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
|
2019-06-24 18:15:11 +00:00
|
|
|
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
|
2024-05-30 00:51:11 +00:00
|
|
|
self.tcx.nested(state, nested)
|
2016-12-27 08:00:18 +00:00
|
|
|
}
|
2023-10-10 01:58:12 +00:00
|
|
|
|
2019-06-24 18:15:11 +00:00
|
|
|
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
|
2020-03-22 12:36:56 +00:00
|
|
|
if let pprust_hir::AnnNode::Expr(_) = node {
|
|
|
|
s.popen();
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-10 01:58:12 +00:00
|
|
|
|
2019-06-24 18:15:11 +00:00
|
|
|
fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
|
2015-07-31 07:04:06 +00:00
|
|
|
match node {
|
2019-06-24 18:15:11 +00:00
|
|
|
pprust_hir::AnnNode::Name(_) => {}
|
2018-08-22 21:05:19 +00:00
|
|
|
pprust_hir::AnnNode::Item(item) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2021-01-30 16:47:51 +00:00
|
|
|
s.synth_comment(format!("hir_id: {}", item.hir_id()));
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
2018-08-22 21:05:19 +00:00
|
|
|
pprust_hir::AnnNode::SubItem(id) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2019-06-29 14:31:43 +00:00
|
|
|
s.synth_comment(id.to_string());
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
2018-08-22 21:05:19 +00:00
|
|
|
pprust_hir::AnnNode::Block(blk) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2019-06-29 14:31:43 +00:00
|
|
|
s.synth_comment(format!("block hir_id: {}", blk.hir_id));
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
2018-08-22 21:05:19 +00:00
|
|
|
pprust_hir::AnnNode::Expr(expr) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2019-06-29 14:31:43 +00:00
|
|
|
s.synth_comment(format!("expr hir_id: {}", expr.hir_id));
|
|
|
|
s.pclose();
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
2018-08-22 21:05:19 +00:00
|
|
|
pprust_hir::AnnNode::Pat(pat) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2019-06-29 14:31:43 +00:00
|
|
|
s.synth_comment(format!("pat hir_id: {}", pat.hir_id));
|
|
|
|
}
|
2025-01-07 10:24:16 +00:00
|
|
|
pprust_hir::AnnNode::TyPat(pat) => {
|
|
|
|
s.s.space();
|
|
|
|
s.synth_comment(format!("ty pat hir_id: {}", pat.hir_id));
|
|
|
|
}
|
2019-06-29 14:31:43 +00:00
|
|
|
pprust_hir::AnnNode::Arm(arm) => {
|
|
|
|
s.s.space();
|
|
|
|
s.synth_comment(format!("arm hir_id: {}", arm.hir_id));
|
2015-07-31 07:04:06 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
struct AstHygieneAnn<'a> {
|
2017-01-26 01:21:50 +00:00
|
|
|
sess: &'a Session,
|
2014-08-11 12:01:37 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
impl<'a> pprust_ast::PpAnn for AstHygieneAnn<'a> {
|
2023-10-09 23:01:52 +00:00
|
|
|
fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
|
2014-08-11 12:01:37 +00:00
|
|
|
match node {
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Ident(&Ident { name, span }) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2018-03-17 23:57:23 +00:00
|
|
|
s.synth_comment(format!("{}{:?}", name.as_u32(), span.ctxt()))
|
2014-08-11 12:01:37 +00:00
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Name(&name) => {
|
2019-06-24 18:15:11 +00:00
|
|
|
s.s.space();
|
2016-11-16 08:21:52 +00:00
|
|
|
s.synth_comment(name.as_u32().to_string())
|
2014-08-11 12:01:37 +00:00
|
|
|
}
|
2023-10-09 23:01:52 +00:00
|
|
|
pprust_ast::AnnNode::Crate(_) => {
|
2019-07-14 20:17:37 +00:00
|
|
|
s.s.hardbreak();
|
2023-12-19 17:39:58 +00:00
|
|
|
let verbose = self.sess.verbose_internals();
|
2019-12-31 17:15:40 +00:00
|
|
|
s.synth_comment(rustc_span::hygiene::debug_hygiene_data(verbose));
|
2019-07-14 20:17:37 +00:00
|
|
|
s.s.hardbreak_if_not_bol();
|
|
|
|
}
|
2019-06-24 18:15:11 +00:00
|
|
|
_ => {}
|
2014-08-11 12:01:37 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
struct HirTypedAnn<'tcx> {
|
2019-06-13 21:48:52 +00:00
|
|
|
tcx: TyCtxt<'tcx>,
|
2020-07-17 08:47:04 +00:00
|
|
|
maybe_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 22:47:15 +00:00
|
|
|
impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
|
2019-06-24 18:15:11 +00:00
|
|
|
fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
|
2020-07-17 08:47:04 +00:00
|
|
|
let old_maybe_typeck_results = self.maybe_typeck_results.get();
|
2017-01-06 19:54:24 +00:00
|
|
|
if let pprust_hir::Nested::Body(id) = nested {
|
2020-07-17 08:47:04 +00:00
|
|
|
self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
|
2017-01-06 19:54:24 +00:00
|
|
|
}
|
2024-05-30 00:51:11 +00:00
|
|
|
self.tcx.nested(state, nested);
|
2020-07-17 08:47:04 +00:00
|
|
|
self.maybe_typeck_results.set(old_maybe_typeck_results);
|
2016-12-27 08:00:18 +00:00
|
|
|
}
|
2023-10-10 01:58:12 +00:00
|
|
|
|
2019-06-24 18:15:11 +00:00
|
|
|
fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
|
2020-03-22 12:36:56 +00:00
|
|
|
if let pprust_hir::AnnNode::Expr(_) = node {
|
|
|
|
s.popen();
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
2023-10-10 01:58:12 +00:00
|
|
|
|
2019-06-24 18:15:11 +00:00
|
|
|
fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
|
2020-03-22 12:36:56 +00:00
|
|
|
if let pprust_hir::AnnNode::Expr(expr) = node {
|
2021-06-26 20:26:26 +00:00
|
|
|
let typeck_results = self.maybe_typeck_results.get().or_else(|| {
|
|
|
|
self.tcx
|
2025-02-17 03:17:57 +00:00
|
|
|
.hir_maybe_body_owned_by(expr.hir_id.owner.def_id)
|
2024-05-29 10:03:40 +00:00
|
|
|
.map(|body_id| self.tcx.typeck_body(body_id.id()))
|
2021-06-26 20:26:26 +00:00
|
|
|
});
|
2021-06-26 14:05:53 +00:00
|
|
|
|
|
|
|
if let Some(typeck_results) = typeck_results {
|
|
|
|
s.s.space();
|
|
|
|
s.s.word("as");
|
|
|
|
s.s.space();
|
|
|
|
s.s.word(typeck_results.expr_ty(expr).to_string());
|
|
|
|
}
|
|
|
|
|
2020-03-22 12:36:56 +00:00
|
|
|
s.pclose();
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-07 09:24:00 +00:00
|
|
|
fn get_source(sess: &Session) -> (String, FileName) {
|
|
|
|
let src_name = sess.io.input.source_name();
|
2021-01-10 00:04:48 +00:00
|
|
|
let src = String::clone(
|
2021-09-30 17:38:50 +00:00
|
|
|
sess.source_map()
|
2021-01-10 00:04:48 +00:00
|
|
|
.get_source_file(&src_name)
|
|
|
|
.expect("get_source_file")
|
|
|
|
.src
|
|
|
|
.as_ref()
|
|
|
|
.expect("src"),
|
|
|
|
);
|
2016-04-20 22:29:49 +00:00
|
|
|
(src, src_name)
|
|
|
|
}
|
|
|
|
|
2022-12-07 09:24:00 +00:00
|
|
|
fn write_or_print(out: &str, sess: &Session) {
|
2023-07-17 05:13:08 +00:00
|
|
|
sess.io.output_file.as_ref().unwrap_or(&OutFileName::Stdout).overwrite(out, sess);
|
2016-04-20 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
// Extra data for pretty-printing, the form of which depends on what kind of
|
|
|
|
// pretty-printing we are doing.
|
|
|
|
pub enum PrintExtra<'tcx> {
|
2023-11-04 18:02:31 +00:00
|
|
|
AfterParsing { krate: &'tcx ast::Crate },
|
2023-10-10 21:49:24 +00:00
|
|
|
NeedsAstMap { tcx: TyCtxt<'tcx> },
|
|
|
|
}
|
2016-04-20 22:29:49 +00:00
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
impl<'tcx> PrintExtra<'tcx> {
|
|
|
|
fn with_krate<F, R>(&self, f: F) -> R
|
|
|
|
where
|
2023-10-10 21:55:41 +00:00
|
|
|
F: FnOnce(&ast::Crate) -> R,
|
2023-10-10 21:49:24 +00:00
|
|
|
{
|
|
|
|
match self {
|
|
|
|
PrintExtra::AfterParsing { krate, .. } => f(krate),
|
2024-02-19 17:25:01 +00:00
|
|
|
PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering().borrow().1),
|
2021-02-19 21:40:28 +00:00
|
|
|
}
|
2023-10-10 21:49:24 +00:00
|
|
|
}
|
2016-04-20 22:29:49 +00:00
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
fn tcx(&self) -> TyCtxt<'tcx> {
|
|
|
|
match self {
|
|
|
|
PrintExtra::AfterParsing { .. } => bug!("PrintExtra::tcx"),
|
|
|
|
PrintExtra::NeedsAstMap { tcx } => *tcx,
|
|
|
|
}
|
|
|
|
}
|
2016-04-20 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
|
2024-11-03 16:45:22 +00:00
|
|
|
if ppm.needs_analysis() {
|
2025-01-30 05:20:09 +00:00
|
|
|
ex.tcx().ensure_ok().analysis(());
|
2016-04-20 22:29:49 +00:00
|
|
|
}
|
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
let (src, src_name) = get_source(sess);
|
2016-04-20 22:29:49 +00:00
|
|
|
|
2021-02-19 18:08:12 +00:00
|
|
|
let out = match ppm {
|
2021-02-18 19:21:18 +00:00
|
|
|
Source(s) => {
|
2023-10-10 21:55:41 +00:00
|
|
|
debug!("pretty printing source code {:?}", s);
|
|
|
|
let annotation: Box<dyn pprust_ast::PpAnn> = match s {
|
2023-10-10 22:47:15 +00:00
|
|
|
Normal => Box::new(AstNoAnn),
|
|
|
|
Expanded => Box::new(AstNoAnn),
|
|
|
|
Identified => Box::new(AstIdentifiedAnn),
|
|
|
|
ExpandedIdentified => Box::new(AstIdentifiedAnn),
|
|
|
|
ExpandedHygiene => Box::new(AstHygieneAnn { sess }),
|
2023-10-10 21:55:41 +00:00
|
|
|
};
|
2024-03-04 05:31:49 +00:00
|
|
|
let psess = &sess.psess;
|
2023-10-10 21:55:41 +00:00
|
|
|
let is_expanded = ppm.needs_ast_map();
|
|
|
|
ex.with_krate(|krate| {
|
|
|
|
pprust_ast::print_crate(
|
|
|
|
sess.source_map(),
|
|
|
|
krate,
|
|
|
|
src_name,
|
|
|
|
src,
|
|
|
|
&*annotation,
|
|
|
|
is_expanded,
|
2024-03-04 05:31:49 +00:00
|
|
|
psess.edition,
|
|
|
|
&sess.psess.attr_id_generator,
|
2019-05-09 16:04:04 +00:00
|
|
|
)
|
2016-10-20 01:38:43 +00:00
|
|
|
})
|
|
|
|
}
|
2023-10-10 21:49:24 +00:00
|
|
|
AstTree => {
|
|
|
|
debug!("pretty printing AST tree");
|
|
|
|
ex.with_krate(|krate| format!("{krate:#?}"))
|
|
|
|
}
|
2023-10-10 01:17:06 +00:00
|
|
|
AstTreeExpanded => {
|
2021-02-19 21:40:28 +00:00
|
|
|
debug!("pretty-printing expanded AST");
|
2024-02-19 17:25:01 +00:00
|
|
|
format!("{:#?}", ex.tcx().resolver_for_lowering().borrow().1)
|
2021-02-19 21:40:28 +00:00
|
|
|
}
|
2023-10-10 21:55:41 +00:00
|
|
|
Hir(s) => {
|
2021-02-19 18:08:12 +00:00
|
|
|
debug!("pretty printing HIR {:?}", s);
|
2023-10-10 21:55:41 +00:00
|
|
|
let tcx = ex.tcx();
|
|
|
|
let f = |annotation: &dyn pprust_hir::PpAnn| {
|
|
|
|
let sm = sess.source_map();
|
2025-02-21 07:33:05 +00:00
|
|
|
let attrs = |id| tcx.hir_attrs(id);
|
2023-10-10 21:55:41 +00:00
|
|
|
pprust_hir::print_crate(
|
|
|
|
sm,
|
2025-02-02 23:45:49 +00:00
|
|
|
tcx.hir_root_module(),
|
2023-10-10 21:55:41 +00:00
|
|
|
src_name,
|
|
|
|
src,
|
|
|
|
&attrs,
|
|
|
|
annotation,
|
|
|
|
)
|
|
|
|
};
|
|
|
|
match s {
|
2024-04-14 14:26:59 +00:00
|
|
|
PpHirMode::Normal => f(&tcx),
|
2023-10-10 21:55:41 +00:00
|
|
|
PpHirMode::Identified => {
|
2023-10-10 22:47:15 +00:00
|
|
|
let annotation = HirIdentifiedAnn { tcx };
|
2023-10-10 21:55:41 +00:00
|
|
|
f(&annotation)
|
|
|
|
}
|
|
|
|
PpHirMode::Typed => {
|
2023-10-10 22:47:15 +00:00
|
|
|
let annotation = HirTypedAnn { tcx, maybe_typeck_results: Cell::new(None) };
|
2023-10-10 21:55:41 +00:00
|
|
|
tcx.dep_graph.with_ignore(|| f(&annotation))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 21:16:28 +00:00
|
|
|
HirTree => {
|
2023-10-09 23:53:12 +00:00
|
|
|
debug!("pretty printing HIR tree");
|
2025-02-17 02:24:07 +00:00
|
|
|
format!("{:#?}", ex.tcx().hir_crate(()))
|
2021-09-19 21:16:28 +00:00
|
|
|
}
|
2021-03-12 07:02:51 +00:00
|
|
|
Mir => {
|
|
|
|
let mut out = Vec::new();
|
2023-10-10 21:49:24 +00:00
|
|
|
write_mir_pretty(ex.tcx(), None, &mut out).unwrap();
|
2021-03-12 07:02:51 +00:00
|
|
|
String::from_utf8(out).unwrap()
|
|
|
|
}
|
|
|
|
MirCFG => {
|
|
|
|
let mut out = Vec::new();
|
2023-10-10 21:49:24 +00:00
|
|
|
write_mir_graphviz(ex.tcx(), None, &mut out).unwrap();
|
2021-03-12 07:02:51 +00:00
|
|
|
String::from_utf8(out).unwrap()
|
|
|
|
}
|
2023-11-14 13:21:55 +00:00
|
|
|
StableMir => {
|
2023-11-08 09:37:26 +00:00
|
|
|
let mut out = Vec::new();
|
|
|
|
write_smir_pretty(ex.tcx(), &mut out).unwrap();
|
|
|
|
String::from_utf8(out).unwrap()
|
|
|
|
}
|
2021-03-12 07:02:51 +00:00
|
|
|
ThirTree => {
|
2023-10-10 21:49:24 +00:00
|
|
|
let tcx = ex.tcx();
|
2021-07-24 21:18:15 +00:00
|
|
|
let mut out = String::new();
|
2024-04-08 14:44:10 +00:00
|
|
|
rustc_hir_analysis::check_crate(tcx);
|
2024-12-20 14:08:24 +00:00
|
|
|
tcx.dcx().abort_if_errors();
|
2021-07-24 21:18:15 +00:00
|
|
|
debug!("pretty printing THIR tree");
|
2025-02-17 03:17:57 +00:00
|
|
|
for did in tcx.hir_body_owners() {
|
2025-01-31 03:42:19 +00:00
|
|
|
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did));
|
2021-07-24 21:18:15 +00:00
|
|
|
}
|
|
|
|
out
|
2021-03-12 07:02:51 +00:00
|
|
|
}
|
2023-01-26 22:35:24 +00:00
|
|
|
ThirFlat => {
|
2023-10-10 21:49:24 +00:00
|
|
|
let tcx = ex.tcx();
|
2023-01-26 22:35:24 +00:00
|
|
|
let mut out = String::new();
|
2024-04-08 14:44:10 +00:00
|
|
|
rustc_hir_analysis::check_crate(tcx);
|
2024-12-20 14:08:24 +00:00
|
|
|
tcx.dcx().abort_if_errors();
|
2023-01-26 22:35:24 +00:00
|
|
|
debug!("pretty printing THIR flat");
|
2025-02-17 03:17:57 +00:00
|
|
|
for did in tcx.hir_body_owners() {
|
2025-01-31 03:42:19 +00:00
|
|
|
let _ = writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did));
|
2023-01-26 22:35:24 +00:00
|
|
|
}
|
|
|
|
out
|
|
|
|
}
|
2021-03-12 07:02:51 +00:00
|
|
|
};
|
2014-08-11 10:59:35 +00:00
|
|
|
|
2023-10-10 21:49:24 +00:00
|
|
|
write_or_print(&out, sess);
|
2014-08-11 10:59:35 +00:00
|
|
|
}
|