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::stack::ensure_sufficient_stack;
5use rustc_hir as hir;
6use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
7use rustc_hir::{LangItem, find_attr};
8use rustc_index::Idx;
9use rustc_middle::hir::place::{
10    Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
11};
12use rustc_middle::middle::region;
13use rustc_middle::mir::{self, AssignOp, BinOp, BorrowKind, UnOp};
14use rustc_middle::thir::*;
15use rustc_middle::ty::adjustment::{
16    Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, PointerCoercion,
17};
18use rustc_middle::ty::{
19    self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, Ty, UpvarArgs,
20};
21use rustc_middle::{bug, span_bug};
22use rustc_span::Span;
23use tracing::{debug, info, instrument, trace};
24
25use crate::errors::*;
26use crate::thir::cx::ThirBuildCx;
27
28impl<'tcx> ThirBuildCx<'tcx> {
29    /// Create a THIR expression for the given HIR expression. This expands all
30    /// adjustments and directly adds the type information from the
31    /// `typeck_results`. See the [dev-guide] for more details.
32    ///
33    /// (The term "mirror" in this case does not refer to "flipped" or
34    /// "reversed".)
35    ///
36    /// [dev-guide]: https://rustc-dev-guide.rust-lang.org/thir.html
37    pub(crate) fn mirror_expr(&mut self, expr: &'tcx hir::Expr<'tcx>) -> ExprId {
38        // `mirror_expr` is recursing very deep. Make sure the stack doesn't overflow.
39        ensure_sufficient_stack(|| self.mirror_expr_inner(expr))
40    }
41
42    pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
43        // `mirror_exprs` may also recurse deeply, so it needs protection from stack overflow.
44        // Note that we *could* forward to `mirror_expr` for that, but we can consolidate the
45        // overhead of stack growth by doing it outside the iteration.
46        ensure_sufficient_stack(|| exprs.iter().map(|expr| self.mirror_expr_inner(expr)).collect())
47    }
48
49    #[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_inner",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(49u32),
                                    ::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(&[]) })
                } 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 compiler/rustc_mir_build/src/thir/cx/expr.rs:54",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(54u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&["hir_expr.hir_id",
                                                    "hir_expr.span"],
                                        ::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};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&hir_expr.hir_id)
                                                        as &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&hir_expr.span)
                                                        as &dyn 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 compiler/rustc_mir_build/src/thir/cx/expr.rs:58",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(58u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&["expr.ty"],
                                        ::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};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&expr.ty) as
                                                        &dyn Value))])
                        });
                } else { ; }
            };
            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 compiler/rustc_mir_build/src/thir/cx/expr.rs:63",
                                            "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                            ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                            ::tracing_core::__macro_support::Option::Some(63u32),
                                            ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                            ::tracing_core::field::FieldSet::new(&["expr",
                                                            "adjustment"],
                                                ::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};
                                    let mut iter = __CALLSITE.metadata().fields().iter();
                                    __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                        ::tracing::__macro_support::Option::Some(&debug(&expr) as
                                                                &dyn Value)),
                                                    (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                        ::tracing::__macro_support::Option::Some(&debug(&adjustment)
                                                                as &dyn 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 compiler/rustc_mir_build/src/thir/cx/expr.rs:69",
                                    "rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
                                    ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(69u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&["message",
                                                    "expr.ty"],
                                        ::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};
                            let mut iter = __CALLSITE.metadata().fields().iter();
                            __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&format_args!("after adjustments")
                                                        as &dyn Value)),
                                            (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                ::tracing::__macro_support::Option::Some(&debug(&expr.ty) as
                                                        &dyn Value))])
                        });
                } else { ; }
            };
            expr =
                Expr {
                    temp_scope_id: expr_scope.local_id,
                    ty: expr.ty,
                    span: hir_expr.span,
                    kind: ExprKind::Scope {
                        region_scope: expr_scope,
                        value: self.thir.exprs.push(expr),
                        hir_id: hir_expr.hir_id,
                    },
                };
            self.thir.exprs.push(expr)
        }
    }
}#[instrument(level = "trace", skip(self, hir_expr))]
50    pub(super) fn mirror_expr_inner(&mut self, hir_expr: &'tcx hir::Expr<'tcx>) -> ExprId {
51        let expr_scope =
52            region::Scope { local_id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
53
54        trace!(?hir_expr.hir_id, ?hir_expr.span);
55
56        let mut expr = self.make_mirror_unadjusted(hir_expr);
57
58        trace!(?expr.ty);
59
60        // Now apply adjustments, if any.
61        if self.apply_adjustments {
62            for adjustment in self.typeck_results.expr_adjustments(hir_expr) {
63                trace!(?expr, ?adjustment);
64                let span = expr.span;
65                expr = self.apply_adjustment(hir_expr, expr, adjustment, span);
66            }
67        }
68
69        trace!(?expr.ty, "after adjustments");
70
71        // Finally, wrap this up in the expr's scope.
72        expr = Expr {
73            temp_scope_id: expr_scope.local_id,
74            ty: expr.ty,
75            span: hir_expr.span,
76            kind: ExprKind::Scope {
77                region_scope: expr_scope,
78                value: self.thir.exprs.push(expr),
79                hir_id: hir_expr.hir_id,
80            },
81        };
82
83        // OK, all done!
84        self.thir.exprs.push(expr)
85    }
86
87    #[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("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                    ::tracing_core::__macro_support::Option::Some(87u32),
                                    ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                    ::tracing_core::field::FieldSet::new(&["hir_expr",
                                                    "adjustment"],
                                        ::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};
                                let mut iter = meta.fields().iter();
                                meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr)
                                                            as &dyn Value)),
                                                (&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                    ::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adjustment)
                                                            as &dyn 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 =
                            Ty::new_fn_def(self.tcx, call_def_id,
                                self.tcx.mk_args(&[expr.ty.into()]));
                        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(rustc_hir::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 compiler/rustc_mir_build/src/thir/cx/expr.rs:221",
                                                "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                                                ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                                                ::tracing_core::__macro_support::Option::Some(221u32),
                                                ::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
                                                ::tracing_core::field::FieldSet::new(&["kind"],
                                                    ::tracing_core::callsite::Identifier(&__CALLSITE)),
                                                ::tracing::metadata::Kind::EVENT)
                                        };
                                    ::tracing::callsite::DefaultCallsite::new(&META)
                                };
                            let enabled =
                                ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::STATIC_MAX_LEVEL &&
                                        ::tracing::Level::DEBUG <=
                                            ::tracing::level_filters::LevelFilter::current() &&
                                    {
                                        let interest = __CALLSITE.interest();
                                        !interest.is_never() &&
                                            ::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
                                                interest)
                                    };
                            if enabled {
                                (|value_set: ::tracing::field::ValueSet|
                                            {
                                                let meta = __CALLSITE.metadata();
                                                ::tracing::Event::dispatch(meta, &value_set);
                                                ;
                                            })({
                                        #[allow(unused_imports)]
                                        use ::tracing::field::{debug, display, Value};
                                        let mut iter = __CALLSITE.metadata().fields().iter();
                                        __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                                            ::tracing::__macro_support::Option::Some(&debug(&kind) as
                                                                    &dyn Value))])
                                    });
                            } else { ; }
                        };
                        kind
                    }
                };
            Expr { temp_scope_id, ty: adjustment.target, span, kind }
        }
    }
}#[instrument(level = "trace", skip(self, expr, span))]
88    fn apply_adjustment(
89        &mut self,
90        hir_expr: &'tcx hir::Expr<'tcx>,
91        mut expr: Expr<'tcx>,
92        adjustment: &Adjustment<'tcx>,
93        mut span: Span,
94    ) -> Expr<'tcx> {
95        let Expr { temp_scope_id, .. } = expr;
96
97        // Adjust the span from the block, to the last expression of the
98        // block. This is a better span when returning a mutable reference
99        // with too short a lifetime. The error message will use the span
100        // from the assignment to the return place, which should only point
101        // at the returned value, not the entire function body.
102        //
103        // fn return_short_lived<'a>(x: &'a mut i32) -> &'static mut i32 {
104        //      x
105        //   // ^ error message points at this expression.
106        // }
107        let mut adjust_span = |expr: &mut Expr<'tcx>| {
108            if let ExprKind::Block { block } = expr.kind
109                && let Some(last_expr) = self.thir[block].expr
110            {
111                span = self.thir[last_expr].span;
112                expr.span = span;
113            }
114        };
115
116        let kind = match adjustment.kind {
117            Adjust::Pointer(cast) => {
118                if cast == PointerCoercion::Unsize {
119                    adjust_span(&mut expr);
120                }
121
122                let is_from_as_cast = if let hir::Node::Expr(hir::Expr {
123                    kind: hir::ExprKind::Cast(..),
124                    span: cast_span,
125                    ..
126                }) = self.tcx.parent_hir_node(hir_expr.hir_id)
127                {
128                    // Use the whole span of the `x as T` expression for the coercion.
129                    span = *cast_span;
130                    true
131                } else {
132                    false
133                };
134                ExprKind::PointerCoercion {
135                    cast,
136                    source: self.thir.exprs.push(expr),
137                    is_from_as_cast,
138                }
139            }
140            Adjust::NeverToAny if adjustment.target.is_never() => return expr,
141            Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
142            Adjust::Deref(DerefAdjustKind::Builtin) => {
143                adjust_span(&mut expr);
144                ExprKind::Deref { arg: self.thir.exprs.push(expr) }
145            }
146            Adjust::Deref(DerefAdjustKind::Pin) => {
147                adjust_span(&mut expr);
148                // pointer = ($expr).pointer
149                let pin_ty = expr.ty.pinned_ty().expect("Deref(Pin) with non-Pin type");
150                let pointer_target = ExprKind::Field {
151                    lhs: self.thir.exprs.push(expr),
152                    variant_index: FIRST_VARIANT,
153                    name: FieldIdx::ZERO,
154                };
155                let expr = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target };
156                // expr = *pointer
157                ExprKind::Deref { arg: self.thir.exprs.push(expr) }
158            }
159            Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
160                // We don't need to do call adjust_span here since
161                // deref coercions always start with a built-in deref.
162                let call_def_id = deref.method_call(self.tcx);
163                let overloaded_callee =
164                    Ty::new_fn_def(self.tcx, call_def_id, self.tcx.mk_args(&[expr.ty.into()]));
165
166                expr = Expr {
167                    temp_scope_id,
168                    ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, deref.mutbl),
169                    span,
170                    kind: ExprKind::Borrow {
171                        borrow_kind: deref.mutbl.to_borrow_kind(),
172                        arg: self.thir.exprs.push(expr),
173                    },
174                };
175
176                let expr = Box::new([self.thir.exprs.push(expr)]);
177
178                self.overloaded_place(
179                    hir_expr,
180                    adjustment.target,
181                    Some(overloaded_callee),
182                    expr,
183                    deref.span,
184                )
185            }
186            Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
187                borrow_kind: m.to_borrow_kind(),
188                arg: self.thir.exprs.push(expr),
189            },
190            Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
191                ExprKind::RawBorrow { mutability, arg: self.thir.exprs.push(expr) }
192            }
193            Adjust::Borrow(AutoBorrow::Pin(mutbl)) => {
194                // expr = &pin (mut|const|) arget
195                let borrow_kind = match mutbl {
196                    hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
197                    hir::Mutability::Not => BorrowKind::Shared,
198                };
199                let new_pin_target =
200                    Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, mutbl);
201                let arg = self.thir.exprs.push(expr);
202                let expr = self.thir.exprs.push(Expr {
203                    temp_scope_id,
204                    ty: new_pin_target,
205                    span,
206                    kind: ExprKind::Borrow { borrow_kind, arg },
207                });
208
209                // kind = Pin { pointer }
210                let pin_did = self.tcx.require_lang_item(rustc_hir::LangItem::Pin, span);
211                let args = self.tcx.mk_args(&[new_pin_target.into()]);
212                let kind = ExprKind::Adt(Box::new(AdtExpr {
213                    adt_def: self.tcx.adt_def(pin_did),
214                    variant_index: FIRST_VARIANT,
215                    args,
216                    fields: Box::new([FieldExpr { name: FieldIdx::ZERO, expr }]),
217                    user_ty: None,
218                    base: AdtExprBase::None,
219                }));
220
221                debug!(?kind);
222                kind
223            }
224        };
225
226        Expr { temp_scope_id, ty: adjustment.target, span, kind }
227    }
228
229    /// Lowers a cast expression.
230    ///
231    /// Dealing with user type annotations is left to the caller.
232    fn mirror_expr_cast(
233        &mut self,
234        source: &'tcx hir::Expr<'tcx>,
235        temp_scope_id: hir::ItemLocalId,
236        span: Span,
237    ) -> ExprKind<'tcx> {
238        let tcx = self.tcx;
239
240        // Check to see if this cast is a "coercion cast", where the cast is actually done
241        // using a coercion (or is a no-op).
242        if self.typeck_results.is_coercion_cast(source.hir_id) {
243            // Convert the lexpr to a vexpr.
244            ExprKind::Use { source: self.mirror_expr(source) }
245        } else if self.typeck_results.expr_ty(source).is_ref() {
246            // Special cased so that we can type check that the element
247            // type of the source matches the pointed to type of the
248            // destination.
249            ExprKind::PointerCoercion {
250                source: self.mirror_expr(source),
251                cast: PointerCoercion::ArrayToPointer,
252                is_from_as_cast: true,
253            }
254        } else if let hir::ExprKind::Path(ref qpath) = source.kind
255            && let res = self.typeck_results.qpath_res(qpath, source.hir_id)
256            && let ty = self.typeck_results.node_type(source.hir_id)
257            && let ty::Adt(adt_def, args) = ty.kind()
258            && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
259        {
260            // Check whether this is casting an enum variant discriminant.
261            // To prevent cycles, we refer to the discriminant initializer,
262            // which is always an integer and thus doesn't need to know the
263            // enum's layout (or its tag type) to compute it during const eval.
264            // Example:
265            // enum Foo {
266            //     A,
267            //     B = A as isize + 4,
268            // }
269            // The correct solution would be to add symbolic computations to miri,
270            // so we wouldn't have to compute and store the actual value
271
272            let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
273            let (discr_did, discr_offset) = adt_def.discriminant_def_for_variant(idx);
274
275            use rustc_middle::ty::util::IntTypeExt;
276            let ty = adt_def.repr().discr_type();
277            let discr_ty = ty.to_ty(tcx);
278
279            let size = tcx
280                .layout_of(self.typing_env.as_query_input(discr_ty))
281                .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:?}"))
282                .size;
283
284            let (lit, overflowing) = ScalarInt::truncate_from_uint(discr_offset as u128, size);
285            if overflowing {
286                // An erroneous enum with too many variants for its repr will emit E0081 and E0370
287                self.tcx.dcx().span_delayed_bug(
288                    source.span,
289                    "overflowing enum wasn't rejected by hir analysis",
290                );
291            }
292            let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
293            let offset = self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
294
295            let source = match discr_did {
296                // in case we are offsetting from a computed discriminant
297                // and not the beginning of discriminants (which is always `0`)
298                Some(did) => {
299                    let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None };
300                    let lhs =
301                        self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
302                    let bin = ExprKind::Binary { op: BinOp::Add, lhs, rhs: offset };
303                    self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind: bin })
304                }
305                None => offset,
306            };
307
308            ExprKind::Cast { source }
309        } else {
310            // Default to `ExprKind::Cast` for all explicit casts.
311            // MIR building then picks the right MIR casts based on the types.
312            ExprKind::Cast { source: self.mirror_expr(source) }
313        }
314    }
315
316    x;#[instrument(level = "debug", skip(self), ret)]
317    fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> {
318        let tcx = self.tcx;
319        let expr_ty = self.typeck_results.expr_ty(expr);
320        let mk_expr =
321            |kind, ty| Expr { temp_scope_id: expr.hir_id.local_id, span: expr.span, ty, kind };
322
323        let kind = match expr.kind {
324            // Here comes the interesting stuff:
325            hir::ExprKind::MethodCall(segment, receiver, args, fn_span) => {
326                // Rewrite a.b(c) into UFCS form like Trait::b(a, c)
327                let expr = self.method_callee(expr, segment.ident.span, None);
328                info!("Using method span: {:?}", expr.span);
329                let args = std::iter::once(receiver)
330                    .chain(args.iter())
331                    .map(|expr| self.mirror_expr(expr))
332                    .collect();
333                ExprKind::Call {
334                    ty: expr.ty,
335                    fun: self.thir.exprs.push(expr),
336                    args,
337                    from_hir_call: true,
338                    fn_span,
339                }
340            }
341
342            hir::ExprKind::Call(fun, ref args) => {
343                if self.typeck_results.is_method_call(expr) {
344                    // The callee is something implementing Fn, FnMut, or FnOnce.
345                    // Find the actual method implementation being called and
346                    // build the appropriate UFCS call expression with the
347                    // callee-object as expr parameter.
348
349                    // rewrite f(u, v) into FnOnce::call_once(f, (u, v))
350
351                    let method = self.method_callee(expr, fun.span, None);
352
353                    let arg_tys = args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e));
354                    let tupled_args = Expr {
355                        ty: Ty::new_tup_from_iter(tcx, arg_tys),
356                        temp_scope_id: expr.hir_id.local_id,
357                        span: expr.span,
358                        kind: ExprKind::Tuple { fields: self.mirror_exprs(args) },
359                    };
360                    let tupled_args = self.thir.exprs.push(tupled_args);
361
362                    ExprKind::Call {
363                        ty: method.ty,
364                        fun: self.thir.exprs.push(method),
365                        args: Box::new([self.mirror_expr(fun), tupled_args]),
366                        from_hir_call: true,
367                        fn_span: expr.span,
368                    }
369                } else {
370                    // Tuple-like ADTs are represented as ExprKind::Call. We convert them here.
371                    let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
372                        && let Some(adt_def) = expr_ty.ty_adt_def()
373                    {
374                        match qpath {
375                            hir::QPath::Resolved(_, path) => match path.res {
376                                Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
377                                    Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
378                                }
379                                Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
380                                _ => None,
381                            },
382                            hir::QPath::TypeRelative(_ty, _) => {
383                                if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
384                                    self.typeck_results.type_dependent_def(fun.hir_id)
385                                {
386                                    Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
387                                } else {
388                                    None
389                                }
390                            }
391                        }
392                    } else {
393                        None
394                    };
395                    if let Some((adt_def, index)) = adt_data {
396                        let node_args = self.typeck_results.node_args(fun.hir_id);
397                        let user_provided_types = self.typeck_results.user_provided_types();
398                        let user_ty =
399                            user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
400                                if let ty::UserTypeKind::TypeOf(did, _) = &mut u_ty.value.kind {
401                                    *did = adt_def.did();
402                                }
403                                Box::new(u_ty)
404                            });
405                        debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
406
407                        let field_refs = args
408                            .iter()
409                            .enumerate()
410                            .map(|(idx, e)| FieldExpr {
411                                name: FieldIdx::new(idx),
412                                expr: self.mirror_expr(e),
413                            })
414                            .collect();
415                        ExprKind::Adt(Box::new(AdtExpr {
416                            adt_def,
417                            args: node_args,
418                            variant_index: index,
419                            fields: field_refs,
420                            user_ty,
421                            base: AdtExprBase::None,
422                        }))
423                    } else {
424                        ExprKind::Call {
425                            ty: self.typeck_results.node_type(fun.hir_id),
426                            fun: self.mirror_expr(fun),
427                            args: self.mirror_exprs(args),
428                            from_hir_call: true,
429                            fn_span: expr.span,
430                        }
431                    }
432                }
433            }
434
435            hir::ExprKind::Use(expr, span) => {
436                ExprKind::ByUse { expr: self.mirror_expr(expr), span }
437            }
438
439            hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
440                ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg: self.mirror_expr(arg) }
441            }
442
443            hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg) => {
444                ExprKind::RawBorrow { mutability, arg: self.mirror_expr(arg) }
445            }
446
447            // Make `&pin mut $expr` and `&pin const $expr` into
448            // `Pin { __pointer: &mut { $expr } }` and `Pin { __pointer: &$expr }`.
449            hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr) => match expr_ty.kind() {
450                &ty::Adt(adt_def, args) if tcx.is_lang_item(adt_def.did(), hir::LangItem::Pin) => {
451                    let ty = args.type_at(0);
452                    let arg_ty = self.typeck_results.expr_ty(arg_expr);
453                    let mut arg = self.mirror_expr(arg_expr);
454                    // For `&pin mut $place` where `$place` is not `Unpin`, move the place
455                    // `$place` to ensure it will not be used afterwards.
456                    if mutbl.is_mut() && !arg_ty.is_unpin(self.tcx, self.typing_env) {
457                        let block = self.thir.blocks.push(Block {
458                            targeted_by_break: false,
459                            region_scope: region::Scope {
460                                local_id: arg_expr.hir_id.local_id,
461                                data: region::ScopeData::Node,
462                            },
463                            span: arg_expr.span,
464                            stmts: Box::new([]),
465                            expr: Some(arg),
466                            safety_mode: BlockSafety::Safe,
467                        });
468                        arg = self.thir.exprs.push(Expr {
469                            temp_scope_id: arg_expr.hir_id.local_id,
470                            ty: arg_ty,
471                            span: arg_expr.span,
472                            kind: ExprKind::Block { block },
473                        });
474                    }
475                    let expr = self.thir.exprs.push(Expr {
476                        temp_scope_id: expr.hir_id.local_id,
477                        ty,
478                        span: expr.span,
479                        kind: ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg },
480                    });
481                    ExprKind::Adt(Box::new(AdtExpr {
482                        adt_def,
483                        variant_index: FIRST_VARIANT,
484                        args,
485                        fields: Box::new([FieldExpr { name: FieldIdx::from(0u32), expr }]),
486                        user_ty: None,
487                        base: AdtExprBase::None,
488                    }))
489                }
490                _ => span_bug!(expr.span, "unexpected type for pinned borrow: {:?}", expr_ty),
491            },
492
493            hir::ExprKind::Block(blk, _) => ExprKind::Block { block: self.mirror_block(blk) },
494
495            hir::ExprKind::Assign(lhs, rhs, _) => {
496                ExprKind::Assign { lhs: self.mirror_expr(lhs), rhs: self.mirror_expr(rhs) }
497            }
498
499            hir::ExprKind::AssignOp(op, lhs, rhs) => {
500                if self.typeck_results.is_method_call(expr) {
501                    let lhs = self.mirror_expr(lhs);
502                    let rhs = self.mirror_expr(rhs);
503                    self.overloaded_operator(expr, Box::new([lhs, rhs]))
504                } else {
505                    ExprKind::AssignOp {
506                        op: assign_op(op.node),
507                        lhs: self.mirror_expr(lhs),
508                        rhs: self.mirror_expr(rhs),
509                    }
510                }
511            }
512
513            hir::ExprKind::Lit(lit) => ExprKind::Literal { lit, neg: false },
514
515            hir::ExprKind::Binary(op, lhs, rhs) => {
516                if self.typeck_results.is_method_call(expr) {
517                    let lhs = self.mirror_expr(lhs);
518                    let rhs = self.mirror_expr(rhs);
519                    self.overloaded_operator(expr, Box::new([lhs, rhs]))
520                } else {
521                    match op.node {
522                        hir::BinOpKind::And => ExprKind::LogicalOp {
523                            op: LogicalOp::And,
524                            lhs: self.mirror_expr(lhs),
525                            rhs: self.mirror_expr(rhs),
526                        },
527                        hir::BinOpKind::Or => ExprKind::LogicalOp {
528                            op: LogicalOp::Or,
529                            lhs: self.mirror_expr(lhs),
530                            rhs: self.mirror_expr(rhs),
531                        },
532                        _ => {
533                            let op = bin_op(op.node);
534                            ExprKind::Binary {
535                                op,
536                                lhs: self.mirror_expr(lhs),
537                                rhs: self.mirror_expr(rhs),
538                            }
539                        }
540                    }
541                }
542            }
543
544            hir::ExprKind::Index(lhs, index, brackets_span) => {
545                if self.typeck_results.is_method_call(expr) {
546                    let lhs = self.mirror_expr(lhs);
547                    let index = self.mirror_expr(index);
548                    self.overloaded_place(
549                        expr,
550                        expr_ty,
551                        None,
552                        Box::new([lhs, index]),
553                        brackets_span,
554                    )
555                } else {
556                    ExprKind::Index { lhs: self.mirror_expr(lhs), index: self.mirror_expr(index) }
557                }
558            }
559
560            hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
561                if self.typeck_results.is_method_call(expr) {
562                    let arg = self.mirror_expr(arg);
563                    self.overloaded_place(expr, expr_ty, None, Box::new([arg]), expr.span)
564                } else {
565                    ExprKind::Deref { arg: self.mirror_expr(arg) }
566                }
567            }
568
569            hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
570                if self.typeck_results.is_method_call(expr) {
571                    let arg = self.mirror_expr(arg);
572                    self.overloaded_operator(expr, Box::new([arg]))
573                } else {
574                    ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) }
575                }
576            }
577
578            hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
579                if self.typeck_results.is_method_call(expr) {
580                    let arg = self.mirror_expr(arg);
581                    self.overloaded_operator(expr, Box::new([arg]))
582                } else if let hir::ExprKind::Lit(lit) = arg.kind {
583                    ExprKind::Literal { lit, neg: true }
584                } else {
585                    ExprKind::Unary { op: UnOp::Neg, arg: self.mirror_expr(arg) }
586                }
587            }
588
589            hir::ExprKind::Struct(qpath, fields, ref base) => match expr_ty.kind() {
590                ty::Adt(adt, args) => match adt.adt_kind() {
591                    AdtKind::Struct | AdtKind::Union => {
592                        let user_provided_types = self.typeck_results.user_provided_types();
593                        let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
594                        debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
595                        ExprKind::Adt(Box::new(AdtExpr {
596                            adt_def: *adt,
597                            variant_index: FIRST_VARIANT,
598                            args,
599                            user_ty,
600                            fields: self.field_refs(fields),
601                            base: match base {
602                                hir::StructTailExpr::Base(base) => AdtExprBase::Base(FruInfo {
603                                    base: self.mirror_expr(base),
604                                    field_types: self.typeck_results.fru_field_types()[expr.hir_id]
605                                        .iter()
606                                        .copied()
607                                        .collect(),
608                                }),
609                                hir::StructTailExpr::DefaultFields(_) => {
610                                    AdtExprBase::DefaultFields(
611                                        self.typeck_results.fru_field_types()[expr.hir_id]
612                                            .iter()
613                                            .copied()
614                                            .collect(),
615                                    )
616                                }
617                                hir::StructTailExpr::None
618                                | hir::StructTailExpr::NoneWithError(_) => AdtExprBase::None,
619                            },
620                        }))
621                    }
622                    AdtKind::Enum => {
623                        let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
624                        match res {
625                            Res::Def(DefKind::Variant, variant_id) => {
626                                assert!(matches!(
627                                    base,
628                                    hir::StructTailExpr::None
629                                        | hir::StructTailExpr::DefaultFields(_)
630                                        | hir::StructTailExpr::NoneWithError(_)
631                                ));
632
633                                let index = adt.variant_index_with_id(variant_id);
634                                let user_provided_types = self.typeck_results.user_provided_types();
635                                let user_ty =
636                                    user_provided_types.get(expr.hir_id).copied().map(Box::new);
637                                debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
638                                ExprKind::Adt(Box::new(AdtExpr {
639                                    adt_def: *adt,
640                                    variant_index: index,
641                                    args,
642                                    user_ty,
643                                    fields: self.field_refs(fields),
644                                    base: match base {
645                                        hir::StructTailExpr::DefaultFields(_) => {
646                                            AdtExprBase::DefaultFields(
647                                                self.typeck_results.fru_field_types()[expr.hir_id]
648                                                    .iter()
649                                                    .copied()
650                                                    .collect(),
651                                            )
652                                        }
653                                        hir::StructTailExpr::Base(base) => {
654                                            span_bug!(base.span, "unexpected res: {:?}", res);
655                                        }
656                                        hir::StructTailExpr::None
657                                        | hir::StructTailExpr::NoneWithError(_) => {
658                                            AdtExprBase::None
659                                        }
660                                    },
661                                }))
662                            }
663                            _ => {
664                                span_bug!(expr.span, "unexpected res: {:?}", res);
665                            }
666                        }
667                    }
668                },
669                _ => {
670                    span_bug!(expr.span, "unexpected type for struct literal: {:?}", expr_ty);
671                }
672            },
673
674            hir::ExprKind::Closure(hir::Closure { .. }) => {
675                let closure_ty = self.typeck_results.expr_ty(expr);
676                let (def_id, args, movability) = match *closure_ty.kind() {
677                    ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
678                    ty::Coroutine(def_id, args) => {
679                        (def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id)))
680                    }
681                    ty::CoroutineClosure(def_id, args) => {
682                        (def_id, UpvarArgs::CoroutineClosure(args), None)
683                    }
684                    _ => {
685                        span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
686                    }
687                };
688                let def_id = def_id.expect_local();
689
690                let upvars = self
691                    .tcx
692                    .closure_captures(def_id)
693                    .iter()
694                    .zip_eq(args.upvar_tys())
695                    .map(|(captured_place, ty)| {
696                        let upvars = self.capture_upvar(expr, captured_place, ty);
697                        self.thir.exprs.push(upvars)
698                    })
699                    .collect();
700
701                // Convert the closure fake reads, if any, from hir `Place` to ExprRef
702                let fake_reads = match self.typeck_results.closure_fake_reads.get(&def_id) {
703                    Some(fake_reads) => fake_reads
704                        .iter()
705                        .map(|(place, cause, hir_id)| {
706                            let expr = self.convert_captured_hir_place(expr, place.clone());
707                            (self.thir.exprs.push(expr), *cause, *hir_id)
708                        })
709                        .collect(),
710                    None => Vec::new(),
711                };
712
713                ExprKind::Closure(Box::new(ClosureExpr {
714                    closure_id: def_id,
715                    args,
716                    upvars,
717                    movability,
718                    fake_reads,
719                }))
720            }
721
722            hir::ExprKind::Path(ref qpath) => {
723                let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
724                self.convert_path_expr(expr, res)
725            }
726
727            hir::ExprKind::InlineAsm(asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr {
728                asm_macro: asm.asm_macro,
729                template: asm.template,
730                operands: asm
731                    .operands
732                    .iter()
733                    .map(|(op, _op_sp)| match *op {
734                        hir::InlineAsmOperand::In { reg, expr } => {
735                            InlineAsmOperand::In { reg, expr: self.mirror_expr(expr) }
736                        }
737                        hir::InlineAsmOperand::Out { reg, late, ref expr } => {
738                            InlineAsmOperand::Out {
739                                reg,
740                                late,
741                                expr: expr.map(|expr| self.mirror_expr(expr)),
742                            }
743                        }
744                        hir::InlineAsmOperand::InOut { reg, late, expr } => {
745                            InlineAsmOperand::InOut { reg, late, expr: self.mirror_expr(expr) }
746                        }
747                        hir::InlineAsmOperand::SplitInOut { reg, late, in_expr, ref out_expr } => {
748                            InlineAsmOperand::SplitInOut {
749                                reg,
750                                late,
751                                in_expr: self.mirror_expr(in_expr),
752                                out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
753                            }
754                        }
755                        hir::InlineAsmOperand::Const { ref anon_const } => {
756                            let ty = self.typeck_results.node_type(anon_const.hir_id);
757                            let did = anon_const.def_id;
758                            let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
759                            let parent_args = tcx.erase_and_anonymize_regions(
760                                GenericArgs::identity_for_item(tcx, typeck_root_def_id),
761                            );
762                            let args =
763                                InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty })
764                                    .args;
765
766                            let uneval = mir::UnevaluatedConst::new(did.to_def_id(), args);
767                            let value = mir::Const::Unevaluated(uneval, ty);
768                            InlineAsmOperand::Const { value, span: tcx.def_span(did) }
769                        }
770                        hir::InlineAsmOperand::SymFn { expr } => {
771                            InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
772                        }
773                        hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
774                            InlineAsmOperand::SymStatic { def_id }
775                        }
776                        hir::InlineAsmOperand::Label { block } => {
777                            InlineAsmOperand::Label { block: self.mirror_block(block) }
778                        }
779                    })
780                    .collect(),
781                options: asm.options,
782                line_spans: asm.line_spans,
783            })),
784
785            hir::ExprKind::OffsetOf(_, _) => {
786                let offset_of_intrinsic = tcx.require_lang_item(LangItem::OffsetOf, expr.span);
787                let mk_u32_kind = |val: u32| ExprKind::NonHirLiteral {
788                    lit: ScalarInt::try_from_uint(val, Size::from_bits(32)).unwrap(),
789                    user_ty: None,
790                };
791                let mk_usize_kind = |val: u64| ExprKind::NonHirLiteral {
792                    lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
793                    user_ty: None,
794                };
795                let mk_call =
796                    |thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx, field: FieldIdx| {
797                        let fun_ty =
798                            Ty::new_fn_def(tcx, offset_of_intrinsic, [ty::GenericArg::from(ty)]);
799                        let fun = thir
800                            .exprs
801                            .push(mk_expr(ExprKind::ZstLiteral { user_ty: None }, fun_ty));
802                        let variant =
803                            thir.exprs.push(mk_expr(mk_u32_kind(variant.as_u32()), tcx.types.u32));
804                        let field =
805                            thir.exprs.push(mk_expr(mk_u32_kind(field.as_u32()), tcx.types.u32));
806                        let args = Box::new([variant, field]);
807                        ExprKind::Call {
808                            ty: fun_ty,
809                            fun,
810                            args,
811                            from_hir_call: false,
812                            fn_span: expr.span,
813                        }
814                    };
815
816                let indices = self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
817                let mut expr = None::<ExprKind<'_>>;
818
819                for &(container, variant, field) in indices.iter() {
820                    let next = mk_call(&mut self.thir, container, variant, field);
821                    expr = Some(match expr.take() {
822                        None => next,
823                        Some(last) => {
824                            let last = self.thir.exprs.push(mk_expr(last, tcx.types.usize));
825                            let next = self.thir.exprs.push(mk_expr(next, tcx.types.usize));
826                            ExprKind::Binary { op: BinOp::Add, lhs: last, rhs: next }
827                        }
828                    });
829                }
830
831                expr.unwrap_or_else(|| mk_usize_kind(0))
832            }
833
834            hir::ExprKind::ConstBlock(ref anon_const) => {
835                let ty = self.typeck_results.node_type(anon_const.hir_id);
836                let did = anon_const.def_id;
837                let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
838                let parent_args = tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(
839                    tcx,
840                    typeck_root_def_id,
841                ));
842                let args = InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty }).args;
843
844                ExprKind::ConstBlock { did: did.to_def_id(), args }
845            }
846            // Now comes the rote stuff:
847            hir::ExprKind::Repeat(v, _) => {
848                let ty = self.typeck_results.expr_ty(expr);
849                let ty::Array(_, count) = ty.kind() else {
850                    span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty);
851                };
852
853                ExprKind::Repeat { value: self.mirror_expr(v), count: *count }
854            }
855            hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
856            hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) },
857            hir::ExprKind::Break(dest, ref value) => {
858                if find_attr!(self.tcx, expr.hir_id, ConstContinue(_)) {
859                    match dest.target_id {
860                        Ok(target_id) => {
861                            let (Some(value), Some(_)) = (value, dest.label) else {
862                                let span = expr.span;
863                                self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue { span })
864                            };
865
866                            ExprKind::ConstContinue {
867                                label: region::Scope {
868                                    local_id: target_id.local_id,
869                                    data: region::ScopeData::Node,
870                                },
871                                value: self.mirror_expr(value),
872                            }
873                        }
874                        Err(err) => bug!("invalid loop id for break: {}", err),
875                    }
876                } else {
877                    match dest.target_id {
878                        Ok(target_id) => ExprKind::Break {
879                            label: region::Scope {
880                                local_id: target_id.local_id,
881                                data: region::ScopeData::Node,
882                            },
883                            value: value.map(|value| self.mirror_expr(value)),
884                        },
885                        Err(err) => bug!("invalid loop id for break: {}", err),
886                    }
887                }
888            }
889            hir::ExprKind::Continue(dest) => match dest.target_id {
890                Ok(loop_id) => ExprKind::Continue {
891                    label: region::Scope {
892                        local_id: loop_id.local_id,
893                        data: region::ScopeData::Node,
894                    },
895                },
896                Err(err) => bug!("invalid loop id for continue: {}", err),
897            },
898            hir::ExprKind::Let(let_expr) => ExprKind::Let {
899                expr: self.mirror_expr(let_expr.init),
900                pat: self.pattern_from_hir(let_expr.pat),
901            },
902            hir::ExprKind::If(cond, then, else_opt) => ExprKind::If {
903                if_then_scope: region::Scope {
904                    local_id: then.hir_id.local_id,
905                    data: {
906                        if expr.span.at_least_rust_2024() {
907                            region::ScopeData::IfThenRescope
908                        } else {
909                            region::ScopeData::IfThen
910                        }
911                    },
912                },
913                cond: self.mirror_expr(cond),
914                then: self.mirror_expr(then),
915                else_opt: else_opt.map(|el| self.mirror_expr(el)),
916            },
917            hir::ExprKind::Match(discr, arms, match_source) => ExprKind::Match {
918                scrutinee: self.mirror_expr(discr),
919                arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
920                match_source,
921            },
922            hir::ExprKind::Loop(body, ..) => {
923                if find_attr!(self.tcx, expr.hir_id, LoopMatch(_)) {
924                    let dcx = self.tcx.dcx();
925
926                    // Accept either `state = expr` or `state = expr;`.
927                    let loop_body_expr = match body.stmts {
928                        [] => match body.expr {
929                            Some(expr) => expr,
930                            None => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
931                        },
932                        [single] if body.expr.is_none() => match single.kind {
933                            hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => expr,
934                            _ => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
935                        },
936                        [first @ last] | [first, .., last] => dcx
937                            .emit_fatal(LoopMatchBadStatements { span: first.span.to(last.span) }),
938                    };
939
940                    let hir::ExprKind::Assign(state, rhs_expr, _) = loop_body_expr.kind else {
941                        dcx.emit_fatal(LoopMatchMissingAssignment { span: loop_body_expr.span })
942                    };
943
944                    let hir::ExprKind::Block(block_body, _) = rhs_expr.kind else {
945                        dcx.emit_fatal(LoopMatchBadRhs { span: rhs_expr.span })
946                    };
947
948                    // The labeled block should contain one match expression, but defining items is
949                    // allowed.
950                    for stmt in block_body.stmts {
951                        if !matches!(stmt.kind, rustc_hir::StmtKind::Item(_)) {
952                            dcx.emit_fatal(LoopMatchBadStatements { span: stmt.span })
953                        }
954                    }
955
956                    let Some(block_body_expr) = block_body.expr else {
957                        dcx.emit_fatal(LoopMatchBadRhs { span: block_body.span })
958                    };
959
960                    let hir::ExprKind::Match(scrutinee, arms, _match_source) = block_body_expr.kind
961                    else {
962                        dcx.emit_fatal(LoopMatchBadRhs { span: block_body_expr.span })
963                    };
964
965                    fn local(
966                        cx: &mut ThirBuildCx<'_>,
967                        expr: &rustc_hir::Expr<'_>,
968                    ) -> Option<hir::HirId> {
969                        if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind
970                            && let Res::Local(hir_id) = path.res
971                            && !cx.is_upvar(hir_id)
972                        {
973                            return Some(hir_id);
974                        }
975
976                        None
977                    }
978
979                    let Some(scrutinee_hir_id) = local(self, scrutinee) else {
980                        dcx.emit_fatal(LoopMatchInvalidMatch { span: scrutinee.span })
981                    };
982
983                    if local(self, state) != Some(scrutinee_hir_id) {
984                        dcx.emit_fatal(LoopMatchInvalidUpdate {
985                            scrutinee: scrutinee.span,
986                            lhs: state.span,
987                        })
988                    }
989
990                    ExprKind::LoopMatch {
991                        state: self.mirror_expr(state),
992                        region_scope: region::Scope {
993                            local_id: block_body.hir_id.local_id,
994                            data: region::ScopeData::Node,
995                        },
996
997                        match_data: Box::new(LoopMatchMatchData {
998                            scrutinee: self.mirror_expr(scrutinee),
999                            arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
1000                            span: block_body_expr.span,
1001                        }),
1002                    }
1003                } else {
1004                    let block_ty = self.typeck_results.node_type(body.hir_id);
1005                    let block = self.mirror_block(body);
1006                    let body = self.thir.exprs.push(Expr {
1007                        ty: block_ty,
1008                        temp_scope_id: body.hir_id.local_id,
1009                        span: self.thir[block].span,
1010                        kind: ExprKind::Block { block },
1011                    });
1012                    ExprKind::Loop { body }
1013                }
1014            }
1015            hir::ExprKind::Field(source, ..) => ExprKind::Field {
1016                lhs: self.mirror_expr(source),
1017                variant_index: FIRST_VARIANT,
1018                name: self.typeck_results.field_index(expr.hir_id),
1019            },
1020            hir::ExprKind::Cast(source, cast_ty) => {
1021                // Check for a user-given type annotation on this `cast`
1022                let user_provided_types = self.typeck_results.user_provided_types();
1023                let user_ty = user_provided_types.get(cast_ty.hir_id);
1024
1025                debug!(
1026                    "cast({:?}) has ty w/ hir_id {:?} and user provided ty {:?}",
1027                    expr, cast_ty.hir_id, user_ty,
1028                );
1029
1030                let cast = self.mirror_expr_cast(source, expr.hir_id.local_id, expr.span);
1031
1032                if let Some(user_ty) = user_ty {
1033                    // NOTE: Creating a new Expr and wrapping a Cast inside of it may be
1034                    //       inefficient, revisit this when performance becomes an issue.
1035                    let cast_expr = self.thir.exprs.push(Expr {
1036                        temp_scope_id: expr.hir_id.local_id,
1037                        ty: expr_ty,
1038                        span: expr.span,
1039                        kind: cast,
1040                    });
1041                    debug!("make_mirror_unadjusted: (cast) user_ty={:?}", user_ty);
1042
1043                    ExprKind::ValueTypeAscription {
1044                        source: cast_expr,
1045                        user_ty: Some(Box::new(*user_ty)),
1046                        user_ty_span: cast_ty.span,
1047                    }
1048                } else {
1049                    cast
1050                }
1051            }
1052            hir::ExprKind::Type(source, ty) => {
1053                let user_provided_types = self.typeck_results.user_provided_types();
1054                let user_ty = user_provided_types.get(ty.hir_id).copied().map(Box::new);
1055                debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
1056                let mirrored = self.mirror_expr(source);
1057                if source.is_syntactic_place_expr() {
1058                    ExprKind::PlaceTypeAscription {
1059                        source: mirrored,
1060                        user_ty,
1061                        user_ty_span: ty.span,
1062                    }
1063                } else {
1064                    ExprKind::ValueTypeAscription {
1065                        source: mirrored,
1066                        user_ty,
1067                        user_ty_span: ty.span,
1068                    }
1069                }
1070            }
1071
1072            hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Unwrap, source, _ty) => {
1073                // FIXME(unsafe_binders): Take into account the ascribed type, too.
1074                let mirrored = self.mirror_expr(source);
1075                if source.is_syntactic_place_expr() {
1076                    ExprKind::PlaceUnwrapUnsafeBinder { source: mirrored }
1077                } else {
1078                    ExprKind::ValueUnwrapUnsafeBinder { source: mirrored }
1079                }
1080            }
1081            hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Wrap, source, _ty) => {
1082                // FIXME(unsafe_binders): Take into account the ascribed type, too.
1083                let mirrored = self.mirror_expr(source);
1084                ExprKind::WrapUnsafeBinder { source: mirrored }
1085            }
1086
1087            hir::ExprKind::DropTemps(source) => ExprKind::Use { source: self.mirror_expr(source) },
1088            hir::ExprKind::Array(fields) => ExprKind::Array { fields: self.mirror_exprs(fields) },
1089            hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
1090
1091            hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
1092            hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"),
1093        };
1094
1095        mk_expr(kind, expr_ty)
1096    }
1097
1098    fn user_args_applied_to_res(
1099        &mut self,
1100        hir_id: hir::HirId,
1101        res: Res,
1102    ) -> Option<Box<ty::CanonicalUserType<'tcx>>> {
1103        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/thir/cx/expr.rs:1103",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1103u32),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: res={0:?}",
                                                    res) as &dyn Value))])
            });
    } else { ; }
};debug!("user_args_applied_to_res: res={:?}", res);
1104        let user_provided_type = match res {
1105            // A reference to something callable -- e.g., a fn, method, or
1106            // a tuple-struct or tuple-variant. This has the type of a
1107            // `Fn` but with the user-given generic parameters.
1108            Res::Def(DefKind::Fn, _)
1109            | Res::Def(DefKind::AssocFn, _)
1110            | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1111            | Res::Def(DefKind::Const { .. }, _)
1112            | Res::Def(DefKind::AssocConst { .. }, _) => {
1113                self.typeck_results.user_provided_types().get(hir_id).copied().map(Box::new)
1114            }
1115
1116            // A unit struct/variant which is used as a value (e.g.,
1117            // `None`). This has the type of the enum/struct that defines
1118            // this variant -- but with the generic parameters given by the
1119            // user.
1120            Res::Def(DefKind::Ctor(_, CtorKind::Const), _) => {
1121                self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new)
1122            }
1123
1124            // `Self` is used in expression as a tuple struct constructor or a unit struct constructor
1125            Res::SelfCtor(_) => self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new),
1126
1127            _ => ::rustc_middle::util::bug::bug_fmt(format_args!("user_args_applied_to_res: unexpected res {0:?} at {1:?}",
        res, hir_id))bug!("user_args_applied_to_res: unexpected res {:?} at {:?}", res, hir_id),
