Skip to main content

rustc_driver_impl/
pretty.rs

1//! The various pretty-printing routines.
2
3use std::cell::Cell;
4use std::fmt::Write;
5
6use rustc_ast as ast;
7use rustc_ast_pretty::pprust as pprust_ast;
8use rustc_hir_pretty as pprust_hir;
9use rustc_middle::bug;
10use rustc_middle::mir::{write_mir_graphviz, write_mir_pretty};
11use rustc_middle::ty::{self, TyCtxt};
12use rustc_mir_build::thir::print::{thir_flat, thir_tree};
13use rustc_public::rustc_internal::pretty::write_smir_pretty;
14use rustc_session::Session;
15use rustc_session::config::{OutFileName, PpHirMode, PpMode, PpSourceMode};
16use rustc_span::{FileName, Ident};
17use tracing::debug;
18
19pub use self::PpMode::*;
20pub use self::PpSourceMode::*;
21
22struct AstNoAnn;
23
24impl pprust_ast::PpAnn for AstNoAnn {}
25
26struct AstIdentifiedAnn;
27
28impl pprust_ast::PpAnn for AstIdentifiedAnn {
29    fn pre(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
30        if let pprust_ast::AnnNode::Expr(_) = node {
31            s.popen();
32        }
33    }
34
35    fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
36        match node {
37            pprust_ast::AnnNode::Crate(_)
38            | pprust_ast::AnnNode::Ident(_)
39            | pprust_ast::AnnNode::Name(_) => {}
40
41            pprust_ast::AnnNode::Item(item) => {
42                s.s.space();
43                s.synth_comment(item.id.to_string())
44            }
45            pprust_ast::AnnNode::SubItem(id) => {
46                s.s.space();
47                s.synth_comment(id.to_string())
48            }
49            pprust_ast::AnnNode::Block(blk) => {
50                s.s.space();
51                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("block {0}", blk.id))
    })format!("block {}", blk.id))
52            }
53            pprust_ast::AnnNode::Expr(expr) => {
54                s.s.space();
55                s.synth_comment(expr.id.to_string());
56                s.pclose()
57            }
58            pprust_ast::AnnNode::Pat(pat) => {
59                s.s.space();
60                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("pat {0}", pat.id))
    })format!("pat {}", pat.id));
61            }
62        }
63    }
64}
65
66struct HirIdentifiedAnn<'tcx> {
67    tcx: TyCtxt<'tcx>,
68}
69
70impl<'tcx> pprust_hir::PpAnn for HirIdentifiedAnn<'tcx> {
71    fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
72        self.tcx.nested(state, nested)
73    }
74
75    fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
76        if let pprust_hir::AnnNode::Expr(_) = node {
77            s.popen();
78        }
79    }
80
81    fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
82        match node {
83            pprust_hir::AnnNode::Name(_) => {}
84            pprust_hir::AnnNode::Item(item) => {
85                s.s.space();
86                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("hir_id: {0}", item.hir_id()))
    })format!("hir_id: {}", item.hir_id()));
87            }
88            pprust_hir::AnnNode::SubItem(id) => {
89                s.s.space();
90                s.synth_comment(id.to_string());
91            }
92            pprust_hir::AnnNode::Block(blk) => {
93                s.s.space();
94                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("block hir_id: {0}", blk.hir_id))
    })format!("block hir_id: {}", blk.hir_id));
95            }
96            pprust_hir::AnnNode::Expr(expr) => {
97                s.s.space();
98                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("expr hir_id: {0}", expr.hir_id))
    })format!("expr hir_id: {}", expr.hir_id));
99                s.pclose();
100            }
101            pprust_hir::AnnNode::Pat(pat) => {
102                s.s.space();
103                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("pat hir_id: {0}", pat.hir_id))
    })format!("pat hir_id: {}", pat.hir_id));
104            }
105            pprust_hir::AnnNode::TyPat(pat) => {
106                s.s.space();
107                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("ty pat hir_id: {0}", pat.hir_id))
    })format!("ty pat hir_id: {}", pat.hir_id));
108            }
109            pprust_hir::AnnNode::Arm(arm) => {
110                s.s.space();
111                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("arm hir_id: {0}", arm.hir_id))
    })format!("arm hir_id: {}", arm.hir_id));
112            }
113        }
114    }
115}
116
117struct AstHygieneAnn<'a> {
118    sess: &'a Session,
119}
120
121impl<'a> pprust_ast::PpAnn for AstHygieneAnn<'a> {
122    fn post(&self, s: &mut pprust_ast::State<'_>, node: pprust_ast::AnnNode<'_>) {
123        match node {
124            pprust_ast::AnnNode::Ident(&Ident { name, span }) => {
125                s.s.space();
126                s.synth_comment(::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0}{1:?}", name.as_u32(),
                span.ctxt()))
    })format!("{}{:?}", name.as_u32(), span.ctxt()))
