Skip to main content

rustc_mir_build/thir/cx/
expr.rs

1use itertools::Itertools;
2use rustc_abi::{FIRST_VARIANT, FieldIdx, Size, VariantIdx};
3use rustc_ast::UnsafeBinderCastKind;
4use rustc_attr_ir::lang_items::LangItem;
5use rustc_attr_ir::{AttributeKind, HasAttrs, UnrollAttr, find_attr};
6use rustc_data_structures::thin_vec::ThinVec;
7use rustc_hir as hir;
8use rustc_hir::HirId;
9use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
10use rustc_index::Idx;
11use rustc_middle::hir::place::{
12    Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
13};
14use rustc_middle::middle::region;
15use rustc_middle::mir::{self, AssignOp, BinOp, BorrowKind, UnOp};
16use rustc_middle::thir::*;
17use rustc_middle::ty::adjustment::{
18    Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, PointerCoercion,
19};
20use rustc_middle::ty::{
21    self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, SplattedDef, Ty,
22    TyCtxt, UpvarArgs,
23};
24use rustc_span::{DesugaringKind, Span, bug, span_bug};
25use tracing::{debug, info, instrument, trace};
26
27use crate::diagnostics::*;
28use crate::thir::cx::ThirBuildCx;
29
30/// The receiver of a splatted method, or the expression for a splatted function call.
31#[derive(#[automatically_derived]impl<'tcx> ::core::marker::Copy for SplattedFunc<'tcx>
    {
}Copy, #[automatically_derived]#[doc(hidden)]unsafe impl<'tcx>
    ::core::clone::TrivialClone for SplattedFunc<'tcx> {
}
#[automatically_derived]impl<'tcx> ::core::clone::Clone for SplattedFunc<'tcx>
    {
    #[inline]
    fn clone(&self) -> Self {
        let _: ::core::clone::AssertParamIsClone<&'tcx hir::Expr<'tcx>>;
        let _: ::core::clone::AssertParamIsClone<&'tcx hir::Expr<'tcx>>;
        *self
    }
}Clone, #[automatically_derived]impl<'tcx> ::core::fmt::Debug for SplattedFunc<'tcx> {
    #[inline]
    fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
        match self {
            Self::FnDefReceiver(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "FnDefReceiver", &__self_0),
            Self::FnExpression(__self_0) =>
                ::core::fmt::Formatter::debug_tuple_field1_finish(f,
                    "FnExpression", &__self_0),
        }
    }
}Debug)]
32enum SplattedFunc<'tcx> {
33    /// The expression for a method receiver. Always a FnDef.
34    FnDefReceiver(&'tcx hir::Expr<'tcx>),
35    /// The expression or path for a function call.
36    /// This can be a FnDef or FnPtr.
37    FnExpression(&'tcx hir::Expr<'tcx>),
38}
39
40impl<'tcx> SplattedFunc<'tcx> {
41    fn has_receiver(&self) -> bool {
42        #[allow(non_exhaustive_omitted_patterns)] match self {
    SplattedFunc::FnDefReceiver(_) => true,
    _ => false,
}matches!(self, SplattedFunc::FnDefReceiver(_))
43    }
44
45    fn receiver(&self) -> Option<&'tcx hir::Expr<'tcx>> {
46        match self {
47            SplattedFunc::FnDefReceiver(receiver) => Some(receiver),
48            SplattedFunc::FnExpression(_fn_expression) => None,
49        }
50    }
51
52    fn fn_expression(&self) -> Option<&'tcx hir::Expr<'tcx>> {
53        match self {
54            SplattedFunc::FnDefReceiver(_receiver) => None,
55            SplattedFunc::FnExpression(fn_expression) => Some(fn_expression),
56        }
57    }
58}
59
60fn filter_loop_hint_attrs(id: HirId, tcx: TyCtxt<'_>) -> ThinVec<UnrollAttr> {
61    HasAttrs::get_attrs(id, &tcx)
62        .into_iter()
63        .filter_map(|attr| match attr {
64            rustc_attr_ir::Attribute::Parsed(AttributeKind::Unroll(unroll)) => Some(unroll.clone()),
65            _ => None,
66        })
67        .collect()
68}
69
70impl<'tcx> ThirBuildCx<'tcx> {
71    pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
72        exprs.iter().map(|expr| self.mirror_expr(expr)).collect()
73    }
74
75    /// Create a THIR expression for the given HIR expression. This expands all
76    /// adjustments and directly adds the type information from the
77    /// `typeck_results`. See the [dev-guide] for more details.
78    ///
79    /// (The term "mirror" in this case does not refer to "flipped" or
80    /// "reversed".)
81    ///
82    /// [dev-guide]: https://rustc-dev-guide.rust-lang.org/thir.html
83    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("mirror_expr",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(83u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&[],
                                        ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{ meta.fields().value_set_all(&[]) })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: ExprId = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let expr_scope =
                region::Scope {
                    local_id: hir_expr.hir_id.local_id,
                    data: region::ScopeData::Node,
                };
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:88",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(88u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("hir_expr.hir_id")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("hir_expr.hir_id");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("hir_expr.span")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("hir_expr.span");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr.hir_id)
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr.span)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut expr = self.make_mirror_unadjusted(hir_expr);
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:92",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(92u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expr.ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expr.ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr.ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let mut loop_hint_attrs = ThinVec::new();
            if let hir::ExprKind::Loop(_, _, _, span) = hir_expr.kind {
                match span.desugaring_kind() {
                    Some(DesugaringKind::ForLoop) => {
                        let arm =
                            self.tcx.parent_hir_node(hir_expr.hir_id).expect_arm();
                        let expr =
                            self.tcx.parent_hir_node(arm.hir_id).expect_expr();
                        {
                            match expr.kind {
                                hir::ExprKind::Match(..) => {}
                                ref left_val => {
                                    ::core::panicking::assert_matches_failed(left_val,
                                        "hir::ExprKind::Match(..)", ::core::option::Option::None);
                                }
                            }
                        };
                        if let hir::Node::Expr(expr) =
                                self.tcx.parent_hir_node(expr.hir_id) {
                            {
                                match expr.kind {
                                    hir::ExprKind::DropTemps(..) => {}
                                    ref left_val => {
                                        ::core::panicking::assert_matches_failed(left_val,
                                            "hir::ExprKind::DropTemps(..)",
                                            ::core::option::Option::None);
                                    }
                                }
                            };
                            loop_hint_attrs =
                                filter_loop_hint_attrs(expr.hir_id, self.tcx)
                        }
                    }
                    Some(DesugaringKind::WhileLoop) | None => {
                        loop_hint_attrs =
                            filter_loop_hint_attrs(hir_expr.hir_id, self.tcx);
                    }
                    _ => (),
                }
            }
            if self.apply_adjustments {
                for adjustment in
                    self.typeck_results.expr_adjustments(hir_expr) {
                    {
                        use ::tracing::__macro_support::Callsite as _;
                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                            {
                                static META: ::tracing::Metadata<'static> =
                                    {
                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:120",
                                            "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                            ::tracing_core::__macro_support::Option::Some(120u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                            ::tracing_core::field::FieldSet::new(&[{
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("expr")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("expr");
                                                                NAME.as_str()
                                                            },
                                                            {
                                                                const NAME:
                                                                    ::tracing::__macro_support::FieldName<{
                                                                        ::tracing::__macro_support::FieldName::len("adjustment")
                                                                    }> =
                                                                    ::tracing::__macro_support::FieldName::new("adjustment");
                                                                NAME.as_str()
                                                            }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                            ::tracing::metadata::Kind::EVENT)
                                    };
                                ::tracing::callsite::DefaultCallsite::new(&META)
                            };
                        let enabled =
                            ::tracing::Level::TRACE <=
                                        ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                    ::tracing::Level::TRACE <=
                                        ::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};
                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
                                                                as &dyn ::tracing::field::Value)),
                                                    (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adjustment)
                                                                as &dyn ::tracing::field::Value))])
                                });
                        } else { ; }
                    };
                    let span = expr.span;
                    expr =
                        self.apply_adjustment(hir_expr, expr, adjustment, span);
                }
            }
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:126",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(126u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&["message",
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("expr.ty")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("expr.ty");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::EVENT)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let enabled =
                    ::tracing::Level::TRACE <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::TRACE <=
                                ::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};
                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("after adjustments")
                                                        as &dyn ::tracing::field::Value)),
                                            (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr.ty)
                                                        as &dyn ::tracing::field::Value))])
                        });
                } else { ; }
            };
            let ty = expr.ty;
            let value = self.thir.exprs.push(expr);
            if !loop_hint_attrs.is_empty() {
                self.thir.loop_hint_attrs.insert(value, loop_hint_attrs);
            }
            expr =
                Expr {
                    temp_scope_id: expr_scope.local_id,
                    ty,
                    span: hir_expr.span,
                    kind: ExprKind::Scope {
                        region_scope: expr_scope,
                        value,
                        hir_id: hir_expr.hir_id,
                    },
                };
            self.thir.exprs.push(expr)
        }
    }
}#[instrument(level = "trace", skip(self, hir_expr))]
84    pub(crate) fn mirror_expr(&mut self, hir_expr: &'tcx hir::Expr<'tcx>) -> ExprId {
85        let expr_scope =
86            region::Scope { local_id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
87
88        trace!(?hir_expr.hir_id, ?hir_expr.span);
89
90        let mut expr = self.make_mirror_unadjusted(hir_expr);
91
92        trace!(?expr.ty);
93
94        let mut loop_hint_attrs = ThinVec::new();
95
96        if let hir::ExprKind::Loop(_, _, _, span) = hir_expr.kind {
97            match span.desugaring_kind() {
98                // `for` loop desugaring puts us pretty deep down the HIR tree
99                Some(DesugaringKind::ForLoop) => {
100                    let arm = self.tcx.parent_hir_node(hir_expr.hir_id).expect_arm();
101                    let expr = self.tcx.parent_hir_node(arm.hir_id).expect_expr();
102                    std::assert_matches!(expr.kind, hir::ExprKind::Match(..));
103                    // ignore async for loops
104                    if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(expr.hir_id) {
105                        std::assert_matches!(expr.kind, hir::ExprKind::DropTemps(..));
106                        loop_hint_attrs = filter_loop_hint_attrs(expr.hir_id, self.tcx)
107                    }
108                }
109                // For loops defined with `loop` and `while`, the expr already has the attrs
110                Some(DesugaringKind::WhileLoop) | None => {
111                    loop_hint_attrs = filter_loop_hint_attrs(hir_expr.hir_id, self.tcx);
112                }
113                _ => (),
114            }
115        }
116
117        // Now apply adjustments, if any.
118        if self.apply_adjustments {
119            for adjustment in self.typeck_results.expr_adjustments(hir_expr) {
120                trace!(?expr, ?adjustment);
121                let span = expr.span;
122                expr = self.apply_adjustment(hir_expr, expr, adjustment, span);
123            }
124        }
125
126        trace!(?expr.ty, "after adjustments");
127
128        let ty = expr.ty;
129        let value = self.thir.exprs.push(expr);
130
131        if !loop_hint_attrs.is_empty() {
132            self.thir.loop_hint_attrs.insert(value, loop_hint_attrs);
133        }
134
135        // Finally, wrap this up in the expr's scope.
136        //
137        // (In addition to marking scope, coverage instrumentation also uses this node
138        // to help mark the point in MIR where an expression is about to be evaluated.)
139        expr = Expr {
140            temp_scope_id: expr_scope.local_id,
141            ty,
142            span: hir_expr.span,
143            kind: ExprKind::Scope { region_scope: expr_scope, value, hir_id: hir_expr.hir_id },
144        };
145
146        // OK, all done!
147        self.thir.exprs.push(expr)
148    }
149
150    {}
#[allow(clippy :: suspicious_else_formatting)]
{
    let __tracing_attr_span;
    let __tracing_attr_guard;
    if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
                &&
                ::tracing::Level::TRACE <=
                    ::tracing::level_filters::LevelFilter::current() ||
            { false } {
        __tracing_attr_span =
            {
                use ::tracing::__macro_support::Callsite as _;
                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                    {
                        static META: ::tracing::Metadata<'static> =
                            {
                                ::tracing_core::metadata::Metadata::new("apply_adjustment",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(150u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&[{
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("hir_expr")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("hir_expr");
                                                        NAME.as_str()
                                                    },
                                                    {
                                                        const NAME:
                                                            ::tracing::__macro_support::FieldName<{
                                                                ::tracing::__macro_support::FieldName::len("adjustment")
                                                            }> =
                                                            ::tracing::__macro_support::FieldName::new("adjustment");
                                                        NAME.as_str()
                                                    }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                    ::tracing::metadata::Kind::SPAN)
                            };
                        ::tracing::callsite::DefaultCallsite::new(&META)
                    };
                let mut interest = ::tracing::subscriber::Interest::never();
                if ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                ::tracing::Level::TRACE <=
                                    ::tracing::level_filters::LevelFilter::current() &&
                            { interest = __CALLSITE.interest(); !interest.is_never() }
                        &&
                        ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                            interest) {
                    let meta = __CALLSITE.metadata();
                    ::tracing::Span::new(meta,
                        &{
                                #[allow(unused_imports)]
                                use ::tracing::field::{debug, display, Value};
                                meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr)
                                                            as &dyn ::tracing::field::Value)),
                                                (::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adjustment)
                                                            as &dyn ::tracing::field::Value))])
                            })
                } else {
                    let span =
                        ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                    {};
                    span
                }
            };
        __tracing_attr_guard = __tracing_attr_span.enter();
    }

    #[warn(clippy :: suspicious_else_formatting)]
    {

        #[allow(unknown_lints, unreachable_code, clippy ::
        diverging_sub_expression, clippy :: empty_loop, clippy ::
        let_unit_value, clippy :: let_with_type_underscore, clippy ::
        needless_return, clippy :: unreachable)]
        if false {
            let __tracing_attr_fake_return: Expr<'tcx> = loop {};
            return __tracing_attr_fake_return;
        }
        {
            let Expr { temp_scope_id, .. } = expr;
            let mut adjust_span =
                |expr: &mut Expr<'tcx>|
                    {
                        if let ExprKind::Block { block } = expr.kind &&
                                let Some(last_expr) = self.thir[block].expr {
                            span = self.thir[last_expr].span;
                            expr.span = span;
                        }
                    };
            let kind =
                match adjustment.kind {
                    Adjust::Pointer(cast) => {
                        if cast == PointerCoercion::Unsize {
                            adjust_span(&mut expr);
                        }
                        let is_from_as_cast =
                            if let hir::Node::Expr(hir::Expr {
                                    kind: hir::ExprKind::Cast(..), span: cast_span, .. }) =
                                    self.tcx.parent_hir_node(hir_expr.hir_id) {
                                span = *cast_span;
                                true
                            } else { false };
                        ExprKind::PointerCoercion {
                            cast,
                            source: self.thir.exprs.push(expr),
                            is_from_as_cast,
                        }
                    }
                    Adjust::NeverToAny if adjustment.target.is_never() =>
                        return expr,
                    Adjust::NeverToAny =>
                        ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
                    Adjust::Deref(DerefAdjustKind::Builtin) => {
                        adjust_span(&mut expr);
                        ExprKind::Deref { arg: self.thir.exprs.push(expr) }
                    }
                    Adjust::Deref(DerefAdjustKind::Pin) => {
                        adjust_span(&mut expr);
                        let pin_ty =
                            expr.ty.pinned_ty().expect("Deref(Pin) with non-Pin type");
                        let pointer_target =
                            ExprKind::Field {
                                lhs: self.thir.exprs.push(expr),
                                variant_index: FIRST_VARIANT,
                                name: FieldIdx::ZERO,
                            };
                        let expr =
                            Expr {
                                temp_scope_id,
                                ty: pin_ty,
                                span,
                                kind: pointer_target,
                            };
                        ExprKind::Deref { arg: self.thir.exprs.push(expr) }
                    }
                    Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
                        let call_def_id = deref.method_call(self.tcx);
                        let overloaded_callee =
                            self.tcx.type_of(call_def_id).instantiate(self.tcx,
                                    self.tcx.mk_args(&[expr.ty.into()])).skip_norm_wip();
                        expr =
                            Expr {
                                temp_scope_id,
                                ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased,
                                    expr.ty, deref.mutbl),
                                span,
                                kind: ExprKind::Borrow {
                                    borrow_kind: deref.mutbl.to_borrow_kind(),
                                    arg: self.thir.exprs.push(expr),
                                },
                            };
                        let expr = Box::new([self.thir.exprs.push(expr)]);
                        self.overloaded_place(hir_expr, adjustment.target,
                            Some(overloaded_callee), expr, deref.span)
                    }
                    Adjust::Borrow(AutoBorrow::Ref(m)) =>
                        ExprKind::Borrow {
                            borrow_kind: m.to_borrow_kind(),
                            arg: self.thir.exprs.push(expr),
                        },
                    Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
                        ExprKind::RawBorrow {
                            mutability,
                            arg: self.thir.exprs.push(expr),
                        }
                    }
                    Adjust::Borrow(AutoBorrow::Pin(mutbl)) => {
                        let borrow_kind =
                            match mutbl {
                                hir::Mutability::Mut =>
                                    BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
                                hir::Mutability::Not => BorrowKind::Shared,
                            };
                        let new_pin_target =
                            Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty,
                                mutbl);
                        let arg = self.thir.exprs.push(expr);
                        let expr =
                            self.thir.exprs.push(Expr {
                                    temp_scope_id,
                                    ty: new_pin_target,
                                    span,
                                    kind: ExprKind::Borrow { borrow_kind, arg },
                                });
                        let pin_did =
                            self.tcx.require_lang_item(LangItem::Pin, span);
                        let args = self.tcx.mk_args(&[new_pin_target.into()]);
                        let kind =
                            ExprKind::Adt(Box::new(AdtExpr {
                                        adt_def: self.tcx.adt_def(pin_did),
                                        variant_index: FIRST_VARIANT,
                                        args,
                                        fields: Box::new([FieldExpr {
                                                        name: FieldIdx::ZERO,
                                                        expr,
                                                    }]),
                                        user_ty: None,
                                        base: AdtExprBase::None,
                                    }));
                        {
                            use ::tracing::__macro_support::Callsite as _;
                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                {
                                    static META: ::tracing::Metadata<'static> =
                                        {
                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:287",
                                                "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                ::tracing_core::__macro_support::Option::Some(287u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                ::tracing_core::field::FieldSet::new(&[{
                                                                    const NAME:
                                                                        ::tracing::__macro_support::FieldName<{
                                                                            ::tracing::__macro_support::FieldName::len("kind")
                                                                        }> =
                                                                        ::tracing::__macro_support::FieldName::new("kind");
                                                                    NAME.as_str()
                                                                }], ::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};
                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
                                                                    as &dyn ::tracing::field::Value))])
                                    });
                            } else { ; }
                        };
                        kind
                    }
                    Adjust::GenericReborrow(mutability) => {
                        let expr = self.thir.exprs.push(expr);
                        let kind =
                            ExprKind::Reborrow {
                                source: expr,
                                mutability,
                                target: adjustment.target,
                            };
                        kind
                    }
                };
            Expr { temp_scope_id, ty: adjustment.target, span, kind }
        }
    }
}#[instrument(level = "trace", skip(self, expr, span))]
151    fn apply_adjustment(
152        &mut self,
153        hir_expr: &'tcx hir::Expr<'tcx>,
154        mut expr: Expr<'tcx>,
155        adjustment: &Adjustment<'tcx>,
156        mut span: Span,
157    ) -> Expr<'tcx> {
158        let Expr { temp_scope_id, .. } = expr;
159
160        // Adjust the span from the block, to the last expression of the
161        // block. This is a better span when returning a mutable reference
162        // with too short a lifetime. The error message will use the span
163        // from the assignment to the return place, which should only point
164        // at the returned value, not the entire function body.
165        //
166        // fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 {
167        //      x
168        //   // ^ error message points at this expression.
169        // }
170        let mut adjust_span = |expr: &mut Expr<'tcx>| {
171            if let ExprKind::Block { block } = expr.kind
172                && let Some(last_expr) = self.thir[block].expr
173            {
174                span = self.thir[last_expr].span;
175                expr.span = span;
176            }
177        };
178
179        let kind = match adjustment.kind {
180            Adjust::Pointer(cast) => {
181                if cast == PointerCoercion::Unsize {
182                    adjust_span(&mut expr);
183                }
184
185                let is_from_as_cast = if let hir::Node::Expr(hir::Expr {
186                    kind: hir::ExprKind::Cast(..),
187                    span: cast_span,
188                    ..
189                }) = self.tcx.parent_hir_node(hir_expr.hir_id)
190                {
191                    // Use the whole span of the `x as T` expression for the coercion.
192                    span = *cast_span;
193                    true
194                } else {
195                    false
196                };
197                ExprKind::PointerCoercion {
198                    cast,
199                    source: self.thir.exprs.push(expr),
200                    is_from_as_cast,
201                }
202            }
203            Adjust::NeverToAny if adjustment.target.is_never() => return expr,
204            Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
205            Adjust::Deref(DerefAdjustKind::Builtin) => {
206                adjust_span(&mut expr);
207                ExprKind::Deref { arg: self.thir.exprs.push(expr) }
208            }
209            Adjust::Deref(DerefAdjustKind::Pin) => {
210                adjust_span(&mut expr);
211                // pointer = ($expr).pointer
212                let pin_ty = expr.ty.pinned_ty().expect("Deref(Pin) with non-Pin type");
213                let pointer_target = ExprKind::Field {
214                    lhs: self.thir.exprs.push(expr),
215                    variant_index: FIRST_VARIANT,
216                    name: FieldIdx::ZERO,
217                };
218                let expr = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target };
219                // expr = *pointer
220                ExprKind::Deref { arg: self.thir.exprs.push(expr) }
221            }
222            Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
223                // We don't need to do call adjust_span here since
224                // deref coercions always start with a built-in deref.
225                let call_def_id = deref.method_call(self.tcx);
226                let overloaded_callee = self
227                    .tcx
228                    .type_of(call_def_id)
229                    .instantiate(self.tcx, self.tcx.mk_args(&[expr.ty.into()]))
230                    .skip_norm_wip();
231
232                expr = Expr {
233                    temp_scope_id,
234                    ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, deref.mutbl),
235                    span,
236                    kind: ExprKind::Borrow {
237                        borrow_kind: deref.mutbl.to_borrow_kind(),
238                        arg: self.thir.exprs.push(expr),
239                    },
240                };
241
242                let expr = Box::new([self.thir.exprs.push(expr)]);
243
244                self.overloaded_place(
245                    hir_expr,
246                    adjustment.target,
247                    Some(overloaded_callee),
248                    expr,
249                    deref.span,
250                )
251            }
252            Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
253                borrow_kind: m.to_borrow_kind(),
254                arg: self.thir.exprs.push(expr),
255            },
256            Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
257                ExprKind::RawBorrow { mutability, arg: self.thir.exprs.push(expr) }
258            }
259            Adjust::Borrow(AutoBorrow::Pin(mutbl)) => {
260                // expr = &pin (mut|const|) arget
261                let borrow_kind = match mutbl {
262                    hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
263                    hir::Mutability::Not => BorrowKind::Shared,
264                };
265                let new_pin_target =
266                    Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, mutbl);
267                let arg = self.thir.exprs.push(expr);
268                let expr = self.thir.exprs.push(Expr {
269                    temp_scope_id,
270                    ty: new_pin_target,
271                    span,
272                    kind: ExprKind::Borrow { borrow_kind, arg },
273                });
274
275                // kind = Pin { pointer }
276                let pin_did = self.tcx.require_lang_item(LangItem::Pin, span);
277                let args = self.tcx.mk_args(&[new_pin_target.into()]);
278                let kind = ExprKind::Adt(Box::new(AdtExpr {
279                    adt_def: self.tcx.adt_def(pin_did),
280                    variant_index: FIRST_VARIANT,
281                    args,
282                    fields: Box::new([FieldExpr { name: FieldIdx::ZERO, expr }]),
283                    user_ty: None,
284                    base: AdtExprBase::None,
285                }));
286
287                debug!(?kind);
288                kind
289            }
290            Adjust::GenericReborrow(mutability) => {
291                let expr = self.thir.exprs.push(expr);
292                let kind =
293                    ExprKind::Reborrow { source: expr, mutability, target: adjustment.target };
294
295                kind
296            }
297        };
298
299        Expr { temp_scope_id, ty: adjustment.target, span, kind }
300    }
301
302    /// Lowers a cast expression.
303    ///
304    /// Dealing with user type annotations is left to the caller.
305    fn mirror_expr_cast(
306        &mut self,
307        source: &'tcx hir::Expr<'tcx>,
308        temp_scope_id: hir::ItemLocalId,
309        span: Span,
310    ) -> ExprKind<'tcx> {
311        let tcx = self.tcx;
312
313        // Check to see if this cast is a "coercion cast", where the cast is actually done
314        // using a coercion (or is a no-op).
315        if self.typeck_results.is_coercion_cast(source.hir_id) {
316            // Convert the lexpr to a vexpr.
317            ExprKind::ValueExpr { source: self.mirror_expr(source) }
318        } else if self.typeck_results.expr_ty(source).is_ref() {
319            // Special cased so that we can type check that the element
320            // type of the source matches the pointed to type of the
321            // destination.
322            ExprKind::PointerCoercion {
323                source: self.mirror_expr(source),
324                cast: PointerCoercion::ArrayToPointer,
325                is_from_as_cast: true,
326            }
327        } else if let hir::ExprKind::Path(ref qpath) = source.kind
328            && let res = self.typeck_results.qpath_res(qpath, source.hir_id)
329            && let ty = self.typeck_results.node_type(source.hir_id)
330            && let ty::Adt(adt_def, _) = ty.kind()
331            && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
332        {
333            // Check whether this is casting an enum variant discriminant.
334            // To prevent cycles, we refer to the discriminant initializer,
335            // which is always an integer and thus doesn't need to know the
336            // enum's layout (or its tag type) to compute it during const eval.
337            // Example:
338            // enum Foo {
339            //     A,
340            //     B = A as isize + 4,
341            // }
342            // The correct solution would be to add symbolic computations to miri,
343            // so we wouldn't have to compute and store the actual value
344
345            let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
346            let (discr_did, discr_offset) = adt_def.discriminant_def_for_variant(idx);
347
348            use rustc_middle::ty::util::IntTypeExt;
349            let ty = adt_def.repr().discr_type();
350            let discr_ty = ty.to_ty(tcx);
351
352            let size = tcx
353                .layout_of(self.typing_env.as_query_input(discr_ty))
354                .unwrap_or_else(|e| {
    ::core::panicking::panic_fmt(format_args!("could not compute layout for {0:?}: {1:?}",
            discr_ty, e));
}panic!("could not compute layout for {discr_ty:?}: {e:?}"))
355                .size;
356
357            let (lit, overflowing) = ScalarInt::truncate_from_uint(discr_offset as u128, size);
358            if overflowing {
359                // An erroneous enum with too many variants for its repr will emit E0081 and E0370
360                self.tcx.dcx().span_delayed_bug(
361                    source.span,
362                    "overflowing enum wasn't rejected by hir analysis",
363                );
364            }
365            let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
366            let offset = self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
367
368            let source = match discr_did {
369                // in case we are offsetting from a computed discriminant
370                // and not the beginning of discriminants (which is always `0`)
371                Some(did) => {
372                    let args = self.tcx.mk_args(&[]);
373                    self.tcx.debug_assert_args_compatible(did, args);
374                    let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None };
375                    let lhs =
376                        self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
377                    let bin = ExprKind::Binary { op: BinOp::Add, lhs, rhs: offset };
378                    self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind: bin })
379                }
380                None => offset,
381            };
382
383            ExprKind::Cast { source }
384        } else {
385            // Default to `ExprKind::Cast` for all explicit casts.
386            // MIR building then picks the right MIR casts based on the types.
387            ExprKind::Cast { source: self.mirror_expr(source) }
388        }
389    }
390
391    {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
            ::tracing::Level::DEBUG <=
                ::tracing::level_filters::LevelFilter::current() || { false }
    {
    __tracing_attr_span =
        {
            use ::tracing::__macro_support::Callsite as _;
            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                {
                    static META: ::tracing::Metadata<'static> =
                        {
                            ::tracing_core::metadata::Metadata::new("make_mirror_unadjusted",
                                "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                ::tracing_core::__macro_support::Option::Some(391u32),
                                ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                ::tracing_core::field::FieldSet::new(&[{
                                                    const NAME:
                                                        ::tracing::__macro_support::FieldName<{
                                                            ::tracing::__macro_support::FieldName::len("expr")
                                                        }> =
                                                        ::tracing::__macro_support::FieldName::new("expr");
                                                    NAME.as_str()
                                                }], ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                ::tracing::metadata::Kind::SPAN)
                        };
                    ::tracing::callsite::DefaultCallsite::new(&META)
                };
            let mut interest = ::tracing::subscriber::Interest::never();
            if ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::STATIC_MAX_LEVEL &&
                            ::tracing::Level::DEBUG <=
                                ::tracing::level_filters::LevelFilter::current() &&
                        { interest = __CALLSITE.interest(); !interest.is_never() }
                    &&
                    ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                        interest) {
                let meta = __CALLSITE.metadata();
                ::tracing::Span::new(meta,
                    &{
                            #[allow(unused_imports)]
                            use ::tracing::field::{debug, display, Value};
                            meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
                                                        as &dyn ::tracing::field::Value))])
                        })
            } else {
                let span =
                    ::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
                {};
                span
            }
        };
    __tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
    (move ||
                {

                    #[allow(unknown_lints, unreachable_code, clippy ::
                    diverging_sub_expression, clippy :: empty_loop, clippy ::
                    let_unit_value, clippy :: let_with_type_underscore, clippy
                    :: needless_return, clippy :: unreachable)]
                    if false {
                        let __tracing_attr_fake_return: Expr<'tcx> = loop {};
                        return __tracing_attr_fake_return;
                    }
                    {
                        let tcx = self.tcx;
                        let expr_ty = self.typeck_results.expr_ty(expr);
                        let mk_expr =
                            |kind, ty|
                                Expr {
                                    temp_scope_id: expr.hir_id.local_id,
                                    span: expr.span,
                                    ty,
                                    kind,
                                };
                        let kind =
                            match expr.kind {
                                hir::ExprKind::MethodCall(segment, receiver, args, fn_span)
                                    => {
                                    if self.typeck_results.is_splatted_call(expr) {
                                        self.convert_splatted_callee(expr, fn_span, args,
                                            SplattedFunc::FnDefReceiver(receiver))
                                    } else {
                                        let expr =
                                            self.method_callee(expr, segment.ident.span, None);
                                        {
                                            use ::tracing::__macro_support::Callsite as _;
                                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                {
                                                    static META: ::tracing::Metadata<'static> =
                                                        {
                                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:413",
                                                                "rustc_mir_build::thir::cx::expr", ::tracing::Level::INFO,
                                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                                ::tracing_core::__macro_support::Option::Some(413u32),
                                                                ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                                ::tracing_core::field::FieldSet::new(&["message"],
                                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                                ::tracing::metadata::Kind::EVENT)
                                                        };
                                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                                };
                                            let enabled =
                                                ::tracing::Level::INFO <=
                                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                                        ::tracing::Level::INFO <=
                                                            ::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};
                                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Using method span: {0:?}",
                                                                                            expr.span) as &dyn ::tracing::field::Value))])
                                                    });
                                            } else { ; }
                                        };
                                        let generics =
                                            match *expr.ty.kind() {
                                                ty::FnDef(def_id, _) => Some(tcx.generics_of(def_id)),
                                                _ => None,
                                            };
                                        let args =
                                            if generics.is_some_and(|g| g.has_arg_pos_consts) {
                                                let is_const_arg =
                                                    |idx: usize|
                                                        {
                                                            generics.is_some_and(|g|
                                                                    {
                                                                        g.own_arg_pos_consts().any(|(_, pos)| pos as usize == idx)
                                                                    })
                                                        };
                                                std::iter::once(receiver).chain(args.iter()).enumerate().filter(|&(idx,
                                                                    _)|
                                                                !is_const_arg(idx)).map(|(_, arg)|
                                                            self.mirror_expr(arg)).collect()
                                            } else {
                                                std::iter::once(receiver).chain(args.iter()).map(|arg|
                                                            self.mirror_expr(arg)).collect()
                                            };
                                        ExprKind::Call {
                                            ty: expr.ty,
                                            fun: self.thir.exprs.push(expr),
                                            args,
                                            from_hir_call: true,
                                            fn_span,
                                        }
                                    }
                                }
                                hir::ExprKind::Call(fun, ref args) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let method = self.method_callee(expr, fun.span, None);
                                        let arg_tys =
                                            args.iter().map(|e|
                                                    self.typeck_results.expr_ty_adjusted(e));
                                        let tupled_args =
                                            Expr {
                                                ty: Ty::new_tup_from_iter(tcx, arg_tys),
                                                temp_scope_id: expr.hir_id.local_id,
                                                span: expr.span,
                                                kind: ExprKind::Tuple { fields: self.mirror_exprs(args) },
                                            };
                                        let tupled_args = self.thir.exprs.push(tupled_args);
                                        ExprKind::Call {
                                            ty: method.ty,
                                            fun: self.thir.exprs.push(method),
                                            args: Box::new([self.mirror_expr(fun), tupled_args]),
                                            from_hir_call: true,
                                            fn_span: expr.span,
                                        }
                                    } else if self.typeck_results.is_splatted_call(expr) {
                                        self.convert_splatted_callee(expr, fun.span, args,
                                            SplattedFunc::FnExpression(fun))
                                    } else {
                                        let adt_data =
                                            if let hir::ExprKind::Path(ref qpath) = fun.kind &&
                                                    let Some(adt_def) = expr_ty.ty_adt_def() {
                                                match qpath {
                                                    hir::QPath::Resolved(_, path) =>
                                                        match path.res {
                                                            Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
                                                                Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
                                                            }
                                                            Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
                                                            _ => None,
                                                        },
                                                    hir::QPath::TypeRelative(_ty, _) => {
                                                        if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
                                                                self.typeck_results.type_dependent_def(fun.hir_id) {
                                                            Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
                                                        } else { None }
                                                    }
                                                }
                                            } else { None };
                                        if let Some((adt_def, index)) = adt_data {
                                            let node_args = self.typeck_results.node_args(fun.hir_id);
                                            let user_provided_types =
                                                self.typeck_results.user_provided_types();
                                            let user_ty =
                                                user_provided_types.get(fun.hir_id).copied().map(|mut u_ty|
                                                        {
                                                            if let ty::UserTypeKind::TypeOf(did, _) =
                                                                    &mut u_ty.value.kind {
                                                                *did = adt_def.did();
                                                            }
                                                            Box::new(u_ty)
                                                        });
                                            {
                                                use ::tracing::__macro_support::Callsite as _;
                                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                    {
                                                        static META: ::tracing::Metadata<'static> =
                                                            {
                                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:523",
                                                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                                    ::tracing_core::__macro_support::Option::Some(523u32),
                                                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                                    ::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};
                                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (call) user_ty={0:?}",
                                                                                                user_ty) as &dyn ::tracing::field::Value))])
                                                        });
                                                } else { ; }
                                            };
                                            let field_refs =
                                                args.iter().enumerate().map(|(idx, e)|
                                                            FieldExpr {
                                                                name: FieldIdx::new(idx),
                                                                expr: self.mirror_expr(e),
                                                            }).collect();
                                            ExprKind::Adt(Box::new(AdtExpr {
                                                        adt_def,
                                                        args: node_args,
                                                        variant_index: index,
                                                        fields: field_refs,
                                                        user_ty,
                                                        base: AdtExprBase::None,
                                                    }))
                                        } else {
                                            let fn_ty = self.typeck_results.node_type(fun.hir_id);
                                            let generics =
                                                match *fn_ty.kind() {
                                                    ty::FnDef(def_id, _) => Some(tcx.generics_of(def_id)),
                                                    _ => None,
                                                };
                                            let args =
                                                if generics.is_some_and(|g| g.has_arg_pos_consts) {
                                                    let is_const_arg =
                                                        |idx: usize|
                                                            {
                                                                generics.is_some_and(|g|
                                                                        {
                                                                            g.own_arg_pos_consts().any(|(_, pos)| pos as usize == idx)
                                                                        })
                                                            };
                                                    args.iter().enumerate().filter(|&(idx, _)|
                                                                    !is_const_arg(idx)).map(|(_, arg)|
                                                                self.mirror_expr(arg)).collect()
                                                } else {
                                                    args.iter().map(|arg| self.mirror_expr(arg)).collect()
                                                };
                                            ExprKind::Call {
                                                ty: fn_ty,
                                                fun: self.mirror_expr(fun),
                                                args,
                                                from_hir_call: true,
                                                fn_span: expr.span,
                                            }
                                        }
                                    }
                                }
                                hir::ExprKind::Use(expr, span) => {
                                    ExprKind::ByUse { expr: self.mirror_expr(expr), span }
                                }
                                hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
                                    ExprKind::Borrow {
                                        borrow_kind: mutbl.to_borrow_kind(),
                                        arg: self.mirror_expr(arg),
                                    }
                                }
                                hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg)
                                    => {
                                    ExprKind::RawBorrow {
                                        mutability,
                                        arg: self.mirror_expr(arg),
                                    }
                                }
                                hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr)
                                    =>
                                    match expr_ty.kind() {
                                        &ty::Adt(adt_def, args) if
                                            tcx.is_lang_item(adt_def.did(), LangItem::Pin) => {
                                            let ty = args.type_at(0);
                                            let arg_ty = self.typeck_results.expr_ty(arg_expr);
                                            let mut arg = self.mirror_expr(arg_expr);
                                            if mutbl.is_mut() &&
                                                    !arg_ty.is_unpin(self.tcx, self.typing_env) {
                                                let block =
                                                    self.thir.blocks.push(Block {
                                                            targeted_by_break: false,
                                                            region_scope: region::Scope {
                                                                local_id: arg_expr.hir_id.local_id,
                                                                data: region::ScopeData::Node,
                                                            },
                                                            span: arg_expr.span,
                                                            stmts: Box::new([]),
                                                            expr: Some(arg),
                                                            safety_mode: BlockSafety::Safe,
                                                        });
                                                arg =
                                                    self.thir.exprs.push(Expr {
                                                            temp_scope_id: arg_expr.hir_id.local_id,
                                                            ty: arg_ty,
                                                            span: arg_expr.span,
                                                            kind: ExprKind::Block { block },
                                                        });
                                            }
                                            let expr =
                                                self.thir.exprs.push(Expr {
                                                        temp_scope_id: expr.hir_id.local_id,
                                                        ty,
                                                        span: expr.span,
                                                        kind: ExprKind::Borrow {
                                                            borrow_kind: mutbl.to_borrow_kind(),
                                                            arg,
                                                        },
                                                    });
                                            ExprKind::Adt(Box::new(AdtExpr {
                                                        adt_def,
                                                        variant_index: FIRST_VARIANT,
                                                        args,
                                                        fields: Box::new([FieldExpr {
                                                                        name: FieldIdx::from(0u32),
                                                                        expr,
                                                                    }]),
                                                        user_ty: None,
                                                        base: AdtExprBase::None,
                                                    }))
                                        }
                                        _ =>
                                            ::rustc_span::macros::bug_impl(Some(expr.span),
                                                format_args!("unexpected type for pinned borrow: {0:?}",
                                                    expr_ty), Location::caller()),
                                    },
                                hir::ExprKind::Block(blk, _) =>
                                    ExprKind::Block { block: self.mirror_block(blk) },
                                hir::ExprKind::Assign(lhs, rhs, _) => {
                                    ExprKind::Assign {
                                        lhs: self.mirror_expr(lhs),
                                        rhs: self.mirror_expr(rhs),
                                    }
                                }
                                hir::ExprKind::AssignOp(op, lhs, rhs) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let lhs = self.mirror_expr(lhs);
                                        let rhs = self.mirror_expr(rhs);
                                        self.overloaded_operator(expr, Box::new([lhs, rhs]))
                                    } else {
                                        ExprKind::AssignOp {
                                            op: assign_op(op.node),
                                            lhs: self.mirror_expr(lhs),
                                            rhs: self.mirror_expr(rhs),
                                        }
                                    }
                                }
                                hir::ExprKind::Lit(lit) =>
                                    ExprKind::Literal { lit, neg: false },
                                hir::ExprKind::Binary(op, lhs, rhs) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let lhs = self.mirror_expr(lhs);
                                        let rhs = self.mirror_expr(rhs);
                                        self.overloaded_operator(expr, Box::new([lhs, rhs]))
                                    } else {
                                        match op.node {
                                            hir::BinOpKind::And =>
                                                ExprKind::LogicalOp {
                                                    op: LogicalOp::And,
                                                    lhs: self.mirror_expr(lhs),
                                                    rhs: self.mirror_expr(rhs),
                                                },
                                            hir::BinOpKind::Or =>
                                                ExprKind::LogicalOp {
                                                    op: LogicalOp::Or,
                                                    lhs: self.mirror_expr(lhs),
                                                    rhs: self.mirror_expr(rhs),
                                                },
                                            _ => {
                                                let op = bin_op(op.node);
                                                ExprKind::Binary {
                                                    op,
                                                    lhs: self.mirror_expr(lhs),
                                                    rhs: self.mirror_expr(rhs),
                                                }
                                            }
                                        }
                                    }
                                }
                                hir::ExprKind::Index(lhs, index, brackets_span) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let lhs = self.mirror_expr(lhs);
                                        let index = self.mirror_expr(index);
                                        self.overloaded_place(expr, expr_ty, None,
                                            Box::new([lhs, index]), brackets_span)
                                    } else {
                                        ExprKind::Index {
                                            lhs: self.mirror_expr(lhs),
                                            index: self.mirror_expr(index),
                                        }
                                    }
                                }
                                hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let arg = self.mirror_expr(arg);
                                        self.overloaded_place(expr, expr_ty, None, Box::new([arg]),
                                            expr.span)
                                    } else { ExprKind::Deref { arg: self.mirror_expr(arg) } }
                                }
                                hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let arg = self.mirror_expr(arg);
                                        self.overloaded_operator(expr, Box::new([arg]))
                                    } else {
                                        ExprKind::Unary {
                                            op: UnOp::Not,
                                            arg: self.mirror_expr(arg),
                                        }
                                    }
                                }
                                hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
                                    if self.typeck_results.is_method_call(expr) {
                                        let arg = self.mirror_expr(arg);
                                        self.overloaded_operator(expr, Box::new([arg]))
                                    } else if let hir::ExprKind::Lit(lit) = arg.kind {
                                        ExprKind::Literal { lit, neg: true }
                                    } else {
                                        ExprKind::Unary {
                                            op: UnOp::Neg,
                                            arg: self.mirror_expr(arg),
                                        }
                                    }
                                }
                                hir::ExprKind::Struct(qpath, fields, ref base) =>
                                    match expr_ty.kind() {
                                        ty::Adt(adt, args) =>
                                            match adt.adt_kind() {
                                                AdtKind::Struct | AdtKind::Union => {
                                                    let user_provided_types =
                                                        self.typeck_results.user_provided_types();
                                                    let user_ty =
                                                        user_provided_types.get(expr.hir_id).copied().map(Box::new);
                                                    {
                                                        use ::tracing::__macro_support::Callsite as _;
                                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                            {
                                                                static META: ::tracing::Metadata<'static> =
                                                                    {
                                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:734",
                                                                            "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                                            ::tracing_core::__macro_support::Option::Some(734u32),
                                                                            ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                                            ::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};
                                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (struct/union) user_ty={0:?}",
                                                                                                        user_ty) as &dyn ::tracing::field::Value))])
                                                                });
                                                        } else { ; }
                                                    };
                                                    ExprKind::Adt(Box::new(AdtExpr {
                                                                adt_def: *adt,
                                                                variant_index: FIRST_VARIANT,
                                                                args,
                                                                user_ty,
                                                                fields: self.field_refs(fields),
                                                                base: match base {
                                                                    hir::StructTailExpr::Base(base) =>
                                                                        AdtExprBase::Base(FruInfo {
                                                                                base: self.mirror_expr(base),
                                                                                field_types: self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect(),
                                                                            }),
                                                                    hir::StructTailExpr::DefaultFields(_) => {
                                                                        AdtExprBase::DefaultFields(self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect())
                                                                    }
                                                                    hir::StructTailExpr::None |
                                                                        hir::StructTailExpr::NoneWithError(_) => AdtExprBase::None,
                                                                },
                                                            }))
                                                }
                                                AdtKind::Enum => {
                                                    let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
                                                    match res {
                                                        Res::Def(DefKind::Variant, variant_id) => {
                                                            if !#[allow(non_exhaustive_omitted_patterns)] match base {
                                                                        hir::StructTailExpr::None |
                                                                            hir::StructTailExpr::DefaultFields(_) |
                                                                            hir::StructTailExpr::NoneWithError(_) => true,
                                                                        _ => false,
                                                                    } {
                                                                ::core::panicking::panic("assertion failed: matches!(base, hir::StructTailExpr::None |\n    hir::StructTailExpr::DefaultFields(_) |\n    hir::StructTailExpr::NoneWithError(_))")
                                                            };
                                                            let index = adt.variant_index_with_id(variant_id);
                                                            let user_provided_types =
                                                                self.typeck_results.user_provided_types();
                                                            let user_ty =
                                                                user_provided_types.get(expr.hir_id).copied().map(Box::new);
                                                            {
                                                                use ::tracing::__macro_support::Callsite as _;
                                                                static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                                    {
                                                                        static META: ::tracing::Metadata<'static> =
                                                                            {
                                                                                ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:777",
                                                                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                                                    ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                                                    ::tracing_core::__macro_support::Option::Some(777u32),
                                                                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                                                    ::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};
                                                                            __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (variant) user_ty={0:?}",
                                                                                                                user_ty) as &dyn ::tracing::field::Value))])
                                                                        });
                                                                } else { ; }
                                                            };
                                                            ExprKind::Adt(Box::new(AdtExpr {
                                                                        adt_def: *adt,
                                                                        variant_index: index,
                                                                        args,
                                                                        user_ty,
                                                                        fields: self.field_refs(fields),
                                                                        base: match base {
                                                                            hir::StructTailExpr::DefaultFields(_) => {
                                                                                AdtExprBase::DefaultFields(self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect())
                                                                            }
                                                                            hir::StructTailExpr::Base(base) => {
                                                                                ::rustc_span::macros::bug_impl(Some(base.span),
                                                                                    format_args!("unexpected res: {0:?}", res),
                                                                                    Location::caller());
                                                                            }
                                                                            hir::StructTailExpr::None |
                                                                                hir::StructTailExpr::NoneWithError(_) => {
                                                                                AdtExprBase::None
                                                                            }
                                                                        },
                                                                    }))
                                                        }
                                                        _ => {
                                                            ::rustc_span::macros::bug_impl(Some(expr.span),
                                                                format_args!("unexpected res: {0:?}", res),
                                                                Location::caller());
                                                        }
                                                    }
                                                }
                                            },
                                        _ => {
                                            ::rustc_span::macros::bug_impl(Some(expr.span),
                                                format_args!("unexpected type for struct literal: {0:?}",
                                                    expr_ty), Location::caller());
                                        }
                                    },
                                hir::ExprKind::Closure(hir::Closure { .. }) => {
                                    let closure_ty = self.typeck_results.expr_ty(expr);
                                    let (def_id, args, movability) =
                                        match *closure_ty.kind() {
                                            ty::Closure(def_id, args) =>
                                                (def_id, UpvarArgs::Closure(args), None),
                                            ty::Coroutine(def_id, args) => {
                                                (def_id, UpvarArgs::Coroutine(args),
                                                    Some(tcx.coroutine_movability(def_id)))
                                            }
                                            ty::CoroutineClosure(def_id, args) => {
                                                (def_id, UpvarArgs::CoroutineClosure(args), None)
                                            }
                                            _ => {
                                                ::rustc_span::macros::bug_impl(Some(expr.span),
                                                    format_args!("closure expr w/o closure type: {0:?}",
                                                        closure_ty), Location::caller());
                                            }
                                        };
                                    let def_id = def_id.expect_local();
                                    let upvars =
                                        self.tcx.closure_captures(def_id).iter().zip_eq(args.upvar_tys()).map(|(captured_place,
                                                        ty)|
                                                    {
                                                        let upvars = self.capture_upvar(expr, captured_place, ty);
                                                        self.thir.exprs.push(upvars)
                                                    }).collect();
                                    let fake_reads =
                                        match self.typeck_results.closure_fake_reads.get(&def_id) {
                                            Some(fake_reads) =>
                                                fake_reads.iter().map(|(place, cause, hir_id)|
                                                            {
                                                                let expr =
                                                                    self.convert_captured_hir_place(expr, place.clone());
                                                                (self.thir.exprs.push(expr), *cause, *hir_id)
                                                            }).collect(),
                                            None => Vec::new(),
                                        };
                                    ExprKind::Closure(Box::new(ClosureExpr {
                                                closure_id: def_id,
                                                args,
                                                upvars,
                                                movability,
                                                fake_reads,
                                            }))
                                }
                                hir::ExprKind::Path(ref qpath) => {
                                    let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
                                    self.convert_path_expr(expr, res)
                                }
                                hir::ExprKind::InlineAsm(asm) =>
                                    ExprKind::InlineAsm(Box::new(InlineAsmExpr {
                                                asm_macro: asm.asm_macro,
                                                template: asm.template,
                                                operands: asm.operands.iter().map(|(op, _op_sp)|
                                                            match *op {
                                                                hir::InlineAsmOperand::In { reg, expr } =>
                                                                    InlineAsmOperand::In {
                                                                        reg: reg.as_target(),
                                                                        expr: self.mirror_expr(expr),
                                                                    },
                                                                hir::InlineAsmOperand::Out { reg, late, ref expr } => {
                                                                    InlineAsmOperand::Out {
                                                                        reg: reg.as_target(),
                                                                        late,
                                                                        expr: expr.map(|expr| self.mirror_expr(expr)),
                                                                    }
                                                                }
                                                                hir::InlineAsmOperand::InOut { reg, late, expr } => {
                                                                    InlineAsmOperand::InOut {
                                                                        reg: reg.as_target(),
                                                                        late,
                                                                        expr: self.mirror_expr(expr),
                                                                    }
                                                                }
                                                                hir::InlineAsmOperand::SplitInOut {
                                                                    reg, late, in_expr, ref out_expr } => {
                                                                    InlineAsmOperand::SplitInOut {
                                                                        reg: reg.as_target(),
                                                                        late,
                                                                        in_expr: self.mirror_expr(in_expr),
                                                                        out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
                                                                    }
                                                                }
                                                                hir::InlineAsmOperand::Const { ref anon_const } => {
                                                                    let ty = self.typeck_results.node_type(anon_const.hir_id);
                                                                    let did = anon_const.def_id;
                                                                    let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
                                                                    let parent_args =
                                                                        tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx,
                                                                                typeck_root_def_id));
                                                                    let args =
                                                                        InlineConstArgs::new(tcx,
                                                                                InlineConstArgsParts { parent_args, ty }).args;
                                                                    let uneval =
                                                                        mir::UnevaluatedConst::new(did.to_def_id(), args);
                                                                    let value = mir::Const::Unevaluated(uneval, ty);
                                                                    InlineAsmOperand::Const { value, span: tcx.def_span(did) }
                                                                }
                                                                hir::InlineAsmOperand::SymFn { expr } => {
                                                                    InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
                                                                }
                                                                hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
                                                                    InlineAsmOperand::SymStatic { def_id }
                                                                }
                                                                hir::InlineAsmOperand::Label { block } => {
                                                                    InlineAsmOperand::Label { block: self.mirror_block(block) }
                                                                }
                                                            }).collect(),
                                                options: asm.options,
                                                line_spans: asm.line_spans,
                                            })),
                                hir::ExprKind::OffsetOf(_, _) => {
                                    let offset_of_intrinsic =
                                        tcx.require_lang_item(LangItem::OffsetOf, expr.span);
                                    let mk_u32_kind =
                                        |val: u32|
                                            ExprKind::NonHirLiteral {
                                                lit: ScalarInt::try_from_uint(val,
                                                        Size::from_bits(32)).unwrap(),
                                                user_ty: None,
                                            };
                                    let mk_usize_kind =
                                        |val: u64|
                                            ExprKind::NonHirLiteral {
                                                lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
                                                user_ty: None,
                                            };
                                    let mk_call =
                                        |thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx,
                                            field: FieldIdx|
                                            {
                                                let fun_ty =
                                                    tcx.type_of(offset_of_intrinsic).instantiate(tcx,
                                                            &[ty.into()]).skip_norm_wip();
                                                let fun =
                                                    thir.exprs.push(mk_expr(ExprKind::ZstLiteral {
                                                                user_ty: None,
                                                            }, fun_ty));
                                                let variant =
                                                    thir.exprs.push(mk_expr(mk_u32_kind(variant.as_u32()),
                                                            tcx.types.u32));
                                                let field =
                                                    thir.exprs.push(mk_expr(mk_u32_kind(field.as_u32()),
                                                            tcx.types.u32));
                                                let args = Box::new([variant, field]);
                                                ExprKind::Call {
                                                    ty: fun_ty,
                                                    fun,
                                                    args,
                                                    from_hir_call: false,
                                                    fn_span: expr.span,
                                                }
                                            };
                                    let indices =
                                        self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
                                    let mut expr = None::<ExprKind<'_>>;
                                    for &(container, variant, field) in indices.iter() {
                                        let next =
                                            mk_call(&mut self.thir, container, variant, field);
                                        expr =
                                            Some(match expr.take() {
                                                    None => next,
                                                    Some(last) => {
                                                        let last =
                                                            self.thir.exprs.push(mk_expr(last, tcx.types.usize));
                                                        let next =
                                                            self.thir.exprs.push(mk_expr(next, tcx.types.usize));
                                                        ExprKind::Binary { op: BinOp::Add, lhs: last, rhs: next }
                                                    }
                                                });
                                    }
                                    expr.unwrap_or_else(|| mk_usize_kind(0))
                                }
                                hir::ExprKind::ConstBlock(ref anon_const) => {
                                    let ty = self.typeck_results.node_type(anon_const.hir_id);
                                    let did = anon_const.def_id;
                                    let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
                                    let parent_args =
                                        tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx,
                                                typeck_root_def_id));
                                    let args =
                                        InlineConstArgs::new(tcx,
                                                InlineConstArgsParts { parent_args, ty }).args;
                                    ExprKind::ConstBlock { did: did.to_def_id(), args }
                                }
                                hir::ExprKind::Repeat(v, _) => {
                                    let ty = self.typeck_results.expr_ty(expr);
                                    let ty::Array(_, count) =
                                        ty.kind() else {
                                            ::rustc_span::macros::bug_impl(Some(expr.span),
                                                format_args!("unexpected repeat expr ty: {0:?}", ty),
                                                Location::caller());
                                        };
                                    ExprKind::Repeat {
                                        value: self.mirror_expr(v),
                                        count: *count,
                                    }
                                }
                                hir::ExprKind::Ret(v) =>
                                    ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
                                hir::ExprKind::Become(call) =>
                                    ExprKind::Become { value: self.mirror_expr(call) },
                                hir::ExprKind::Break(dest, ref value) => {
                                    if {
                                                {
                                                    'done:
                                                        {
                                                        for i in
                                                            ::rustc_attr_ir::HasAttrs::get_attrs(expr.hir_id, &self.tcx)
                                                            {
                                                            #[allow(unused_imports)]
                                                            use ::rustc_attr_ir::AttributeKind::*;
                                                            let i: &::rustc_attr_ir::Attribute = i;
                                                            match i {
                                                                ::rustc_attr_ir::Attribute::Parsed(ConstContinue(_)) => {
                                                                    break 'done Some(());
                                                                }
                                                                ::rustc_attr_ir::Attribute::Tool(..) |
                                                                    ::rustc_attr_ir::Attribute::DeriveHelper(..) =>
                                                                    {}
                                                                    #[deny(unreachable_patterns)]
                                                                    _ => {}
                                                            }
                                                        }
                                                        None
                                                    }
                                                }
                                            }.is_some() {
                                        match dest.target_id {
                                            Ok(target_id) => {
                                                let (Some(value), Some(_)) =
                                                    (value,
                                                        dest.label) else {
                                                        let span = expr.span;
                                                        self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue {
                                                                span,
                                                            })
                                                    };
                                                ExprKind::ConstContinue {
                                                    label: region::Scope {
                                                        local_id: target_id.local_id,
                                                        data: region::ScopeData::Node,
                                                    },
                                                    value: self.mirror_expr(value),
                                                }
                                            }
                                            Err(err) =>
                                                ::rustc_span::macros::bug_impl(None,
                                                    format_args!("invalid loop id for break: {0}", err),
                                                    Location::caller()),
                                        }
                                    } else {
                                        match dest.target_id {
                                            Ok(target_id) =>
                                                ExprKind::Break {
                                                    label: region::Scope {
                                                        local_id: target_id.local_id,
                                                        data: region::ScopeData::Node,
                                                    },
                                                    value: value.map(|value| self.mirror_expr(value)),
                                                },
                                            Err(err) =>
                                                ::rustc_span::macros::bug_impl(None,
                                                    format_args!("invalid loop id for break: {0}", err),
                                                    Location::caller()),
                                        }
                                    }
                                }
                                hir::ExprKind::Continue(dest) =>
                                    match dest.target_id {
                                        Ok(loop_id) =>
                                            ExprKind::Continue {
                                                label: region::Scope {
                                                    local_id: loop_id.local_id,
                                                    data: region::ScopeData::Node,
                                                },
                                            },
                                        Err(err) =>
                                            ::rustc_span::macros::bug_impl(None,
                                                format_args!("invalid loop id for continue: {0}", err),
                                                Location::caller()),
                                    },
                                hir::ExprKind::Let(let_expr) =>
                                    ExprKind::Let {
                                        expr: self.mirror_expr(let_expr.init),
                                        pat: self.pattern_from_hir(let_expr.pat),
                                    },
                                hir::ExprKind::If(cond, then, else_opt) =>
                                    ExprKind::If {
                                        if_then_scope: region::Scope {
                                            local_id: then.hir_id.local_id,
                                            data: {
                                                if expr.span.at_least_rust_2024() {
                                                    region::ScopeData::IfThenRescope
                                                } else { region::ScopeData::IfThen }
                                            },
                                        },
                                        cond: self.mirror_expr(cond),
                                        then: self.mirror_expr(then),
                                        else_opt: else_opt.map(|el| self.mirror_expr(el)),
                                    },
                                hir::ExprKind::Match(discr, arms, match_source) =>
                                    ExprKind::Match {
                                        scrutinee: self.mirror_expr(discr),
                                        arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
                                        match_source,
                                    },
                                hir::ExprKind::Loop(body, ..) => {
                                    if {
                                                {
                                                    'done:
                                                        {
                                                        for i in
                                                            ::rustc_attr_ir::HasAttrs::get_attrs(expr.hir_id, &self.tcx)
                                                            {
                                                            #[allow(unused_imports)]
                                                            use ::rustc_attr_ir::AttributeKind::*;
                                                            let i: &::rustc_attr_ir::Attribute = i;
                                                            match i {
                                                                ::rustc_attr_ir::Attribute::Parsed(LoopMatch(_)) => {
                                                                    break 'done Some(());
                                                                }
                                                                ::rustc_attr_ir::Attribute::Tool(..) |
                                                                    ::rustc_attr_ir::Attribute::DeriveHelper(..) =>
                                                                    {}
                                                                    #[deny(unreachable_patterns)]
                                                                    _ => {}
                                                            }
                                                        }
                                                        None
                                                    }
                                                }
                                            }.is_some() {
                                        let dcx = self.tcx.dcx();
                                        let loop_body_expr =
                                            match body.stmts {
                                                [] =>
                                                    match body.expr {
                                                        Some(expr) => expr,
                                                        None =>
                                                            dcx.emit_fatal(LoopMatchMissingAssignment {
                                                                    span: body.span,
                                                                }),
                                                    },
                                                [single] if body.expr.is_none() =>
                                                    match single.kind {
                                                        hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) =>
                                                            expr,
                                                        _ =>
                                                            dcx.emit_fatal(LoopMatchMissingAssignment {
                                                                    span: body.span,
                                                                }),
                                                    },
                                                [first @ last] | [first, .., last] =>
                                                    dcx.emit_fatal(LoopMatchBadStatements {
                                                            span: first.span.to(last.span),
                                                        }),
                                            };
                                        let hir::ExprKind::Assign(state, rhs_expr, _) =
                                            loop_body_expr.kind else {
                                                dcx.emit_fatal(LoopMatchMissingAssignment {
                                                        span: loop_body_expr.span,
                                                    })
                                            };
                                        let hir::ExprKind::Block(block_body, _) =
                                            rhs_expr.kind else {
                                                dcx.emit_fatal(LoopMatchBadRhs { span: rhs_expr.span })
                                            };
                                        for stmt in block_body.stmts {
                                            if !#[allow(non_exhaustive_omitted_patterns)] match stmt.kind
                                                        {
                                                        rustc_hir::StmtKind::Item(_) => true,
                                                        _ => false,
                                                    } {
                                                dcx.emit_fatal(LoopMatchBadStatements { span: stmt.span })
                                            }
                                        }
                                        let Some(block_body_expr) =
                                            block_body.expr else {
                                                dcx.emit_fatal(LoopMatchBadRhs { span: block_body.span })
                                            };
                                        let hir::ExprKind::Match(scrutinee, arms, _match_source) =
                                            block_body_expr.kind else {
                                                dcx.emit_fatal(LoopMatchBadRhs {
                                                        span: block_body_expr.span,
                                                    })
                                            };
                                        fn local(cx: &mut ThirBuildCx<'_>,
                                            expr: &rustc_hir::Expr<'_>) -> Option<hir::HirId> {
                                            if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) =
                                                            expr.kind && let Res::Local(hir_id) = path.res &&
                                                    !cx.is_upvar(hir_id) {
                                                return Some(hir_id);
                                            }
                                            None
                                        }
                                        let Some(scrutinee_hir_id) =
                                            local(self,
                                                scrutinee) else {
                                                dcx.emit_fatal(LoopMatchInvalidMatch {
                                                        span: scrutinee.span,
                                                    })
                                            };
                                        if local(self, state) != Some(scrutinee_hir_id) {
                                            dcx.emit_fatal(LoopMatchInvalidUpdate {
                                                    scrutinee: scrutinee.span,
                                                    lhs: state.span,
                                                })
                                        }
                                        ExprKind::LoopMatch {
                                            state: self.mirror_expr(state),
                                            region_scope: region::Scope {
                                                local_id: block_body.hir_id.local_id,
                                                data: region::ScopeData::Node,
                                            },
                                            match_data: Box::new(LoopMatchMatchData {
                                                    scrutinee: self.mirror_expr(scrutinee),
                                                    arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
                                                    span: block_body_expr.span,
                                                }),
                                        }
                                    } else {
                                        let block_ty = self.typeck_results.node_type(body.hir_id);
                                        let block = self.mirror_block(body);
                                        let body =
                                            self.thir.exprs.push(Expr {
                                                    ty: block_ty,
                                                    temp_scope_id: body.hir_id.local_id,
                                                    span: self.thir[block].span,
                                                    kind: ExprKind::Block { block },
                                                });
                                        ExprKind::Loop { body }
                                    }
                                }
                                hir::ExprKind::Field(source, ..) =>
                                    ExprKind::Field {
                                        lhs: self.mirror_expr(source),
                                        variant_index: FIRST_VARIANT,
                                        name: self.typeck_results.field_index(expr.hir_id),
                                    },
                                hir::ExprKind::Cast(source, cast_ty) => {
                                    let user_provided_types =
                                        self.typeck_results.user_provided_types();
                                    let user_ty = user_provided_types.get(cast_ty.hir_id);
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1172",
                                                            "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(1172u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                            ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("cast({0:?}) has ty w/ hir_id {1:?} and user provided ty {2:?}",
                                                                                        expr, cast_ty.hir_id, user_ty) as
                                                                                &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let cast =
                                        self.mirror_expr_cast(source, expr.hir_id.local_id,
                                            expr.span);
                                    if let Some(user_ty) = user_ty {
                                        let cast_expr =
                                            self.thir.exprs.push(Expr {
                                                    temp_scope_id: expr.hir_id.local_id,
                                                    ty: expr_ty,
                                                    span: expr.span,
                                                    kind: cast,
                                                });
                                        {
                                            use ::tracing::__macro_support::Callsite as _;
                                            static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                                {
                                                    static META: ::tracing::Metadata<'static> =
                                                        {
                                                            ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1188",
                                                                "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                                ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                                ::tracing_core::__macro_support::Option::Some(1188u32),
                                                                ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                                ::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};
                                                        __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (cast) user_ty={0:?}",
                                                                                            user_ty) as &dyn ::tracing::field::Value))])
                                                    });
                                            } else { ; }
                                        };
                                        ExprKind::ValueTypeAscription {
                                            source: cast_expr,
                                            user_ty: Some(Box::new(*user_ty)),
                                            user_ty_span: cast_ty.span,
                                        }
                                    } else { cast }
                                }
                                hir::ExprKind::Type(source, ty) => {
                                    let user_provided_types =
                                        self.typeck_results.user_provided_types();
                                    let user_ty =
                                        user_provided_types.get(ty.hir_id).copied().map(Box::new);
                                    {
                                        use ::tracing::__macro_support::Callsite as _;
                                        static __CALLSITE: ::tracing::callsite::DefaultCallsite =
                                            {
                                                static META: ::tracing::Metadata<'static> =
                                                    {
                                                        ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1202",
                                                            "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                            ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                            ::tracing_core::__macro_support::Option::Some(1202u32),
                                                            ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                            ::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};
                                                    __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (type) user_ty={0:?}",
                                                                                        user_ty) as &dyn ::tracing::field::Value))])
                                                });
                                        } else { ; }
                                    };
                                    let mirrored = self.mirror_expr(source);
                                    if source.is_syntactic_place_expr() {
                                        ExprKind::PlaceTypeAscription {
                                            source: mirrored,
                                            user_ty,
                                            user_ty_span: ty.span,
                                        }
                                    } else {
                                        ExprKind::ValueTypeAscription {
                                            source: mirrored,
                                            user_ty,
                                            user_ty_span: ty.span,
                                        }
                                    }
                                }
                                hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Unwrap,
                                    source, _ty) => {
                                    let mirrored = self.mirror_expr(source);
                                    if source.is_syntactic_place_expr() {
                                        ExprKind::PlaceUnwrapUnsafeBinder { source: mirrored }
                                    } else {
                                        ExprKind::ValueUnwrapUnsafeBinder { source: mirrored }
                                    }
                                }
                                hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Wrap,
                                    source, _ty) => {
                                    let mirrored = self.mirror_expr(source);
                                    ExprKind::WrapUnsafeBinder { source: mirrored }
                                }
                                hir::ExprKind::DropTemps(source) => {
                                    ExprKind::ValueExpr { source: self.mirror_expr(source) }
                                }
                                hir::ExprKind::Array(fields) =>
                                    ExprKind::Array { fields: self.mirror_exprs(fields) },
                                hir::ExprKind::Tup(fields) =>
                                    ExprKind::Tuple { fields: self.mirror_exprs(fields) },
                                hir::ExprKind::Yield(v, _) =>
                                    ExprKind::Yield { value: self.mirror_expr(v) },
                                hir::ExprKind::Err(_) => {
                                    ::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
                                            format_args!("cannot lower a `hir::ExprKind::Err` to THIR")));
                                }
                            };
                        mk_expr(kind, expr_ty)
                    }
                })();
{
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:391",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(391u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::tracing_core::field::FieldSet::new(&[{
                                            const NAME:
                                                ::tracing::__macro_support::FieldName<{
                                                    ::tracing::__macro_support::FieldName::len("return")
                                                }> =
                                                ::tracing::__macro_support::FieldName::new("return");
                                            NAME.as_str()
                                        }], ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
                                            as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