1128        };
1129        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/thir/cx/expr.rs:1129",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1129u32),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: user_provided_type={0:?}",
                                                    user_provided_type) as &dyn Value))])
            });
    } else { ; }
};debug!("user_args_applied_to_res: user_provided_type={:?}", user_provided_type);
1130        user_provided_type
1131    }
1132
1133    fn method_callee(
1134        &mut self,
1135        expr: &hir::Expr<'_>,
1136        span: Span,
1137        overloaded_callee: Option<Ty<'tcx>>,
1138    ) -> Expr<'tcx> {
1139        let (ty, user_ty) = match overloaded_callee {
1140            Some(fn_def) => (fn_def, None),
1141            None => {
1142                let (kind, def_id) =
1143                    self.typeck_results.type_dependent_def(expr.hir_id).unwrap_or_else(|| {
1144                        ::rustc_middle::util::bug::span_bug_fmt(expr.span,
    format_args!("no type-dependent def for method callee"))span_bug!(expr.span, "no type-dependent def for method callee")
1145                    });
1146                let user_ty = self.user_args_applied_to_res(expr.hir_id, Res::Def(kind, def_id));
1147                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/thir/cx/expr.rs:1147",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1147u32),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("method_callee: user_ty={0:?}",
                                                    user_ty) as &dyn Value))])
            });
    } else { ; }
};debug!("method_callee: user_ty={:?}", user_ty);
1148                (
1149                    Ty::new_fn_def(self.tcx, def_id, self.typeck_results.node_args(expr.hir_id)),
1150                    user_ty,
1151                )
1152            }
1153        };
1154        Expr {
1155            temp_scope_id: expr.hir_id.local_id,
1156            ty,
1157            span,
1158            kind: ExprKind::ZstLiteral { user_ty },
1159        }
1160    }
1161
1162    fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
1163        let arm = Arm {
1164            pattern: self.pattern_from_hir(&arm.pat),
1165            guard: arm.guard.as_ref().map(|g| self.mirror_expr(g)),
1166            body: self.mirror_expr(arm.body),
1167            hir_id: arm.hir_id,
1168            scope: region::Scope { local_id: arm.hir_id.local_id, data: region::ScopeData::Node },
1169            span: arm.span,
1170        };
1171        self.thir.arms.push(arm)
1172    }
1173
1174    fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKind<'tcx> {
1175        let args = self.typeck_results.node_args(expr.hir_id);
1176        match res {
1177            // A regular function, constructor function or a constant.
1178            Res::Def(DefKind::Fn, _)
1179            | Res::Def(DefKind::AssocFn, _)
1180            | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1181            | Res::SelfCtor(_) => {
1182                let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1183                ExprKind::ZstLiteral { user_ty }
1184            }
1185
1186            Res::Def(DefKind::ConstParam, def_id) => {
1187                let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
1188                let generics = self.tcx.generics_of(hir_id.owner);
1189                let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
1190                    ::rustc_middle::util::bug::span_bug_fmt(expr.span,
    format_args!("Should have already errored about late bound consts: {0:?}",
        def_id));span_bug!(
1191                        expr.span,
1192                        "Should have already errored about late bound consts: {def_id:?}"
1193                    );
1194                };
1195                let name = self.tcx.hir_name(hir_id);
1196                let param = ty::ParamConst::new(index, name);
1197
1198                ExprKind::ConstParam { param, def_id }
1199            }
1200
1201            Res::Def(DefKind::Const { .. }, def_id)
1202            | Res::Def(DefKind::AssocConst { .. }, def_id) => {
1203                let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1204                ExprKind::NamedConst { def_id, args, user_ty }
1205            }
1206
1207            Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
1208                let user_provided_types = self.typeck_results.user_provided_types();
1209                let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
1210                {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/thir/cx/expr.rs:1210",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1210u32),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("convert_path_expr: user_ty={0:?}",
                                                    user_ty) as &dyn Value))])
            });
    } else { ; }
};debug!("convert_path_expr: user_ty={:?}", user_ty);
1211                let ty = self.typeck_results.node_type(expr.hir_id);
1212                match ty.kind() {
1213                    // A unit struct/variant which is used as a value.
1214                    // We return a completely different ExprKind here to account for this special case.
1215                    ty::Adt(adt_def, args) => ExprKind::Adt(Box::new(AdtExpr {
1216                        adt_def: *adt_def,
1217                        variant_index: adt_def.variant_index_with_ctor_id(def_id),
1218                        args,
1219                        user_ty,
1220                        fields: Box::new([]),
1221                        base: AdtExprBase::None,
1222                    })),
1223                    _ => ::rustc_middle::util::bug::bug_fmt(format_args!("unexpected ty: {0:?}", ty))bug!("unexpected ty: {:?}", ty),
1224                }
1225            }
1226
1227            // A source Rust `path::to::STATIC` is a place expr like *&ident is.
1228            // In THIR, we make them exactly equivalent by inserting the implied *& or *&raw,
1229            // but distinguish between &STATIC and &THREAD_LOCAL as they have different semantics
1230            Res::Def(DefKind::Static { .. }, id) => {
1231                // this is &raw for extern static or static mut, and & for other statics
1232                let ty = self.tcx.static_ptr_ty(id, self.typing_env);
1233                let kind = if self.tcx.is_thread_local_static(id) {
1234                    ExprKind::ThreadLocalRef(id)
1235                } else {
1236                    let alloc_id = self.tcx.reserve_and_set_static_alloc(id);
1237                    ExprKind::StaticRef { alloc_id, ty, def_id: id }
1238                };
1239                ExprKind::Deref {
1240                    arg: self.thir.exprs.push(Expr {
1241                        ty,
1242                        temp_scope_id: expr.hir_id.local_id,
1243                        span: expr.span,
1244                        kind,
1245                    }),
1246                }
1247            }
1248
1249            Res::Local(var_hir_id) => self.convert_var(var_hir_id),
1250
1251            _ => ::rustc_middle::util::bug::span_bug_fmt(expr.span,
    format_args!("res `{0:?}` not yet implemented", res))span_bug!(expr.span, "res `{:?}` not yet implemented", res),