127            }
128            pprust_ast::AnnNode::Name(&name) => {
129                s.s.space();
130                s.synth_comment(name.as_u32().to_string())
131            }
132            pprust_ast::AnnNode::Crate(_) => {
133                s.s.hardbreak();
134                let verbose = self.sess.verbose_internals();
135                s.synth_comment(rustc_span::hygiene::debug_hygiene_data(verbose));
136                s.s.hardbreak_if_not_bol();
137            }
138            _ => {}
139        }
140    }
141}
142
143struct HirTypedAnn<'tcx> {
144    tcx: TyCtxt<'tcx>,
145    maybe_typeck_results: Cell<Option<&'tcx ty::TypeckResults<'tcx>>>,
146}
147
148impl<'tcx> pprust_hir::PpAnn for HirTypedAnn<'tcx> {
149    fn nested(&self, state: &mut pprust_hir::State<'_>, nested: pprust_hir::Nested) {
150        let old_maybe_typeck_results = self.maybe_typeck_results.get();
151        if let pprust_hir::Nested::Body(id) = nested {
152            self.maybe_typeck_results.set(Some(self.tcx.typeck_body(id)));
153        }
154        self.tcx.nested(state, nested);
155        self.maybe_typeck_results.set(old_maybe_typeck_results);
156    }
157
158    fn pre(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
159        if let pprust_hir::AnnNode::Expr(_) = node {
160            s.popen();
161        }
162    }
163
164    fn post(&self, s: &mut pprust_hir::State<'_>, node: pprust_hir::AnnNode<'_>) {
165        if let pprust_hir::AnnNode::Expr(expr) = node {
166            let typeck_results = self.maybe_typeck_results.get().or_else(|| {
167                self.tcx
168                    .hir_maybe_body_owned_by(expr.hir_id.owner.def_id)
169                    .map(|body_id| self.tcx.typeck_body(body_id.id()))
170            });
171
172            if let Some(typeck_results) = typeck_results {
173                s.s.space();
174                s.s.word("as");
175                s.s.space();
176                s.s.word(typeck_results.expr_ty(expr).to_string());
177            }
178
179            s.pclose();
180        }
181    }
182}
183
184fn get_source(sess: &Session) -> (String, FileName) {
185    let src_name = sess.io.input.file_name(&sess);
186    let src = String::clone(
187        sess.source_map()
188            .get_source_file(&src_name)
189            .expect("get_source_file")
190            .src
191            .as_ref()
192            .expect("src"),
193    );
194    (src, src_name)
195}
196
197fn write_or_print(out: &str, sess: &Session) {
198    sess.io.output_file.as_ref().unwrap_or(&OutFileName::Stdout).overwrite(out, sess);
199}
200
201// Extra data for pretty-printing, the form of which depends on what kind of
202// pretty-printing we are doing.
203pub enum PrintExtra<'tcx> {
204    AfterParsing { krate: &'tcx ast::Crate },
205    NeedsAstMap { tcx: TyCtxt<'tcx> },
206}
207
208impl<'tcx> PrintExtra<'tcx> {
209    fn with_krate<F, R>(&self, f: F) -> R
210    where
211        F: FnOnce(&ast::Crate) -> R,
212    {
213        match self {
214            PrintExtra::AfterParsing { krate, .. } => f(krate),
215            PrintExtra::NeedsAstMap { tcx } => f(&tcx.resolver_for_lowering().borrow().1),
216        }
217    }
218
219    fn tcx(&self) -> TyCtxt<'tcx> {
220        match self {
221            PrintExtra::AfterParsing { .. } => ::rustc_middle::util::bug::bug_fmt(format_args!("PrintExtra::tcx"))bug!("PrintExtra::tcx"),
222            PrintExtra::NeedsAstMap { tcx } => *tcx,
223        }
224    }
225}
226
227pub fn print<'tcx>(sess: &Session, ppm: PpMode, ex: PrintExtra<'tcx>) {
228    if ppm.needs_analysis() {
229        ex.tcx().ensure_ok().analysis(());
230    }
231
232    let (src, src_name) = get_source(sess);
233
234    let out = match ppm {
235        Source(s) => {
236            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:236",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(236u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing source code {0:?}",
                                                    s) as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing source code {:?}", s);
237            let annotation: Box<dyn pprust_ast::PpAnn> = match s {
238                Normal => Box::new(AstNoAnn),
239                Expanded => Box::new(AstNoAnn),
240                Identified => Box::new(AstIdentifiedAnn),
241                ExpandedIdentified => Box::new(AstIdentifiedAnn),
242                ExpandedHygiene => Box::new(AstHygieneAnn { sess }),
243            };
244            let psess = &sess.psess;
245            let is_expanded = ppm.needs_ast_map();
246            ex.with_krate(|krate| {
247                pprust_ast::print_crate(
248                    sess.source_map(),
249                    krate,
250                    src_name,
251                    src,
252                    &*annotation,
253                    is_expanded,
254                    psess.edition,
255                    &sess.psess.attr_id_generator,
256                )
257            })
258        }
259        AstTree => {
260            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:260",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(260u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing AST tree")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing AST tree");
261            ex.with_krate(|krate| ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0:#?}", krate))
    })format!("{krate:#?}"))