392    fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> {
393        let tcx = self.tcx;
394        let expr_ty = self.typeck_results.expr_ty(expr);
395        let mk_expr =
396            |kind, ty| Expr { temp_scope_id: expr.hir_id.local_id, span: expr.span, ty, kind };
397
398        let kind = match expr.kind {
399            // Here comes the interesting stuff:
400            hir::ExprKind::MethodCall(segment, receiver, args, fn_span) => {
401                if self.typeck_results.is_splatted_call(expr) {
402                    // The callee has a splatted tuple argument.
403                    // rewrite `receiver.f(a, u, v)` into `receiver.f(a, #[rustc_splat] (u, v))`
404                    self.convert_splatted_callee(
405                        expr,
406                        fn_span,
407                        args,
408                        SplattedFunc::FnDefReceiver(receiver),
409                    )
410                } else {
411                    // Rewrite a.b(c) into UFCS form like Trait::b(a, c)
412                    let expr = self.method_callee(expr, segment.ident.span, None);
413                    info!("Using method span: {:?}", expr.span);
414
415                    // Arg position const args are already part of the callee's generic args,
416                    // so we skip them when building runtime arguments.
417                    let generics = match *expr.ty.kind() {
418                        ty::FnDef(def_id, _) => Some(tcx.generics_of(def_id)),
419                        _ => None,
420                    };
421                    let args = if generics.is_some_and(|g| g.has_arg_pos_consts) {
422                        let is_const_arg = |idx: usize| {
423                            generics.is_some_and(|g| {
424                                g.own_arg_pos_consts().any(|(_, pos)| pos as usize == idx)
425                            })
426                        };
427
428                        std::iter::once(receiver)
429                            .chain(args.iter())
430                            .enumerate()
431                            .filter(|&(idx, _)| !is_const_arg(idx))
432                            .map(|(_, arg)| self.mirror_expr(arg))
433                            .collect()
434                    } else {
435                        std::iter::once(receiver)
436                            .chain(args.iter())
437                            .map(|arg| self.mirror_expr(arg))
438                            .collect()
439                    };
440
441                    ExprKind::Call {
442                        ty: expr.ty,
443                        fun: self.thir.exprs.push(expr),
444                        args,
445                        from_hir_call: true,
446                        fn_span,
447                    }
448                }
449            }
450
451            hir::ExprKind::Call(fun, ref args) => {
452                if self.typeck_results.is_method_call(expr) {
453                    // The callee is something implementing Fn, FnMut, or FnOnce.
454                    // Find the actual method implementation being called and
455                    // build the appropriate UFCS call expression with the
456                    // callee-object as expr parameter.
457
458                    // rewrite f(u, v) into FnOnce::call_once(f, (u, v))
459
460                    let method = self.method_callee(expr, fun.span, None);
461
462                    let arg_tys = args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e));
463                    let tupled_args = Expr {
464                        ty: Ty::new_tup_from_iter(tcx, arg_tys),
465                        temp_scope_id: expr.hir_id.local_id,
466                        span: expr.span,
467                        kind: ExprKind::Tuple { fields: self.mirror_exprs(args) },
468                    };
469                    let tupled_args = self.thir.exprs.push(tupled_args);
470
471                    ExprKind::Call {
472                        ty: method.ty,
473                        fun: self.thir.exprs.push(method),
474                        args: Box::new([self.mirror_expr(fun), tupled_args]),
475                        from_hir_call: true,
476                        fn_span: expr.span,
477                    }
478                } else if self.typeck_results.is_splatted_call(expr) {
479                    // The callee has a splatted tuple argument.
480                    // rewrite `f(a, u, v)` into `f(a, #[rustc_splat] (u, v))`
481                    self.convert_splatted_callee(
482                        expr,
483                        fun.span,
484                        args,
485                        SplattedFunc::FnExpression(fun),
486                    )
487                } else {
488                    // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
489                    let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
490                        && let Some(adt_def) = expr_ty.ty_adt_def()
491                    {
492                        match qpath {
493                            hir::QPath::Resolved(_, path) => match path.res {
494                                Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
495                                    Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
496                                }
497                                Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
498                                _ => None,
499                            },
500                            hir::QPath::TypeRelative(_ty, _) => {
501                                if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
502                                    self.typeck_results.type_dependent_def(fun.hir_id)
503                                {
504                                    Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
505                                } else {
506                                    None
507                                }
508                            }
509                        }
510                    } else {
511                        None
512                    };
513                    if let Some((adt_def, index)) = adt_data {
514                        let node_args = self.typeck_results.node_args(fun.hir_id);
515                        let user_provided_types = self.typeck_results.user_provided_types();
516                        let user_ty =
517                            user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
518                                if let ty::UserTypeKind::TypeOf(did, _) = &mut u_ty.value.kind {
519                                    *did = adt_def.did();
520                                }
521                                Box::new(u_ty)
522                            });
523                        debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
524
525                        let field_refs = args
526                            .iter()
527                            .enumerate()
528                            .map(|(idx, e)| FieldExpr {
529                                name: FieldIdx::new(idx),
530                                expr: self.mirror_expr(e),
531                            })
532                            .collect();
533                        ExprKind::Adt(Box::new(AdtExpr {
534                            adt_def,
535                            args: node_args,
536                            variant_index: index,
537                            fields: field_refs,
538                            user_ty,
539                            base: AdtExprBase::None,
540                        }))
541                    } else {
542                        // Arg position const args are already part of the callee's generic args,
543                        // so we skip them when building runtime arguments.
544                        let fn_ty = self.typeck_results.node_type(fun.hir_id);
545                        let generics = match *fn_ty.kind() {
546                            ty::FnDef(def_id, _) => Some(tcx.generics_of(def_id)),
547                            _ => None,
548                        };
549                        let args = if generics.is_some_and(|g| g.has_arg_pos_consts) {
550                            let is_const_arg = |idx: usize| {
551                                generics.is_some_and(|g| {
552                                    g.own_arg_pos_consts().any(|(_, pos)| pos as usize == idx)
553                                })
554                            };
555                            args.iter()
556                                .enumerate()
557                                .filter(|&(idx, _)| !is_const_arg(idx))
558                                .map(|(_, arg)| self.mirror_expr(arg))
559                                .collect()
560                        } else {
561                            args.iter().map(|arg| self.mirror_expr(arg)).collect()
562                        };
563
564                        ExprKind::Call {
565                            ty: fn_ty,
566                            fun: self.mirror_expr(fun),
567                            args,
568                            from_hir_call: true,
569                            fn_span: expr.span,
570                        }
571                    }
572                }
573            }
574
575            hir::ExprKind::Use(expr, span) => {
576                ExprKind::ByUse { expr: self.mirror_expr(expr), span }
577            }
578
579            hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
580                ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg: self.mirror_expr(arg) }
581            }
582
583            hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg) => {
584                ExprKind::RawBorrow { mutability, arg: self.mirror_expr(arg) }
585            }
586
587            // Make `&pin mut $expr` and `&pin const $expr` into
588            // `Pin { __pointer: &mut { $expr } }` and `Pin { __pointer: &$expr }`.
589            hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr) => match expr_ty.kind() {
590                &ty::Adt(adt_def, args) if tcx.is_lang_item(adt_def.did(), LangItem::Pin) => {
591                    let ty = args.type_at(0);
592                    let arg_ty = self.typeck_results.expr_ty(arg_expr);
593                    let mut arg = self.mirror_expr(arg_expr);
594                    // For `&pin mut $place` where `$place` is not `Unpin`, move the place
595                    // `$place` to ensure it will not be used afterwards.
596                    if mutbl.is_mut() && !arg_ty.is_unpin(self.tcx, self.typing_env) {
597                        let block = self.thir.blocks.push(Block {
598                            targeted_by_break: false,
599                            region_scope: region::Scope {
600                                local_id: arg_expr.hir_id.local_id,
601                                data: region::ScopeData::Node,
602                            },
603                            span: arg_expr.span,
604                            stmts: Box::new([]),
605                            expr: Some(arg),
606                            safety_mode: BlockSafety::Safe,
607                        });
608                        arg = self.thir.exprs.push(Expr {
609                            temp_scope_id: arg_expr.hir_id.local_id,
610                            ty: arg_ty,
611                            span: arg_expr.span,
612                            kind: ExprKind::Block { block },
613                        });
614                    }
615                    let expr = self.thir.exprs.push(Expr {
616                        temp_scope_id: expr.hir_id.local_id,
617                        ty,
618                        span: expr.span,
619                        kind: ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg },
620                    });
621                    ExprKind::Adt(Box::new(AdtExpr {
622                        adt_def,
623                        variant_index: FIRST_VARIANT,
624                        args,
625                        fields: Box::new([FieldExpr { name: FieldIdx::from(0u32), expr }]),
626                        user_ty: None,
627                        base: AdtExprBase::None,
628                    }))
629                }
630                _ => span_bug!(expr.span, "unexpected type for pinned borrow: {:?}", expr_ty),
631            },
632
633            hir::ExprKind::Block(blk, _) => ExprKind::Block { block: self.mirror_block(blk) },
634
635            hir::ExprKind::Assign(lhs, rhs, _) => {
636                ExprKind::Assign { lhs: self.mirror_expr(lhs), rhs: self.mirror_expr(rhs) }
637            }
638
639            hir::ExprKind::AssignOp(op, lhs, rhs) => {
640                if self.typeck_results.is_method_call(expr) {
641                    let lhs = self.mirror_expr(lhs);
642                    let rhs = self.mirror_expr(rhs);
643                    self.overloaded_operator(expr, Box::new([lhs, rhs]))
644                } else {
645                    ExprKind::AssignOp {
646                        op: assign_op(op.node),
647                        lhs: self.mirror_expr(lhs),
648                        rhs: self.mirror_expr(rhs),
649                    }
650                }
651            }
652
653            hir::ExprKind::Lit(lit) => ExprKind::Literal { lit, neg: false },
654
655            hir::ExprKind::Binary(op, lhs, rhs) => {
656                if self.typeck_results.is_method_call(expr) {
657                    let lhs = self.mirror_expr(lhs);
658                    let rhs = self.mirror_expr(rhs);
659                    self.overloaded_operator(expr, Box::new([lhs, rhs]))
660                } else {
661                    match op.node {
662                        hir::BinOpKind::And => ExprKind::LogicalOp {
663                            op: LogicalOp::And,
664                            lhs: self.mirror_expr(lhs),
665                            rhs: self.mirror_expr(rhs),
666                        },
667                        hir::BinOpKind::Or => ExprKind::LogicalOp {
668                            op: LogicalOp::Or,
669                            lhs: self.mirror_expr(lhs),
670                            rhs: self.mirror_expr(rhs),
671                        },
672                        _ => {
673                            let op = bin_op(op.node);
674                            ExprKind::Binary {
675                                op,
676                                lhs: self.mirror_expr(lhs),
677                                rhs: self.mirror_expr(rhs),
678                            }
679                        }
680                    }
681                }
682            }
683
684            hir::ExprKind::Index(lhs, index, brackets_span) => {
685                if self.typeck_results.is_method_call(expr) {
686                    let lhs = self.mirror_expr(lhs);
687                    let index = self.mirror_expr(index);
688                    self.overloaded_place(
689                        expr,
690                        expr_ty,
691                        None,
692                        Box::new([lhs, index]),
693                        brackets_span,
694                    )
695                } else {
696                    ExprKind::Index { lhs: self.mirror_expr(lhs), index: self.mirror_expr(index) }
697                }
698            }
699
700            hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
701                if self.typeck_results.is_method_call(expr) {
702                    let arg = self.mirror_expr(arg);
703                    self.overloaded_place(expr, expr_ty, None, Box::new([arg]), expr.span)
704                } else {
705                    ExprKind::Deref { arg: self.mirror_expr(arg) }
706                }
707            }
708
709            hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
710                if self.typeck_results.is_method_call(expr) {
711                    let arg = self.mirror_expr(arg);
712                    self.overloaded_operator(expr, Box::new([arg]))
713                } else {
714                    ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) }
715                }
716            }
717
718            hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
719                if self.typeck_results.is_method_call(expr) {
720                    let arg = self.mirror_expr(arg);
721                    self.overloaded_operator(expr, Box::new([arg]))
722                } else if let hir::ExprKind::Lit(lit) = arg.kind {
723                    ExprKind::Literal { lit, neg: true }
724                } else {
725                    ExprKind::Unary { op: UnOp::Neg, arg: self.mirror_expr(arg) }
726                }
727            }
728
729            hir::ExprKind::Struct(qpath, fields, ref base) => match expr_ty.kind() {
730                ty::Adt(adt, args) => match adt.adt_kind() {
731                    AdtKind::Struct | AdtKind::Union => {
732                        let user_provided_types = self.typeck_results.user_provided_types();
733                        let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
734                        debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
735                        ExprKind::Adt(Box::new(AdtExpr {
736                            adt_def: *adt,
737                            variant_index: FIRST_VARIANT,
738                            args,
739                            user_ty,
740                            fields: self.field_refs(fields),
741                            base: match base {
742                                hir::StructTailExpr::Base(base) => AdtExprBase::Base(FruInfo {
743                                    base: self.mirror_expr(base),
744                                    field_types: self.typeck_results.fru_field_types()[expr.hir_id]
745                                        .iter()
746                                        .copied()
747                                        .collect(),
748                                }),
749                                hir::StructTailExpr::DefaultFields(_) => {
750                                    AdtExprBase::DefaultFields(
751                                        self.typeck_results.fru_field_types()[expr.hir_id]
752                                            .iter()
753                                            .copied()
754                                            .collect(),
755                                    )
756                                }
757                                hir::StructTailExpr::None
758                                | hir::StructTailExpr::NoneWithError(_) => AdtExprBase::None,
759                            },
760                        }))
761                    }
762                    AdtKind::Enum => {
763                        let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
764                        match res {
765                            Res::Def(DefKind::Variant, variant_id) => {
766                                assert!(matches!(
767                                    base,
768                                    hir::StructTailExpr::None
769                                        | hir::StructTailExpr::DefaultFields(_)
770                                        | hir::StructTailExpr::NoneWithError(_)
771                                ));
772
773                                let index = adt.variant_index_with_id(variant_id);
774                                let user_provided_types = self.typeck_results.user_provided_types();
775                                let user_ty =
776                                    user_provided_types.get(expr.hir_id).copied().map(Box::new);
777                                debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
778                                ExprKind::Adt(Box::new(AdtExpr {
779                                    adt_def: *adt,
780                                    variant_index: index,
781                                    args,
782                                    user_ty,
783                                    fields: self.field_refs(fields),
784                                    base: match base {
785                                        hir::StructTailExpr::DefaultFields(_) => {
786                                            AdtExprBase::DefaultFields(
787                                                self.typeck_results.fru_field_types()[expr.hir_id]
788                                                    .iter()
789                                                    .copied()
790                                                    .collect(),
791                                            )
792                                        }
793                                        hir::StructTailExpr::Base(base) => {
794                                            span_bug!(base.span, "unexpected res: {:?}", res);
795                                        }
796                                        hir::StructTailExpr::None
797                                        | hir::StructTailExpr::NoneWithError(_) => {
798                                            AdtExprBase::None
799                                        }
800                                    },
801                                }))
802                            }
803                            _ => {
804                                span_bug!(expr.span, "unexpected res: {:?}", res);
805                            }
806                        }
807                    }
808                },
809                _ => {
810                    span_bug!(expr.span, "unexpected type for struct literal: {:?}", expr_ty);
811                }
812            },
813
814            hir::ExprKind::Closure(hir::Closure { .. }) => {
815                let closure_ty = self.typeck_results.expr_ty(expr);
816                let (def_id, args, movability) = match *closure_ty.kind() {
817                    ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
818                    ty::Coroutine(def_id, args) => {
819                        (def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id)))
820                    }
821                    ty::CoroutineClosure(def_id, args) => {
822                        (def_id, UpvarArgs::CoroutineClosure(args), None)
823                    }
824                    _ => {
825                        span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
826                    }
827                };
828                let def_id = def_id.expect_local();
829
830                let upvars = self
831                    .tcx
832                    .closure_captures(def_id)
833                    .iter()
834                    .zip_eq(args.upvar_tys())
835                    .map(|(captured_place, ty)| {
836                        let upvars = self.capture_upvar(expr, captured_place, ty);
837                        self.thir.exprs.push(upvars)
838                    })
839                    .collect();
840
841                // Convert the closure fake reads, if any, from hir `Place` to ExprRef
842                let fake_reads = match self.typeck_results.closure_fake_reads.get(&def_id) {
843                    Some(fake_reads) => fake_reads
844                        .iter()
845                        .map(|(place, cause, hir_id)| {
846                            let expr = self.convert_captured_hir_place(expr, place.clone());
847                            (self.thir.exprs.push(expr), *cause, *hir_id)
848                        })
849                        .collect(),
850                    None => Vec::new(),
851                };
852
853                ExprKind::Closure(Box::new(ClosureExpr {
854                    closure_id: def_id,
855                    args,
856                    upvars,
857                    movability,
858                    fake_reads,
859                }))
860            }
861
862            hir::ExprKind::Path(ref qpath) => {
863                let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
864                self.convert_path_expr(expr, res)
865            }
866
867            hir::ExprKind::InlineAsm(asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr {
868                asm_macro: asm.asm_macro,
869                template: asm.template,
870                operands: asm
871                    .operands
872                    .iter()
873                    .map(|(op, _op_sp)| match *op {
874                        hir::InlineAsmOperand::In { reg, expr } => InlineAsmOperand::In {
875                            reg: reg.as_target(),
876                            expr: self.mirror_expr(expr),
877                        },
878                        hir::InlineAsmOperand::Out { reg, late, ref expr } => {
879                            InlineAsmOperand::Out {
880                                reg: reg.as_target(),
881                                late,
882                                expr: expr.map(|expr| self.mirror_expr(expr)),
883                            }
884                        }
885                        hir::InlineAsmOperand::InOut { reg, late, expr } => {
886                            InlineAsmOperand::InOut {
887                                reg: reg.as_target(),
888                                late,
889                                expr: self.mirror_expr(expr),
890                            }
891                        }
892                        hir::InlineAsmOperand::SplitInOut { reg, late, in_expr, ref out_expr } => {
893                            InlineAsmOperand::SplitInOut {
894                                reg: reg.as_target(),
895                                late,
896                                in_expr: self.mirror_expr(in_expr),
897                                out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
898                            }
899                        }
900                        hir::InlineAsmOperand::Const { ref anon_const } => {
901                            let ty = self.typeck_results.node_type(anon_const.hir_id);
902                            let did = anon_const.def_id;
903                            let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
904                            let parent_args = tcx.erase_and_anonymize_regions(
905                                GenericArgs::identity_for_item(tcx, typeck_root_def_id),
906                            );
907                            let args =
908                                InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty })
909                                    .args;
910
911                            let uneval = mir::UnevaluatedConst::new(did.to_def_id(), args);
912                            let value = mir::Const::Unevaluated(uneval, ty);
913                            InlineAsmOperand::Const { value, span: tcx.def_span(did) }
914                        }
915                        hir::InlineAsmOperand::SymFn { expr } => {
916                            InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
917                        }
918                        hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
919                            InlineAsmOperand::SymStatic { def_id }
920                        }
921                        hir::InlineAsmOperand::Label { block } => {
922                            InlineAsmOperand::Label { block: self.mirror_block(block) }
923                        }
924                    })
925                    .collect(),
926                options: asm.options,
927                line_spans: asm.line_spans,
928            })),
929
930            hir::ExprKind::OffsetOf(_, _) => {
931                let offset_of_intrinsic = tcx.require_lang_item(LangItem::OffsetOf, expr.span);
932                let mk_u32_kind = |val: u32| ExprKind::NonHirLiteral {
933                    lit: ScalarInt::try_from_uint(val, Size::from_bits(32)).unwrap(),
934                    user_ty: None,
935                };
936                let mk_usize_kind = |val: u64| ExprKind::NonHirLiteral {
937                    lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
938                    user_ty: None,
939                };
940                let mk_call =
941                    |thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx, field: FieldIdx| {
942                        let fun_ty = tcx
943                            .type_of(offset_of_intrinsic)
944                            .instantiate(tcx, &[ty.into()])
945                            .skip_norm_wip();
946                        let fun = thir
947                            .exprs
948                            .push(mk_expr(ExprKind::ZstLiteral { user_ty: None }, fun_ty));
949                        let variant =
950                            thir.exprs.push(mk_expr(mk_u32_kind(variant.as_u32()), tcx.types.u32));
951                        let field =
952                            thir.exprs.push(mk_expr(mk_u32_kind(field.as_u32()), tcx.types.u32));
953                        let args = Box::new([variant, field]);
954                        ExprKind::Call {
955                            ty: fun_ty,
956                            fun,
957                            args,
958                            from_hir_call: false,
959                            fn_span: expr.span,
960                        }
961                    };
962
963                let indices = self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
964                let mut expr = None::<ExprKind<'_>>;
965
966                for &(container, variant, field) in indices.iter() {
967                    let next = mk_call(&mut self.thir, container, variant, field);
968                    expr = Some(match expr.take() {
969                        None => next,
970                        Some(last) => {
971                            let last = self.thir.exprs.push(mk_expr(last, tcx.types.usize));
972                            let next = self.thir.exprs.push(mk_expr(next, tcx.types.usize));
973                            ExprKind::Binary { op: BinOp::Add, lhs: last, rhs: next }
974                        }
975                    });
976                }
977
978                expr.unwrap_or_else(|| mk_usize_kind(0))
979            }
980
981            hir::ExprKind::ConstBlock(ref anon_const) => {
982                let ty = self.typeck_results.node_type(anon_const.hir_id);
983                let did = anon_const.def_id;
984                let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
985                let parent_args = tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(
986                    tcx,
987                    typeck_root_def_id,
988                ));
989                let args = InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty }).args;
990
991                ExprKind::ConstBlock { did: did.to_def_id(), args }
992            }
993            // Now comes the rote stuff:
994            hir::ExprKind::Repeat(v, _) => {
995                let ty = self.typeck_results.expr_ty(expr);
996                let ty::Array(_, count) = ty.kind() else {
997                    span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty);
998                };
999
1000                ExprKind::Repeat { value: self.mirror_expr(v), count: *count }
1001            }
1002            hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
1003            hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) },
1004            hir::ExprKind::Break(dest, ref value) => {
1005                if find_attr!(self.tcx, expr.hir_id, ConstContinue(_)) {
1006                    match dest.target_id {
1007                        Ok(target_id) => {
1008                            let (Some(value), Some(_)) = (value, dest.label) else {
1009                                let span = expr.span;
1010                                self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue { span })
1011                            };
1012
1013                            ExprKind::ConstContinue {
1014                                label: region::Scope {
1015                                    local_id: target_id.local_id,
1016                                    data: region::ScopeData::Node,
1017                                },
1018                                value: self.mirror_expr(value),
1019                            }
1020                        }
1021                        Err(err) => bug!("invalid loop id for break: {}", err),
1022                    }
1023                } else {
1024                    match dest.target_id {
1025                        Ok(target_id) => ExprKind::Break {
1026                            label: region::Scope {
1027                                local_id: target_id.local_id,
1028                                data: region::ScopeData::Node,
1029                            },
1030                            value: value.map(|value| self.mirror_expr(value)),
1031                        },
1032                        Err(err) => bug!("invalid loop id for break: {}", err),
1033                    }
1034                }
1035            }
1036            hir::ExprKind::Continue(dest) => match dest.target_id {
1037                Ok(loop_id) => ExprKind::Continue {
1038                    label: region::Scope {
1039                        local_id: loop_id.local_id,
1040                        data: region::ScopeData::Node,
1041                    },
1042                },
1043                Err(err) => bug!("invalid loop id for continue: {}", err),
1044            },
1045            hir::ExprKind::Let(let_expr) => ExprKind::Let {
1046                expr: self.mirror_expr(let_expr.init),
1047                pat: self.pattern_from_hir(let_expr.pat),
1048            },
1049            hir::ExprKind::If(cond, then, else_opt) => ExprKind::If {
1050                if_then_scope: region::Scope {
1051                    local_id: then.hir_id.local_id,
1052                    data: {
1053                        if expr.span.at_least_rust_2024() {
1054                            region::ScopeData::IfThenRescope
1055                        } else {
1056                            region::ScopeData::IfThen
1057                        }
1058                    },
1059                },
1060                cond: self.mirror_expr(cond),
1061                then: self.mirror_expr(then),
1062                else_opt: else_opt.map(|el| self.mirror_expr(el)),
1063            },
1064            hir::ExprKind::Match(discr, arms, match_source) => ExprKind::Match {
1065                scrutinee: self.mirror_expr(discr),
1066                arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
1067                match_source,
1068            },
1069            hir::ExprKind::Loop(body, ..) => {
1070                if find_attr!(self.tcx, expr.hir_id, LoopMatch(_)) {
1071                    let dcx = self.tcx.dcx();
1072
1073                    // Accept either `state = expr` or `state = expr;`.
1074                    let loop_body_expr = match body.stmts {
1075                        [] => match body.expr {
1076                            Some(expr) => expr,
1077                            None => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
1078                        },
1079                        [single] if body.expr.is_none() => match single.kind {
1080                            hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => expr,
1081                            _ => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
1082                        },
1083                        [first @ last] | [first, .., last] => dcx
1084                            .emit_fatal(LoopMatchBadStatements { span: first.span.to(last.span) }),
1085                    };
1086
1087                    let hir::ExprKind::Assign(state, rhs_expr, _) = loop_body_expr.kind else {
1088                        dcx.emit_fatal(LoopMatchMissingAssignment { span: loop_body_expr.span })
1089                    };
1090
1091                    let hir::ExprKind::Block(block_body, _) = rhs_expr.kind else {
1092                        dcx.emit_fatal(LoopMatchBadRhs { span: rhs_expr.span })
1093                    };
1094
1095                    // The labeled block should contain one match expression, but defining items is
1096                    // allowed.
1097                    for stmt in block_body.stmts {
1098                        if !matches!(stmt.kind, rustc_hir::StmtKind::Item(_)) {
1099                            dcx.emit_fatal(LoopMatchBadStatements { span: stmt.span })
1100                        }
1101                    }
1102
1103                    let Some(block_body_expr) = block_body.expr else {
1104                        dcx.emit_fatal(LoopMatchBadRhs { span: block_body.span })
1105                    };
1106
1107                    let hir::ExprKind::Match(scrutinee, arms, _match_source) = block_body_expr.kind
1108                    else {
1109                        dcx.emit_fatal(LoopMatchBadRhs { span: block_body_expr.span })
1110                    };
1111
1112                    fn local(
1113                        cx: &mut ThirBuildCx<'_>,
1114                        expr: &rustc_hir::Expr<'_>,
1115                    ) -> Option<hir::HirId> {
1116                        if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind
1117                            && let Res::Local(hir_id) = path.res
1118                            && !cx.is_upvar(hir_id)
1119                        {
1120                            return Some(hir_id);
1121                        }
1122
1123                        None
1124                    }
1125
1126                    let Some(scrutinee_hir_id) = local(self, scrutinee) else {
1127                        dcx.emit_fatal(LoopMatchInvalidMatch { span: scrutinee.span })
1128                    };
1129
1130                    if local(self, state) != Some(scrutinee_hir_id) {
1131                        dcx.emit_fatal(LoopMatchInvalidUpdate {
1132                            scrutinee: scrutinee.span,
1133                            lhs: state.span,
1134                        })
1135                    }
1136
1137                    ExprKind::LoopMatch {
1138                        state: self.mirror_expr(state),
1139                        region_scope: region::Scope {
1140                            local_id: block_body.hir_id.local_id,
1141                            data: region::ScopeData::Node,
1142                        },
1143
1144                        match_data: Box::new(LoopMatchMatchData {
1145                            scrutinee: self.mirror_expr(scrutinee),
1146                            arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
1147                            span: block_body_expr.span,
1148                        }),
1149                    }
1150                } else {
1151                    let block_ty = self.typeck_results.node_type(body.hir_id);
1152                    let block = self.mirror_block(body);
1153                    let body = self.thir.exprs.push(Expr {
1154                        ty: block_ty,
1155                        temp_scope_id: body.hir_id.local_id,
1156                        span: self.thir[block].span,
1157                        kind: ExprKind::Block { block },
1158                    });
1159                    ExprKind::Loop { body }
1160                }
1161            }
1162            hir::ExprKind::Field(source, ..) => ExprKind::Field {
1163                lhs: self.mirror_expr(source),
1164                variant_index: FIRST_VARIANT,
1165                name: self.typeck_results.field_index(expr.hir_id),
1166            },
1167            hir::ExprKind::Cast(source, cast_ty) => {
1168                // Check for a user-given type annotation on this `cast`
1169                let user_provided_types = self.typeck_results.user_provided_types();
1170                let user_ty = user_provided_types.get(cast_ty.hir_id);
1171
1172                debug!(
1173                    "cast({:?}) has ty w/ hir_id {:?} and user provided ty {:?}",
1174                    expr, cast_ty.hir_id, user_ty,
1175                );
1176
1177                let cast = self.mirror_expr_cast(source, expr.hir_id.local_id, expr.span);
1178
1179                if let Some(user_ty) = user_ty {
1180                    // NOTE: Creating a new Expr and wrapping a Cast inside of it may be
1181                    //       inefficient, revisit this when performance becomes an issue.
1182                    let cast_expr = self.thir.exprs.push(Expr {
1183                        temp_scope_id: expr.hir_id.local_id,
1184                        ty: expr_ty,
1185                        span: expr.span,
1186                        kind: cast,
1187                    });
1188                    debug!("make_mirror_unadjusted: (cast) user_ty={:?}", user_ty);
1189
1190                    ExprKind::ValueTypeAscription {
1191                        source: cast_expr,
1192                        user_ty: Some(Box::new(*user_ty)),
1193                        user_ty_span: cast_ty.span,
1194                    }
1195                } else {
1196                    cast
1197                }
1198            }
1199            hir::ExprKind::Type(source, ty) => {
1200                let user_provided_types = self.typeck_results.user_provided_types();
1201                let user_ty = user_provided_types.get(ty.hir_id).copied().map(Box::new);
1202                debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
1203                let mirrored = self.mirror_expr(source);
1204                if source.is_syntactic_place_expr() {
1205                    ExprKind::PlaceTypeAscription {
1206                        source: mirrored,
1207                        user_ty,
1208                        user_ty_span: ty.span,
1209                    }
1210                } else {
1211                    ExprKind::ValueTypeAscription {
1212                        source: mirrored,
1213                        user_ty,
1214                        user_ty_span: ty.span,
1215                    }
1216                }
1217            }
1218
1219            hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Unwrap, source, _ty) => {
1220                // FIXME(unsafe_binders): Take into account the ascribed type, too.
1221                let mirrored = self.mirror_expr(source);
1222                if source.is_syntactic_place_expr() {
1223                    ExprKind::PlaceUnwrapUnsafeBinder { source: mirrored }
1224                } else {
1225                    ExprKind::ValueUnwrapUnsafeBinder { source: mirrored }
1226                }
1227            }
1228            hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Wrap, source, _ty) => {
1229                // FIXME(unsafe_binders): Take into account the ascribed type, too.
1230                let mirrored = self.mirror_expr(source);
1231                ExprKind::WrapUnsafeBinder { source: mirrored }
1232            }
1233
1234            hir::ExprKind::DropTemps(source) => {
1235                ExprKind::ValueExpr { source: self.mirror_expr(source) }
1236            }
1237            hir::ExprKind::Array(fields) => ExprKind::Array { fields: self.mirror_exprs(fields) },
1238            hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
1239
1240            hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
1241            hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"),
1242        };
1243
1244        mk_expr(kind, expr_ty)
1245    }
1246
1247    fn user_args_applied_to_res(
1248        &mut self,
1249        hir_id: hir::HirId,
1250        res: Res,
1251    ) -> Option<Box<ty::CanonicalUserType<'tcx>>> {
1252        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1252",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1252u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: res={0:?}",
                                                    res) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("user_args_applied_to_res: res={:?}", res);
