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