262        }
263        AstTreeExpanded => {
264            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:264",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(264u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty-printing expanded AST")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("pretty-printing expanded AST");
265            ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0:#?}",
                ex.tcx().resolver_for_lowering().borrow().1))
    })format!("{:#?}", ex.tcx().resolver_for_lowering().borrow().1)
266        }
267        Hir(s) => {
268            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:268",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(268u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing HIR {0:?}",
                                                    s) as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing HIR {:?}", s);
269            let tcx = ex.tcx();
270            let f = |annotation: &dyn pprust_hir::PpAnn| {
271                let sm = sess.source_map();
272                let attrs = |id| tcx.hir_attrs(id);
273                pprust_hir::print_crate(
274                    sm,
275                    tcx.hir_root_module(),
276                    src_name,
277                    src,
278                    &attrs,
279                    annotation,
280                )
281            };
282            match s {
283                PpHirMode::Normal => f(&tcx),
284                PpHirMode::Identified => {
285                    let annotation = HirIdentifiedAnn { tcx };
286                    f(&annotation)
287                }
288                PpHirMode::Typed => {
289                    let annotation = HirTypedAnn { tcx, maybe_typeck_results: Cell::new(None) };
290                    tcx.dep_graph.with_ignore(|| f(&annotation))
291                }
292            }
293        }
294        HirTree => {
295            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:295",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(295u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing HIR tree")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing HIR tree");
296            ex.tcx()
297                .hir_crate_items(())
298                .owners()
299                .map(|owner| ::alloc::__export::must_use({
        ::alloc::fmt::format(format_args!("{0:#?} => {1:#?}\n", owner,
                ex.tcx().hir_owner_nodes(owner)))
    })format!("{:#?} => {:#?}\n", owner, ex.tcx().hir_owner_nodes(owner)))
300                .collect()
301        }
302        Mir => {
303            let mut out = Vec::new();
304            write_mir_pretty(ex.tcx(), None, &mut out).unwrap();
305            String::from_utf8(out).unwrap()
306        }
307        MirCFG => {
308            let mut out = Vec::new();
309            write_mir_graphviz(ex.tcx(), None, &mut out).unwrap();
310            String::from_utf8(out).unwrap()
311        }
312        StableMir => {
313            let mut out = Vec::new();
314            write_smir_pretty(ex.tcx(), &mut out).unwrap();
315            String::from_utf8(out).unwrap()
316        }
317        ThirTree => {
318            let tcx = ex.tcx();
319            let mut out = String::new();
320            rustc_hir_analysis::check_crate(tcx);
321            tcx.dcx().abort_if_errors();
322            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:322",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(322u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing THIR tree")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing THIR tree");
323            for did in tcx.hir_body_owners() {
324                let _ = out.write_fmt(format_args!("{0:?}:\n{1}\n\n", did, thir_tree(tcx, did)))writeln!(out, "{:?}:\n{}\n", did, thir_tree(tcx, did));
325            }
326            out
327        }
328        ThirFlat => {
329            let tcx = ex.tcx();
330            let mut out = String::new();
331            rustc_hir_analysis::check_crate(tcx);
332            tcx.dcx().abort_if_errors();
333            {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_driver_impl/src/pretty.rs:333",
                        "rustc_driver_impl::pretty", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_driver_impl/src/pretty.rs"),
                        ::tracing_core::__macro_support::Option::Some(333u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_driver_impl::pretty"),
                        ::tracing_core::field::FieldSet::new(&["message"],
                            ::tracing_core::callsite::Identifier(&__CALLSITE)),
                        ::tracing::metadata::Kind::EVENT)
                };
            ::tracing::callsite::DefaultCallsite::new(&META)
        };
    let enabled =
        ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::DEBUG <=
                    ::tracing::level_filters::LevelFilter::current() &&
            {
                let interest = __CALLSITE.interest();
                !interest.is_never() &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest)
            };
    if enabled {
        (|value_set: ::tracing::field::ValueSet|
                    {
                        let meta = __CALLSITE.metadata();
                        ::tracing::Event::dispatch(meta, &value_set);
                        ;
                    })({
                #[allow(unused_imports)]
                use ::tracing::field::{debug, display, Value};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("pretty printing THIR flat")
                                            as &dyn Value))])
            });
    } else { ; }
};debug!("pretty printing THIR flat");
334            for did in tcx.hir_body_owners() {
335                let _ = out.write_fmt(format_args!("{0:?}:\n{1}\n\n", did, thir_flat(tcx, did)))writeln!(out, "{:?}:\n{}\n", did, thir_flat(tcx, did));
336            }
337            out
338        }
339    };
340
341    write_or_print(&out, sess);
342}