1253        let user_provided_type = match res {
1254            // A reference to something callable -- e.g., a fn, method, or
1255            // a tuple-struct or tuple-variant. This has the type of a
1256            // `Fn` but with the user-given generic parameters.
1257            Res::Def(DefKind::Fn, _)
1258            | Res::Def(DefKind::AssocFn, _)
1259            | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1260            | Res::Def(DefKind::Const, _)
1261            | Res::Def(DefKind::AssocConst, _) => {
1262                self.typeck_results.user_provided_types().get(hir_id).copied().map(Box::new)
1263            }
1264
1265            // A unit struct/variant which is used as a value (e.g.,
1266            // `None`). This has the type of the enum/struct that defines
1267            // this variant -- but with the generic parameters given by the
1268            // user.
1269            Res::Def(DefKind::Ctor(_, CtorKind::Const), _) => {
1270                self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new)
1271            }
1272
1273            // `Self` is used in expression as a tuple struct constructor or a unit struct constructor
1274            Res::SelfCtor(_) => self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new),
1275
1276            _ => ::rustc_span::macros::bug_impl(None,
    format_args!("user_args_applied_to_res: unexpected res {0:?} at {1:?}",
        res, hir_id), Location::caller())bug!("user_args_applied_to_res: unexpected res {:?} at {:?}", res, hir_id),