1252        }
1253    }
1254
1255    fn convert_var(&mut self, var_hir_id: hir::HirId) -> ExprKind<'tcx> {
1256        // We want upvars here not captures.
1257        // Captures will be handled in MIR.
1258        let is_upvar = self.is_upvar(var_hir_id);
1259
1260        {
    use ::tracing::__macro_support::Callsite as _;
    static __CALLSITE: ::tracing::callsite::DefaultCallsite =
        {
            static META: ::tracing::Metadata<'static> =
                {
                    ::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/thir/cx/expr.rs:1260",
                        "rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
                        ::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/thir/cx/expr.rs"),
                        ::tracing_core::__macro_support::Option::Some(1260u32),
                        ::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};
                let mut iter = __CALLSITE.metadata().fields().iter();
                __CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
                                    ::tracing::__macro_support::Option::Some(&format_args!("convert_var({0:?}): is_upvar={1}, body_owner={2:?}",
                                                    var_hir_id, is_upvar, self.body_owner) as &dyn Value))])
            });
    } else { ; }
};debug!(
1261            "convert_var({:?}): is_upvar={}, body_owner={:?}",
1262            var_hir_id, is_upvar, self.body_owner
1263        );
1264
1265        if is_upvar {
1266            ExprKind::UpvarRef {
1267                closure_def_id: self.body_owner,
1268                var_hir_id: LocalVarId(var_hir_id),
1269            }
1270        } else {
1271            ExprKind::VarRef { id: LocalVarId(var_hir_id) }
1272        }
1273    }
1274
1275    fn overloaded_operator(
1276        &mut self,
1277        expr: &'tcx hir::Expr<'tcx>,
1278        args: Box<[ExprId]>,
1279    ) -> ExprKind<'tcx> {
1280        let fun = self.method_callee(expr, expr.span, None);
1281        let fun = self.thir.exprs.push(fun);
1282        ExprKind::Call {
1283            ty: self.thir[fun].ty,
1284            fun,
1285            args,
1286            from_hir_call: false,
1287            fn_span: expr.span,
1288        }
1289    }
1290
1291    fn overloaded_place(
1292        &mut self,
1293        expr: &'tcx hir::Expr<'tcx>,
1294        place_ty: Ty<'tcx>,
1295        overloaded_callee: Option<Ty<'tcx>>,
1296        args: Box<[ExprId]>,
1297        span: Span,
1298    ) -> ExprKind<'tcx> {
1299        // For an overloaded *x or x[y] expression of type T, the method
1300        // call returns an &T and we must add the deref so that the types
1301        // line up (this is because `*x` and `x[y]` represent places):
1302
1303        // Reconstruct the output assuming it's a reference with the
1304        // same region and mutability as the receiver. This holds for
1305        // `Deref(Mut)::deref(_mut)` and `Index(Mut)::index(_mut)`.
1306        let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else {
1307            ::rustc_middle::util::bug::span_bug_fmt(span,
    format_args!("overloaded_place: receiver is not a reference"));span_bug!(span, "overloaded_place: receiver is not a reference");
1308        };
1309        let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl);
1310
1311        // construct the complete expression `foo()` for the overloaded call,
1312        // which will yield the &T type
1313        let fun = self.method_callee(expr, span, overloaded_callee);
1314        let fun = self.thir.exprs.push(fun);
1315        let fun_ty = self.thir[fun].ty;
1316        let ref_expr = self.thir.exprs.push(Expr {
1317            temp_scope_id: expr.hir_id.local_id,
1318            ty: ref_ty,
1319            span,
1320            kind: ExprKind::Call { ty: fun_ty, fun, args, from_hir_call: false, fn_span: span },
1321        });
1322
1323        // construct and return a deref wrapper `*foo()`
1324        ExprKind::Deref { arg: ref_expr }
1325    }
1326
1327    fn convert_captured_hir_place(
1328        &mut self,
1329        closure_expr: &'tcx hir::Expr<'tcx>,
1330        place: HirPlace<'tcx>,
1331    ) -> Expr<'tcx> {
1332        let temp_scope_id = closure_expr.hir_id.local_id;
1333        let var_ty = place.base_ty;
1334
1335        // The result of capture analysis in `rustc_hir_typeck/src/upvar.rs` represents a captured path
1336        // as it's seen for use within the closure and not at the time of closure creation.
1337        //
1338        // That is we see expect to see it start from a captured upvar and not something that is local
1339        // to the closure's parent.
1340        let var_hir_id = match place.base {
1341            HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
1342            base => ::rustc_middle::util::bug::bug_fmt(format_args!("Expected an upvar, found {0:?}",
        base))bug!("Expected an upvar, found {:?}", base),
1343        };
1344
1345        let mut captured_place_expr = Expr {
1346            temp_scope_id,
1347            ty: var_ty,
1348            span: closure_expr.span,
1349            kind: self.convert_var(var_hir_id),
1350        };
1351
1352        for proj in place.projections.iter() {
1353            let kind = match proj.kind {
1354                HirProjectionKind::Deref => {
1355                    ExprKind::Deref { arg: self.thir.exprs.push(captured_place_expr) }
1356                }
1357                HirProjectionKind::Field(field, variant_index) => ExprKind::Field {
1358                    lhs: self.thir.exprs.push(captured_place_expr),
1359                    variant_index,
1360                    name: field,
1361                },
1362                HirProjectionKind::OpaqueCast => {
1363                    ExprKind::Use { source: self.thir.exprs.push(captured_place_expr) }
1364                }
1365                HirProjectionKind::UnwrapUnsafeBinder => ExprKind::PlaceUnwrapUnsafeBinder {
1366                    source: self.thir.exprs.push(captured_place_expr),
1367                },
1368                HirProjectionKind::Index | HirProjectionKind::Subslice => {
1369                    // We don't capture these projections, so we can ignore them here
1370                    continue;
1371                }
1372            };
1373
1374            captured_place_expr =
1375                Expr { temp_scope_id, ty: proj.ty, span: closure_expr.span, kind };
1376        }
1377
1378        captured_place_expr
1379    }
1380
1381    fn capture_upvar(
1382        &mut self,
1383        closure_expr: &'tcx hir::Expr<'tcx>,
1384        captured_place: &'tcx ty::CapturedPlace<'tcx>,
1385        upvar_ty: Ty<'tcx>,
1386    ) -> Expr<'tcx> {
1387        let upvar_capture = captured_place.info.capture_kind;
1388        let captured_place_expr =
1389            self.convert_captured_hir_place(closure_expr, captured_place.place.clone());
1390        let temp_scope_id = closure_expr.hir_id.local_id;
1391
1392        match upvar_capture {
1393            ty::UpvarCapture::ByValue => captured_place_expr,
1394            ty::UpvarCapture::ByUse => {
1395                let span = captured_place_expr.span;
1396                let expr_id = self.thir.exprs.push(captured_place_expr);
1397
1398                Expr {
1399                    temp_scope_id,
1400                    ty: upvar_ty,
1401                    span: closure_expr.span,
1402                    kind: ExprKind::ByUse { expr: expr_id, span },
1403                }
1404            }
1405            ty::UpvarCapture::ByRef(upvar_borrow) => {
1406                let borrow_kind = match upvar_borrow {
1407                    ty::BorrowKind::Immutable => BorrowKind::Shared,
1408                    ty::BorrowKind::UniqueImmutable => {
1409                        BorrowKind::Mut { kind: mir::MutBorrowKind::ClosureCapture }
1410                    }
1411                    ty::BorrowKind::Mutable => {
1412                        BorrowKind::Mut { kind: mir::MutBorrowKind::Default }
1413                    }
1414                };
1415                Expr {
1416                    temp_scope_id,
1417                    ty: upvar_ty,
1418                    span: closure_expr.span,
1419                    kind: ExprKind::Borrow {
1420                        borrow_kind,
1421                        arg: self.thir.exprs.push(captured_place_expr),
1422                    },
1423                }
1424            }
1425        }
1426    }
1427
1428    fn is_upvar(&mut self, var_hir_id: hir::HirId) -> bool {
1429        self.tcx
1430            .upvars_mentioned(self.body_owner)
1431            .is_some_and(|upvars| upvars.contains_key(&var_hir_id))
1432    }
1433
1434    /// Converts a list of named fields (i.e., for struct-like struct/enum ADTs) into FieldExpr.
1435    fn field_refs(&mut self, fields: &'tcx [hir::ExprField<'tcx>]) -> Box<[FieldExpr]> {
1436        fields
1437            .iter()
1438            .map(|field| FieldExpr {
1439                name: self.typeck_results.field_index(field.hir_id),
1440                expr: self.mirror_expr(field.expr),
1441            })
1442            .collect()
1443    }
1444}
1445
1446trait ToBorrowKind {
1447    fn to_borrow_kind(&self) -> BorrowKind;
1448}
1449
1450impl ToBorrowKind for AutoBorrowMutability {
1451    fn to_borrow_kind(&self) -> BorrowKind {
1452        use rustc_middle::ty::adjustment::AllowTwoPhase;
1453        match *self {
1454            AutoBorrowMutability::Mut { allow_two_phase_borrow } => BorrowKind::Mut {
1455                kind: match allow_two_phase_borrow {
1456                    AllowTwoPhase::Yes => mir::MutBorrowKind::TwoPhaseBorrow,
1457                    AllowTwoPhase::No => mir::MutBorrowKind::Default,
1458                },
1459            },
1460            AutoBorrowMutability::Not => BorrowKind::Shared,
1461        }
1462    }
1463}
1464
1465impl ToBorrowKind for hir::Mutability {
1466    fn to_borrow_kind(&self) -> BorrowKind {
1467        match *self {
1468            hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
1469            hir::Mutability::Not => BorrowKind::Shared,
1470        }
1471    }
1472}
1473
1474fn bin_op(op: hir::BinOpKind) -> BinOp {
1475    match op {
1476        hir::BinOpKind::Add => BinOp::Add,
1477        hir::BinOpKind::Sub => BinOp::Sub,
1478        hir::BinOpKind::Mul => BinOp::Mul,
1479        hir::BinOpKind::Div => BinOp::Div,
1480        hir::BinOpKind::Rem => BinOp::Rem,
1481        hir::BinOpKind::BitXor => BinOp::BitXor,
1482        hir::BinOpKind::BitAnd => BinOp::BitAnd,
1483        hir::BinOpKind::BitOr => BinOp::BitOr,
1484        hir::BinOpKind::Shl => BinOp::Shl,
1485        hir::BinOpKind::Shr => BinOp::Shr,
1486        hir::BinOpKind::Eq => BinOp::Eq,
1487        hir::BinOpKind::Lt => BinOp::Lt,
1488        hir::BinOpKind::Le => BinOp::Le,
1489        hir::BinOpKind::Ne => BinOp::Ne,
1490        hir::BinOpKind::Ge => BinOp::Ge,
1491        hir::BinOpKind::Gt => BinOp::Gt,
1492        _ => ::rustc_middle::util::bug::bug_fmt(format_args!("no equivalent for ast binop {0:?}",
        op))bug!("no equivalent for ast binop {:?}", op),
1493    }
1494}
1495
1496fn assign_op(op: hir::AssignOpKind) -> AssignOp {
1497    match op {
1498        hir::AssignOpKind::AddAssign => AssignOp::AddAssign,
1499        hir::AssignOpKind::SubAssign => AssignOp::SubAssign,
1500        hir::AssignOpKind::MulAssign => AssignOp::MulAssign,
1501        hir::AssignOpKind::DivAssign => AssignOp::DivAssign,
1502        hir::AssignOpKind::RemAssign => AssignOp::RemAssign,
1503        hir::AssignOpKind::BitXorAssign => AssignOp::BitXorAssign,
1504        hir::AssignOpKind::BitAndAssign => AssignOp::BitAndAssign,
1505        hir::AssignOpKind::BitOrAssign => AssignOp::BitOrAssign,
1506        hir::AssignOpKind::ShlAssign => AssignOp::ShlAssign,
1507        hir::AssignOpKind::ShrAssign => AssignOp::ShrAssign,
1508    }
1509}