1277        };
1278        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1278",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1278u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: user_provided_type={0:?}",
                                                    user_provided_type) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("user_args_applied_to_res: user_provided_type={:?}", user_provided_type);
1279        user_provided_type
1280    }
1281
1282    fn method_callee(
1283        &mut self,
1284        expr: &hir::Expr<'_>,
1285        span: Span,
1286        overloaded_callee: Option<Ty<'tcx>>,
1287    ) -> Expr<'tcx> {
1288        let (ty, user_ty) = match overloaded_callee {
1289            Some(fn_def) => (fn_def, None),
1290            None => {
1291                let (kind, def_id) =
1292                    self.typeck_results.type_dependent_def(expr.hir_id).unwrap_or_else(|| {
1293                        ::rustc_span::macros::bug_impl(Some(expr.span),
    format_args!("no type-dependent def for method callee"),
    Location::caller())span_bug!(expr.span, "no type-dependent def for method callee")
1294                    });
1295                let user_ty = self.user_args_applied_to_res(expr.hir_id, Res::Def(kind, def_id));
1296                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1296",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1296u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_callee: user_ty={0:?}",
                                                    user_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("method_callee: user_ty={:?}", user_ty);
1297                (
1298                    self.tcx
1299                        .type_of(def_id)
1300                        .instantiate(self.tcx, self.typeck_results.node_args(expr.hir_id))
1301                        .skip_norm_wip(),
1302                    user_ty,
1303                )
1304            }
1305        };
1306        Expr {
1307            temp_scope_id: expr.hir_id.local_id,
1308            ty,
1309            span,
1310            kind: ExprKind::ZstLiteral { user_ty },
1311        }
1312    }
1313
1314    /// The callee has a splatted tuple argument.
1315    /// Rewrite a splatted call `receiver.f(a, u, v)` into `receiver.f(a, #[rustc_splat] (u, v))`.
1316    /// The receiver is optional.
1317    fn convert_splatted_callee(
1318        &mut self,
1319        call_expr: &'tcx hir::Expr<'_>,
1320        fn_span: Span,
1321        args: &'tcx [hir::Expr<'tcx>],
1322        receiver_or_func: SplattedFunc<'tcx>,
1323    ) -> ExprKind<'tcx> {
1324        let tcx = self.tcx;
1325
1326        // Look up the typeck results
1327        let splatted_def =
1328            self.typeck_results.splatted_def(call_expr.hir_id).unwrap_or_else(|| {
1329                ::rustc_span::macros::bug_impl(Some(call_expr.span),
    format_args!("no splatted def for function or method callee"),
    Location::caller())span_bug!(call_expr.span, "no splatted def for function or method callee")
1330            });
1331
1332        let tupled_arg_index = usize::from(splatted_def.arg_index());
1333        let tupled_args_count = usize::from(splatted_def.arg_count());
1334
1335        // Splatting an empty tuple is permitted: `a.f() -> Trait::f(a, #[rustc_splat] ())`.
1336        // In that case, the tupled arg index is one past the end of the args.
1337        if tupled_arg_index + tupled_args_count > args.len() {
1338            ::rustc_span::macros::bug_impl(Some(call_expr.span),
    format_args!("splatted arg index out of bounds of function args: {0:?} + {1:?} > {2:?} for function call: {3:?}, args {4:?}",
        tupled_arg_index, tupled_args_count, args.len(), receiver_or_func,
        args), Location::caller());span_bug!(
1339                call_expr.span,
1340                "splatted arg index out of bounds of function args: {:?} + {:?} > {:?} for function call: {:?}, args {:?}",
1341                tupled_arg_index,
1342                tupled_args_count,
1343                args.len(),
1344                receiver_or_func,
1345                args,
1346            );
1347        }
1348
1349        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1349",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1349u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Using splatted function span: {0:?}",
                                                    fn_span) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("Using splatted function span: {:?}", fn_span);
1350
1351        // Split into non-tupled and tupled arguments
1352        let initial_non_tupled_args =
1353            args.iter().take(tupled_arg_index).map(|e| self.mirror_expr(e)).collect_vec();
1354        let tupled_args = if tupled_arg_index == args.len() || tupled_args_count == 0 {
1355            // Splatting an empty tuple, in the ABI this gets ignored
1356            Default::default()
1357        } else {
1358            &args[tupled_arg_index..(tupled_arg_index + tupled_args_count)]
1359        };
1360        let final_non_tupled_args = args
1361            .iter()
1362            .skip(tupled_arg_index + tupled_args_count)
1363            .map(|e| self.mirror_expr(e))
1364            .collect_vec();
1365
1366        let tupled_arg_tys = tupled_args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e));
1367
1368        // We need the tupled arguments in HIR/MIR for type checking
1369        // FIXME(splat): de-tuple args in codegen for performance
1370        let tupled_args = Expr {
1371            ty: Ty::new_tup_from_iter(tcx, tupled_arg_tys),
1372            temp_scope_id: call_expr.hir_id.local_id,
1373            span: call_expr.span,
1374            kind: ExprKind::Tuple { fields: self.mirror_exprs(tupled_args) },
1375        };
1376
1377        let tupled_args = self.thir.exprs.push(tupled_args);
1378
1379        // Handle the receiver as the first arg, if present
1380        let mut args = Vec::with_capacity(
1381            usize::from(receiver_or_func.has_receiver())
1382                + initial_non_tupled_args.len()
1383                + 1
1384                + final_non_tupled_args.len(),
1385        );
1386        if let Some(receiver) = receiver_or_func.receiver() {
1387            args.push(self.mirror_expr(receiver));
1388        }
1389        args.extend(initial_non_tupled_args);
1390        args.push(tupled_args);
1391        args.extend(final_non_tupled_args);
1392
1393        let fn_span = if receiver_or_func.has_receiver() { fn_span } else { call_expr.span };
1394
1395        let (fn_ty, fun_expr) = match (splatted_def, receiver_or_func.fn_expression()) {
1396            // Create a FnDef shim for user-provided types
1397            (SplattedDef::FnDef { def_id, arg_index, arg_count }, _) => {
1398                // We're calling a function via a FnDef, and its possibly generic type
1399                // This is effectively `self.method_callee(call_expr, fn_span, None)`,
1400                // applied to `splatted_def` instead of `type_dependent_def`.
1401                let def_kind = self.tcx.def_kind(def_id);
1402                let user_ty =
1403                    self.user_args_applied_to_res(call_expr.hir_id, Res::Def(def_kind, def_id));
1404                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1404",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1404u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("splatted_callee FnDef: user_ty={0:?} def_kind={1:?} def_id={2:?} arg_index={3:?} arg_count={4:?}",
                                                    user_ty, def_kind, def_id, arg_index, arg_count) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
1405                    "splatted_callee FnDef: user_ty={:?} def_kind={:?} def_id={:?} arg_index={:?} arg_count={:?}",
1406                    user_ty, def_kind, def_id, arg_index, arg_count,
1407                );
1408
1409                // Create a new FnDef expression with user-provided type applied
1410                let callee_expr = Expr {
1411                    temp_scope_id: call_expr.hir_id.local_id,
1412                    ty: self
1413                        .tcx
1414                        .type_of(def_id)
1415                        .instantiate(self.tcx, self.typeck_results.node_args(call_expr.hir_id))
1416                        .skip_norm_wip(),
1417                    span: fn_span,
1418                    kind: ExprKind::ZstLiteral { user_ty },
1419                };
1420                (callee_expr.ty, self.thir.exprs.push(callee_expr))
1421            }
1422
1423            // We're calling a function via a FnPtr and its type
1424            // FIXME(splat): do we need to populate and apply user_provided_types() ?
1425            (SplattedDef::FnPtr { fn_ptr_type, arg_index, arg_count }, Some(fn_expression)) => {
1426                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1426",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1426u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("splatted_callee FnPtr: fn_ty={0:?} arg_index={1:?} arg_count={2:?}",
                                                    fn_ptr_type, arg_index, arg_count) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
1427                    "splatted_callee FnPtr: fn_ty={:?} arg_index={:?} arg_count={:?}",
1428                    fn_ptr_type, arg_index, arg_count,
1429                );
1430
1431                if !fn_ptr_type.is_fn() {
1432                    ::rustc_span::macros::bug_impl(Some(call_expr.span),
    format_args!("splatted FnPtr side-tables were not populated correctly, non-fn type received: {0:?}",
        fn_ptr_type), Location::caller())span_bug!(
1433                        call_expr.span,
1434                        "splatted FnPtr side-tables were not populated correctly, non-fn type received: {:?}",
1435                        fn_ptr_type
1436                    )
1437                }
1438
1439                // Pass through the FnPtr type and the mirrored function path
1440                (fn_ptr_type, self.mirror_expr(fn_expression))
1441            }
1442            // FnPtrs must have a function expression (and they never have method receivers)
1443            (SplattedDef::FnPtr { .. }, None) => {
1444                ::rustc_span::macros::bug_impl(Some(call_expr.span),
    format_args!("convert_splatted_callee: FnPtr without fn expression (or with receiver) is invalid: splatted_def={0:?}, receiver_or_func={1:?}",
        splatted_def, receiver_or_func), Location::caller());span_bug!(
1445                    call_expr.span,
1446                    "convert_splatted_callee: FnPtr without fn expression (or with receiver) is invalid: splatted_def={:?}, receiver_or_func={:?}",
1447                    splatted_def,
1448                    receiver_or_func,
1449                );
1450            }
1451        };
1452
1453        ExprKind::Call {
1454            ty: fn_ty,
1455            fun: fun_expr,
1456            args: args.into_boxed_slice(),
1457            from_hir_call: true,
1458            fn_span,
1459        }
1460    }
1461
1462    fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
1463        let arm = Arm {
1464            pattern: self.pattern_from_hir(&arm.pat),
1465            guard: arm.guard.as_ref().map(|g| self.mirror_expr(g)),
1466            body: self.mirror_expr(arm.body),
1467            hir_id: arm.hir_id,
1468            scope: region::Scope { local_id: arm.hir_id.local_id, data: region::ScopeData::Node },
1469            span: arm.span,
1470        };
1471        self.thir.arms.push(arm)
1472    }
1473
1474    fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKind<'tcx> {
1475        let args = self.typeck_results.node_args(expr.hir_id);
1476        match res {
1477            // A regular function, constructor function or a constant.
1478            Res::Def(DefKind::Fn, _)
1479            | Res::Def(DefKind::AssocFn, _)
1480            | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1481            | Res::SelfCtor(_) => {
1482                let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1483                ExprKind::ZstLiteral { user_ty }
1484            }
1485
1486            Res::Def(DefKind::ConstParam, def_id) => {
1487                let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
1488                let generics = self.tcx.generics_of(hir_id.owner);
1489                let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
1490                    ::rustc_span::macros::bug_impl(Some(expr.span),
    format_args!("Should have already errored about late bound consts: {0:?}",
        def_id), Location::caller());span_bug!(
1491                        expr.span,
1492                        "Should have already errored about late bound consts: {def_id:?}"
1493                    );
1494                };
1495                let name = self.tcx.hir_name(hir_id);
1496                let param = ty::ParamConst::new(index, name);
1497
1498                ExprKind::ConstParam { param, def_id }
1499            }
1500
1501            Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
1502                let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1503                ExprKind::NamedConst { def_id, args, user_ty }
1504            }
1505
1506            Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
1507                let user_provided_types = self.typeck_results.user_provided_types();
1508                let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
1509                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1509",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1509u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("convert_path_expr: user_ty={0:?}",
                                                    user_ty) as &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!("convert_path_expr: user_ty={:?}", user_ty);
1510                let ty = self.typeck_results.node_type(expr.hir_id);
1511                match ty.kind() {
1512                    // A unit struct/variant which is used as a value.
1513                    // We return a completely different ExprKind here to account for this special case.
1514                    ty::Adt(adt_def, args) => ExprKind::Adt(Box::new(AdtExpr {
1515                        adt_def: *adt_def,
1516                        variant_index: adt_def.variant_index_with_ctor_id(def_id),
1517                        args,
1518                        user_ty,
1519                        fields: Box::new([]),
1520                        base: AdtExprBase::None,
1521                    })),
1522                    _ => ::rustc_span::macros::bug_impl(None, format_args!("unexpected ty: {0:?}", ty),
    Location::caller())bug!("unexpected ty: {:?}", ty),
1523                }
1524            }
1525
1526            // A source Rust `path::to::STATIC` is a place expr like *&ident is.
1527            // In THIR, we make them exactly equivalent by inserting the implied *& or *&raw,
1528            // but distinguish between &STATIC and &THREAD_LOCAL as they have different semantics
1529            Res::Def(DefKind::Static { .. }, id) => {
1530                // this is &raw for extern static or static mut, and & for other statics
1531                let ty = self.tcx.static_ptr_ty(id, self.typing_env);
1532                let kind = if self.tcx.is_thread_local_static(id) {
1533                    ExprKind::ThreadLocalRef(id)
1534                } else {
1535                    let alloc_id = self.tcx.reserve_and_set_static_alloc(id);
1536                    ExprKind::StaticRef { alloc_id, ty, def_id: id }
1537                };
1538                ExprKind::Deref {
1539                    arg: self.thir.exprs.push(Expr {
1540                        ty,
1541                        temp_scope_id: expr.hir_id.local_id,
1542                        span: expr.span,
1543                        kind,
1544                    }),
1545                }
1546            }
1547
1548            Res::Local(var_hir_id) => self.convert_var(var_hir_id),
1549
1550            _ => ::rustc_span::macros::bug_impl(Some(expr.span),
    format_args!("res `{0:?}` not yet implemented", res), Location::caller())span_bug!(expr.span, "res `{:?}` not yet implemented", res),
1551        }
1552    }
1553
1554    fn convert_var(&mut self, var_hir_id: hir::HirId) -> ExprKind<'tcx> {
1555        // We want upvars here not captures.
1556        // Captures will be handled in MIR.
1557        let is_upvar = self.is_upvar(var_hir_id);
1558
1559        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event /rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs:1559",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("/rustc-dev/92ffebeceaa0a071066f233873c2438e73d70fe7/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1559u32),
                        ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                        ::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};
                __CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("convert_var({0:?}): is_upvar={1}, body_owner={2:?}",
                                                    var_hir_id, is_upvar, self.body_owner) as
                                            &dyn ::tracing::field::Value))])
            });
    } else { ; }
};debug!(
1560            "convert_var({:?}): is_upvar={}, body_owner={:?}",
1561            var_hir_id, is_upvar, self.body_owner
1562        );
1563
1564        if is_upvar {
1565            ExprKind::UpvarRef {
1566                closure_def_id: self.body_owner,
1567                var_hir_id: LocalVarId(var_hir_id),
1568            }
1569        } else {
1570            ExprKind::VarRef { id: LocalVarId(var_hir_id) }
1571        }
1572    }
1573
1574    fn overloaded_operator(
1575        &mut self,
1576        expr: &'tcx hir::Expr<'tcx>,
1577        args: Box<[ExprId]>,
1578    ) -> ExprKind<'tcx> {
1579        let fun = self.method_callee(expr, expr.span, None);
1580        let fun = self.thir.exprs.push(fun);
1581        ExprKind::Call {
1582            ty: self.thir[fun].ty,
1583            fun,
1584            args,
1585            from_hir_call: false,
1586            fn_span: expr.span,
1587        }
1588    }
1589
1590    fn overloaded_place(
1591        &mut self,
1592        expr: &'tcx hir::Expr<'tcx>,
1593        place_ty: Ty<'tcx>,
1594        overloaded_callee: Option<Ty<'tcx>>,
1595        args: Box<[ExprId]>,
1596        span: Span,
1597    ) -> ExprKind<'tcx> {
1598        // For an overloaded *x or x[y] expression of type T, the method
1599        // call returns an &T and we must add the deref so that the types
1600        // line up (this is because `*x` and `x[y]` represent places):
1601
1602        // Reconstruct the output assuming it's a reference with the
1603        // same region and mutability as the receiver. This holds for
1604        // `Deref(Mut)::deref(_mut)` and `Index(Mut)::index(_mut)`.
1605        let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else {
1606            ::rustc_span::macros::bug_impl(Some(span),
    format_args!("overloaded_place: receiver is not a reference"),
    Location::caller());span_bug!(span, "overloaded_place: receiver is not a reference");
1607        };
1608        let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl);
1609
1610        // construct the complete expression `foo()` for the overloaded call,
1611        // which will yield the &T type
1612        let fun = self.method_callee(expr, span, overloaded_callee);
1613        let fun = self.thir.exprs.push(fun);
1614        let fun_ty = self.thir[fun].ty;
1615        let ref_expr = self.thir.exprs.push(Expr {
1616            temp_scope_id: expr.hir_id.local_id,
1617            ty: ref_ty,
1618            span,
1619            kind: ExprKind::Call { ty: fun_ty, fun, args, from_hir_call: false, fn_span: span },
1620        });
1621
1622        // construct and return a deref wrapper `*foo()`
1623        ExprKind::Deref { arg: ref_expr }
1624    }
1625
1626    fn convert_captured_hir_place(
1627        &mut self,
1628        closure_expr: &'tcx hir::Expr<'tcx>,
1629        place: HirPlace<'tcx>,
1630    ) -> Expr<'tcx> {
1631        let temp_scope_id = closure_expr.hir_id.local_id;
1632        let var_ty = place.base_ty;
1633
1634        // The result of capture analysis in `rustc_hir_typeck/src/upvar.rs` represents a captured path
1635        // as it's seen for use within the closure and not at the time of closure creation.
1636        //
1637        // That is we see expect to see it start from a captured upvar and not something that is local
1638        // to the closure's parent.
1639        let var_hir_id = match place.base {
1640            HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
1641            base => ::rustc_span::macros::bug_impl(None,
    format_args!("Expected an upvar, found {0:?}", base), Location::caller())bug!("Expected an upvar, found {:?}", base),
1642        };
1643
1644        let mut captured_place_expr = Expr {
1645            temp_scope_id,
1646            ty: var_ty,
1647            span: closure_expr.span,
1648            kind: self.convert_var(var_hir_id),
1649        };
1650
1651        for proj in place.projections.iter() {
1652            let kind = match proj.kind {
1653                HirProjectionKind::Deref => {
1654                    ExprKind::Deref { arg: self.thir.exprs.push(captured_place_expr) }
1655                }
1656                HirProjectionKind::Field(field, variant_index) => ExprKind::Field {
1657                    lhs: self.thir.exprs.push(captured_place_expr),
1658                    variant_index,
1659                    name: field,
1660                },
1661                HirProjectionKind::OpaqueCast => {
1662                    ExprKind::ValueExpr { source: self.thir.exprs.push(captured_place_expr) }
1663                }
1664                HirProjectionKind::UnwrapUnsafeBinder => ExprKind::PlaceUnwrapUnsafeBinder {
1665                    source: self.thir.exprs.push(captured_place_expr),
1666                },
1667                HirProjectionKind::Index | HirProjectionKind::Subslice => {
1668                    // We don't capture these projections, so we can ignore them here
1669                    continue;
1670                }
1671            };
1672
1673            captured_place_expr =
1674                Expr { temp_scope_id, ty: proj.ty, span: closure_expr.span, kind };
1675        }
1676
1677        captured_place_expr
1678    }
1679
1680    fn capture_upvar(
1681        &mut self,
1682        closure_expr: &'tcx hir::Expr<'tcx>,
1683        captured_place: &'tcx ty::CapturedPlace<'tcx>,
1684        upvar_ty: Ty<'tcx>,
1685    ) -> Expr<'tcx> {
1686        let upvar_capture = captured_place.info.capture_kind;
1687        let captured_place_expr =
1688            self.convert_captured_hir_place(closure_expr, captured_place.place.clone());
1689        let temp_scope_id = closure_expr.hir_id.local_id;
1690
1691        match upvar_capture {
1692            ty::UpvarCapture::ByValue => captured_place_expr,
1693            ty::UpvarCapture::ByUse => {
1694                let span = captured_place_expr.span;
1695                let expr_id = self.thir.exprs.push(captured_place_expr);
1696
1697                Expr {
1698                    temp_scope_id,
1699                    ty: upvar_ty,
1700                    span: closure_expr.span,
1701                    kind: ExprKind::ByUse { expr: expr_id, span },
1702                }
1703            }
1704            ty::UpvarCapture::ByRef(upvar_borrow) => {
1705                let borrow_kind = match upvar_borrow {
1706                    ty::BorrowKind::Immutable => BorrowKind::Shared,
1707                    ty::BorrowKind::UniqueImmutable => {
1708                        BorrowKind::Mut { kind: mir::MutBorrowKind::ClosureCapture }
1709                    }
1710                    ty::BorrowKind::Mutable => {
1711                        BorrowKind::Mut { kind: mir::MutBorrowKind::Default }
1712                    }
1713                };
1714                Expr {
1715                    temp_scope_id,
1716                    ty: upvar_ty,
1717                    span: closure_expr.span,
1718                    kind: ExprKind::Borrow {
1719                        borrow_kind,
1720                        arg: self.thir.exprs.push(captured_place_expr),
1721                    },
1722                }
1723            }
1724        }
1725    }
1726
1727    fn is_upvar(&mut self, var_hir_id: hir::HirId) -> bool {
1728        self.tcx
1729            .upvars_mentioned(self.body_owner)
1730            .is_some_and(|upvars| upvars.contains_key(&var_hir_id))
1731    }
1732
1733    /// Converts a list of named fields (i.e., for struct-like struct/enum ADTs) into FieldExpr.
1734    fn field_refs(&mut self, fields: &'tcx [hir::ExprField<'tcx>]) -> Box<[FieldExpr]> {
1735        fields
1736            .iter()
1737            .map(|field| FieldExpr {
1738                name: self.typeck_results.field_index(field.hir_id),
1739                expr: self.mirror_expr(field.expr),
1740            })
1741            .collect()
1742    }
1743}
1744
1745trait ToBorrowKind {
1746    fn to_borrow_kind(&self) -> BorrowKind;
1747}
1748
1749impl ToBorrowKind for AutoBorrowMutability {
1750    fn to_borrow_kind(&self) -> BorrowKind {
1751        use rustc_middle::ty::adjustment::AllowTwoPhase;
1752        match *self {
1753            AutoBorrowMutability::Mut { allow_two_phase_borrow } => BorrowKind::Mut {
1754                kind: match allow_two_phase_borrow {
1755                    AllowTwoPhase::Yes => mir::MutBorrowKind::TwoPhaseBorrow,
1756                    AllowTwoPhase::No => mir::MutBorrowKind::Default,
1757                },
1758            },
1759            AutoBorrowMutability::Not => BorrowKind::Shared,
1760        }
1761    }
1762}
1763
1764impl ToBorrowKind for hir::Mutability {
1765    fn to_borrow_kind(&self) -> BorrowKind {
1766        match *self {
1767            hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
1768            hir::Mutability::Not => BorrowKind::Shared,
1769        }
1770    }
1771}
1772
1773fn bin_op(op: hir::BinOpKind) -> BinOp {
1774    match op {
1775        hir::BinOpKind::Add => BinOp::Add,
1776        hir::BinOpKind::Sub => BinOp::Sub,
1777        hir::BinOpKind::Mul => BinOp::Mul,
1778        hir::BinOpKind::Div => BinOp::Div,
1779        hir::BinOpKind::Rem => BinOp::Rem,
1780        hir::BinOpKind::BitXor => BinOp::BitXor,
1781        hir::BinOpKind::BitAnd => BinOp::BitAnd,
1782        hir::BinOpKind::BitOr => BinOp::BitOr,
1783        hir::BinOpKind::Shl => BinOp::Shl,
1784        hir::BinOpKind::Shr => BinOp::Shr,
1785        hir::BinOpKind::Eq => BinOp::Eq,
1786        hir::BinOpKind::Lt => BinOp::Lt,
1787        hir::BinOpKind::Le => BinOp::Le,
1788        hir::BinOpKind::Ne => BinOp::Ne,
1789        hir::BinOpKind::Ge => BinOp::Ge,
1790        hir::BinOpKind::Gt => BinOp::Gt,
1791        _ => ::rustc_span::macros::bug_impl(None,
    format_args!("no equivalent for ast binop {0:?}", op), Location::caller())bug!("no equivalent for ast binop {:?}", op),
1792    }
1793}
1794
1795fn assign_op(op: hir::AssignOpKind) -> AssignOp {
1796    match op {
1797        hir::AssignOpKind::AddAssign => AssignOp::AddAssign,
1798        hir::AssignOpKind::SubAssign => AssignOp::SubAssign,
1799        hir::AssignOpKind::MulAssign => AssignOp::MulAssign,
1800        hir::AssignOpKind::DivAssign => AssignOp::DivAssign,
1801        hir::AssignOpKind::RemAssign => AssignOp::RemAssign,
1802        hir::AssignOpKind::BitXorAssign => AssignOp::BitXorAssign,
1803        hir::AssignOpKind::BitAndAssign => AssignOp::BitAndAssign,
1804        hir::AssignOpKind::BitOrAssign => AssignOp::BitOrAssign,
1805        hir::AssignOpKind::ShlAssign => AssignOp::ShlAssign,
1806        hir::AssignOpKind::ShrAssign => AssignOp::ShrAssign,
1807    }
1808}