1use itertools::Itertools;
2use rustc_abi::{FIRST_VARIANT, FieldIdx, Size, VariantIdx};
3use rustc_ast::UnsafeBinderCastKind;
4use rustc_data_structures::thin_vec::ThinVec;
5use rustc_hir as hir;
6use rustc_hir::attrs::lang_items::LangItem;
7use rustc_hir::attrs::{AttributeKind, HasAttrs};
8use rustc_hir::def::{CtorKind, CtorOf, DefKind, Res};
9use rustc_hir::{HirId, find_attr};
10use rustc_index::Idx;
11use rustc_middle::hir::place::{
12 Place as HirPlace, PlaceBase as HirPlaceBase, ProjectionKind as HirProjectionKind,
13};
14use rustc_middle::middle::region;
15use rustc_middle::mir::{self, AssignOp, BinOp, BorrowKind, UnOp};
16use rustc_middle::thir::*;
17use rustc_middle::ty::adjustment::{
18 Adjust, Adjustment, AutoBorrow, AutoBorrowMutability, DerefAdjustKind, PointerCoercion,
19};
20use rustc_middle::ty::{
21 self, AdtKind, GenericArgs, InlineConstArgs, InlineConstArgsParts, ScalarInt, SplattedDef, Ty,
22 TyCtxt, UpvarArgs,
23};
24use rustc_span::{DesugaringKind, Span, bug, span_bug};
25use tracing::{debug, info, instrument, trace};
26
27use crate::diagnostics::*;
28use crate::thir::cx::ThirBuildCx;
29
30#[derive(#[automatically_derived]
impl<'tcx> ::core::marker::Copy for SplattedFunc<'tcx> { }Copy, #[automatically_derived]
#[doc(hidden)]
unsafe impl<'tcx> ::core::clone::TrivialClone for SplattedFunc<'tcx> { }
#[automatically_derived]
impl<'tcx> ::core::clone::Clone for SplattedFunc<'tcx> {
#[inline]
fn clone(&self) -> SplattedFunc<'tcx> {
let _: ::core::clone::AssertParamIsClone<&'tcx hir::Expr<'tcx>>;
let _: ::core::clone::AssertParamIsClone<&'tcx hir::Expr<'tcx>>;
*self
}
}Clone, #[automatically_derived]
impl<'tcx> ::core::fmt::Debug for SplattedFunc<'tcx> {
#[inline]
fn fmt(&self, f: &mut ::core::fmt::Formatter) -> ::core::fmt::Result {
match self {
SplattedFunc::FnDefReceiver(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FnDefReceiver", &__self_0),
SplattedFunc::FnExpression(__self_0) =>
::core::fmt::Formatter::debug_tuple_field1_finish(f,
"FnExpression", &__self_0),
}
}
}Debug)]
32enum SplattedFunc<'tcx> {
33 FnDefReceiver(&'tcx hir::Expr<'tcx>),
35 FnExpression(&'tcx hir::Expr<'tcx>),
38}
39
40impl<'tcx> SplattedFunc<'tcx> {
41 fn has_receiver(&self) -> bool {
42 #[allow(non_exhaustive_omitted_patterns)] match self {
SplattedFunc::FnDefReceiver(_) => true,
_ => false,
}matches!(self, SplattedFunc::FnDefReceiver(_))
43 }
44
45 fn receiver(&self) -> Option<&'tcx hir::Expr<'tcx>> {
46 match self {
47 SplattedFunc::FnDefReceiver(receiver) => Some(receiver),
48 SplattedFunc::FnExpression(_fn_expression) => None,
49 }
50 }
51
52 fn fn_expression(&self) -> Option<&'tcx hir::Expr<'tcx>> {
53 match self {
54 SplattedFunc::FnDefReceiver(_receiver) => None,
55 SplattedFunc::FnExpression(fn_expression) => Some(fn_expression),
56 }
57 }
58}
59
60fn parsed_attrs(id: HirId, tcx: TyCtxt<'_>) -> ThinVec<AttributeKind> {
61 HasAttrs::get_attrs(id, &tcx)
62 .into_iter()
63 .filter_map(|attr| match attr {
64 hir::Attribute::Parsed(attrkind) => Some(attrkind.clone()),
65 hir::Attribute::Unparsed(_) => None,
66 })
67 .collect()
68}
69
70impl<'tcx> ThirBuildCx<'tcx> {
71 pub(crate) fn mirror_exprs(&mut self, exprs: &'tcx [hir::Expr<'tcx>]) -> Box<[ExprId]> {
72 exprs.iter().map(|expr| self.mirror_expr(expr)).collect()
73 }
74
75 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("mirror_expr",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(83u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{ meta.fields().value_set_all(&[]) })
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: ExprId = loop {};
return __tracing_attr_fake_return;
}
{
let expr_scope =
region::Scope {
local_id: hir_expr.hir_id.local_id,
data: region::ScopeData::Node,
};
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:88",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(88u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_expr.hir_id")
}> =
::tracing::__macro_support::FieldName::new("hir_expr.hir_id");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_expr.span")
}> =
::tracing::__macro_support::FieldName::new("hir_expr.span");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr.hir_id)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr.span)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut expr = self.make_mirror_unadjusted(hir_expr);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:92",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(92u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr.ty")
}> =
::tracing::__macro_support::FieldName::new("expr.ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr.ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mut attrs = ThinVec::new();
if let hir::ExprKind::Loop(_, _, _, span) = hir_expr.kind {
match span.desugaring_kind() {
Some(DesugaringKind::ForLoop) => {
let arm =
self.tcx.parent_hir_node(hir_expr.hir_id).expect_arm();
let expr =
self.tcx.parent_hir_node(arm.hir_id).expect_expr();
{
match expr.kind {
hir::ExprKind::Match(..) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"hir::ExprKind::Match(..)", ::core::option::Option::None);
}
}
};
if let hir::Node::Expr(expr) =
self.tcx.parent_hir_node(expr.hir_id) {
{
match expr.kind {
hir::ExprKind::DropTemps(..) => {}
ref left_val => {
::core::panicking::assert_matches_failed(left_val,
"hir::ExprKind::DropTemps(..)",
::core::option::Option::None);
}
}
};
attrs = parsed_attrs(expr.hir_id, self.tcx)
}
}
Some(DesugaringKind::WhileLoop) | None => {
attrs = parsed_attrs(hir_expr.hir_id, self.tcx);
}
_ => (),
}
}
if self.apply_adjustments {
for adjustment in
self.typeck_results.expr_adjustments(hir_expr) {
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:120",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(120u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("adjustment")
}> =
::tracing::__macro_support::FieldName::new("adjustment");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adjustment)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let span = expr.span;
expr =
self.apply_adjustment(hir_expr, expr, adjustment, span);
}
}
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:126",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(126u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message",
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr.ty")
}> =
::tracing::__macro_support::FieldName::new("expr.ty");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("after adjustments")
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr.ty)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let ty = expr.ty;
let value = self.thir.exprs.push(expr);
if !attrs.is_empty() {
self.thir.attributes.insert(value, attrs);
}
expr =
Expr {
temp_scope_id: expr_scope.local_id,
ty,
span: hir_expr.span,
kind: ExprKind::Scope {
region_scope: expr_scope,
value,
hir_id: hir_expr.hir_id,
},
};
self.thir.exprs.push(expr)
}
}
}#[instrument(level = "trace", skip(self, hir_expr))]
84 pub(crate) fn mirror_expr(&mut self, hir_expr: &'tcx hir::Expr<'tcx>) -> ExprId {
85 let expr_scope =
86 region::Scope { local_id: hir_expr.hir_id.local_id, data: region::ScopeData::Node };
87
88 trace!(?hir_expr.hir_id, ?hir_expr.span);
89
90 let mut expr = self.make_mirror_unadjusted(hir_expr);
91
92 trace!(?expr.ty);
93
94 let mut attrs = ThinVec::new();
95
96 if let hir::ExprKind::Loop(_, _, _, span) = hir_expr.kind {
97 match span.desugaring_kind() {
98 Some(DesugaringKind::ForLoop) => {
100 let arm = self.tcx.parent_hir_node(hir_expr.hir_id).expect_arm();
101 let expr = self.tcx.parent_hir_node(arm.hir_id).expect_expr();
102 std::assert_matches!(expr.kind, hir::ExprKind::Match(..));
103 if let hir::Node::Expr(expr) = self.tcx.parent_hir_node(expr.hir_id) {
105 std::assert_matches!(expr.kind, hir::ExprKind::DropTemps(..));
106 attrs = parsed_attrs(expr.hir_id, self.tcx)
107 }
108 }
109 Some(DesugaringKind::WhileLoop) | None => {
111 attrs = parsed_attrs(hir_expr.hir_id, self.tcx);
112 }
113 _ => (),
114 }
115 }
116
117 if self.apply_adjustments {
119 for adjustment in self.typeck_results.expr_adjustments(hir_expr) {
120 trace!(?expr, ?adjustment);
121 let span = expr.span;
122 expr = self.apply_adjustment(hir_expr, expr, adjustment, span);
123 }
124 }
125
126 trace!(?expr.ty, "after adjustments");
127
128 let ty = expr.ty;
129 let value = self.thir.exprs.push(expr);
130
131 if !attrs.is_empty() {
132 self.thir.attributes.insert(value, attrs);
133 }
134
135 expr = Expr {
140 temp_scope_id: expr_scope.local_id,
141 ty,
142 span: hir_expr.span,
143 kind: ExprKind::Scope { region_scope: expr_scope, value, hir_id: hir_expr.hir_id },
144 };
145
146 self.thir.exprs.push(expr)
148 }
149
150 {}
#[allow(clippy :: suspicious_else_formatting)]
{
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::TRACE <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() ||
{ false } {
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("apply_adjustment",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::TRACE,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(150u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("hir_expr")
}> =
::tracing::__macro_support::FieldName::new("hir_expr");
NAME.as_str()
},
{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("adjustment")
}> =
::tracing::__macro_support::FieldName::new("adjustment");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::TRACE <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::TRACE <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&hir_expr)
as &dyn ::tracing::field::Value)),
(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&adjustment)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Expr<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let Expr { temp_scope_id, .. } = expr;
let mut adjust_span =
|expr: &mut Expr<'tcx>|
{
if let ExprKind::Block { block } = expr.kind &&
let Some(last_expr) = self.thir[block].expr {
span = self.thir[last_expr].span;
expr.span = span;
}
};
let kind =
match adjustment.kind {
Adjust::Pointer(cast) => {
if cast == PointerCoercion::Unsize {
adjust_span(&mut expr);
}
let is_from_as_cast =
if let hir::Node::Expr(hir::Expr {
kind: hir::ExprKind::Cast(..), span: cast_span, .. }) =
self.tcx.parent_hir_node(hir_expr.hir_id) {
span = *cast_span;
true
} else { false };
ExprKind::PointerCoercion {
cast,
source: self.thir.exprs.push(expr),
is_from_as_cast,
}
}
Adjust::NeverToAny if adjustment.target.is_never() =>
return expr,
Adjust::NeverToAny =>
ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
Adjust::Deref(DerefAdjustKind::Builtin) => {
adjust_span(&mut expr);
ExprKind::Deref { arg: self.thir.exprs.push(expr) }
}
Adjust::Deref(DerefAdjustKind::Pin) => {
adjust_span(&mut expr);
let pin_ty =
expr.ty.pinned_ty().expect("Deref(Pin) with non-Pin type");
let pointer_target =
ExprKind::Field {
lhs: self.thir.exprs.push(expr),
variant_index: FIRST_VARIANT,
name: FieldIdx::ZERO,
};
let expr =
Expr {
temp_scope_id,
ty: pin_ty,
span,
kind: pointer_target,
};
ExprKind::Deref { arg: self.thir.exprs.push(expr) }
}
Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
let call_def_id = deref.method_call(self.tcx);
let overloaded_callee =
self.tcx.type_of(call_def_id).instantiate(self.tcx,
self.tcx.mk_args(&[expr.ty.into()])).skip_norm_wip();
expr =
Expr {
temp_scope_id,
ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased,
expr.ty, deref.mutbl),
span,
kind: ExprKind::Borrow {
borrow_kind: deref.mutbl.to_borrow_kind(),
arg: self.thir.exprs.push(expr),
},
};
let expr = Box::new([self.thir.exprs.push(expr)]);
self.overloaded_place(hir_expr, adjustment.target,
Some(overloaded_callee), expr, deref.span)
}
Adjust::Borrow(AutoBorrow::Ref(m)) =>
ExprKind::Borrow {
borrow_kind: m.to_borrow_kind(),
arg: self.thir.exprs.push(expr),
},
Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
ExprKind::RawBorrow {
mutability,
arg: self.thir.exprs.push(expr),
}
}
Adjust::Borrow(AutoBorrow::Pin(mutbl)) => {
let borrow_kind =
match mutbl {
hir::Mutability::Mut =>
BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
hir::Mutability::Not => BorrowKind::Shared,
};
let new_pin_target =
Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty,
mutbl);
let arg = self.thir.exprs.push(expr);
let expr =
self.thir.exprs.push(Expr {
temp_scope_id,
ty: new_pin_target,
span,
kind: ExprKind::Borrow { borrow_kind, arg },
});
let pin_did =
self.tcx.require_lang_item(LangItem::Pin, span);
let args = self.tcx.mk_args(&[new_pin_target.into()]);
let kind =
ExprKind::Adt(Box::new(AdtExpr {
adt_def: self.tcx.adt_def(pin_did),
variant_index: FIRST_VARIANT,
args,
fields: Box::new([FieldExpr {
name: FieldIdx::ZERO,
expr,
}]),
user_ty: None,
base: AdtExprBase::None,
}));
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:287",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(287u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("kind")
}> =
::tracing::__macro_support::FieldName::new("kind");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&kind)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
kind
}
Adjust::GenericReborrow(mutability) => {
let expr = self.thir.exprs.push(expr);
let kind =
ExprKind::Reborrow {
source: expr,
mutability,
target: adjustment.target,
};
kind
}
};
Expr { temp_scope_id, ty: adjustment.target, span, kind }
}
}
}#[instrument(level = "trace", skip(self, expr, span))]
151 fn apply_adjustment(
152 &mut self,
153 hir_expr: &'tcx hir::Expr<'tcx>,
154 mut expr: Expr<'tcx>,
155 adjustment: &Adjustment<'tcx>,
156 mut span: Span,
157 ) -> Expr<'tcx> {
158 let Expr { temp_scope_id, .. } = expr;
159
160 let mut adjust_span = |expr: &mut Expr<'tcx>| {
171 if let ExprKind::Block { block } = expr.kind
172 && let Some(last_expr) = self.thir[block].expr
173 {
174 span = self.thir[last_expr].span;
175 expr.span = span;
176 }
177 };
178
179 let kind = match adjustment.kind {
180 Adjust::Pointer(cast) => {
181 if cast == PointerCoercion::Unsize {
182 adjust_span(&mut expr);
183 }
184
185 let is_from_as_cast = if let hir::Node::Expr(hir::Expr {
186 kind: hir::ExprKind::Cast(..),
187 span: cast_span,
188 ..
189 }) = self.tcx.parent_hir_node(hir_expr.hir_id)
190 {
191 span = *cast_span;
193 true
194 } else {
195 false
196 };
197 ExprKind::PointerCoercion {
198 cast,
199 source: self.thir.exprs.push(expr),
200 is_from_as_cast,
201 }
202 }
203 Adjust::NeverToAny if adjustment.target.is_never() => return expr,
204 Adjust::NeverToAny => ExprKind::NeverToAny { source: self.thir.exprs.push(expr) },
205 Adjust::Deref(DerefAdjustKind::Builtin) => {
206 adjust_span(&mut expr);
207 ExprKind::Deref { arg: self.thir.exprs.push(expr) }
208 }
209 Adjust::Deref(DerefAdjustKind::Pin) => {
210 adjust_span(&mut expr);
211 let pin_ty = expr.ty.pinned_ty().expect("Deref(Pin) with non-Pin type");
213 let pointer_target = ExprKind::Field {
214 lhs: self.thir.exprs.push(expr),
215 variant_index: FIRST_VARIANT,
216 name: FieldIdx::ZERO,
217 };
218 let expr = Expr { temp_scope_id, ty: pin_ty, span, kind: pointer_target };
219 ExprKind::Deref { arg: self.thir.exprs.push(expr) }
221 }
222 Adjust::Deref(DerefAdjustKind::Overloaded(deref)) => {
223 let call_def_id = deref.method_call(self.tcx);
226 let overloaded_callee = self
227 .tcx
228 .type_of(call_def_id)
229 .instantiate(self.tcx, self.tcx.mk_args(&[expr.ty.into()]))
230 .skip_norm_wip();
231
232 expr = Expr {
233 temp_scope_id,
234 ty: Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, deref.mutbl),
235 span,
236 kind: ExprKind::Borrow {
237 borrow_kind: deref.mutbl.to_borrow_kind(),
238 arg: self.thir.exprs.push(expr),
239 },
240 };
241
242 let expr = Box::new([self.thir.exprs.push(expr)]);
243
244 self.overloaded_place(
245 hir_expr,
246 adjustment.target,
247 Some(overloaded_callee),
248 expr,
249 deref.span,
250 )
251 }
252 Adjust::Borrow(AutoBorrow::Ref(m)) => ExprKind::Borrow {
253 borrow_kind: m.to_borrow_kind(),
254 arg: self.thir.exprs.push(expr),
255 },
256 Adjust::Borrow(AutoBorrow::RawPtr(mutability)) => {
257 ExprKind::RawBorrow { mutability, arg: self.thir.exprs.push(expr) }
258 }
259 Adjust::Borrow(AutoBorrow::Pin(mutbl)) => {
260 let borrow_kind = match mutbl {
262 hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
263 hir::Mutability::Not => BorrowKind::Shared,
264 };
265 let new_pin_target =
266 Ty::new_ref(self.tcx, self.tcx.lifetimes.re_erased, expr.ty, mutbl);
267 let arg = self.thir.exprs.push(expr);
268 let expr = self.thir.exprs.push(Expr {
269 temp_scope_id,
270 ty: new_pin_target,
271 span,
272 kind: ExprKind::Borrow { borrow_kind, arg },
273 });
274
275 let pin_did = self.tcx.require_lang_item(LangItem::Pin, span);
277 let args = self.tcx.mk_args(&[new_pin_target.into()]);
278 let kind = ExprKind::Adt(Box::new(AdtExpr {
279 adt_def: self.tcx.adt_def(pin_did),
280 variant_index: FIRST_VARIANT,
281 args,
282 fields: Box::new([FieldExpr { name: FieldIdx::ZERO, expr }]),
283 user_ty: None,
284 base: AdtExprBase::None,
285 }));
286
287 debug!(?kind);
288 kind
289 }
290 Adjust::GenericReborrow(mutability) => {
291 let expr = self.thir.exprs.push(expr);
292 let kind =
293 ExprKind::Reborrow { source: expr, mutability, target: adjustment.target };
294
295 kind
296 }
297 };
298
299 Expr { temp_scope_id, ty: adjustment.target, span, kind }
300 }
301
302 fn mirror_expr_cast(
306 &mut self,
307 source: &'tcx hir::Expr<'tcx>,
308 temp_scope_id: hir::ItemLocalId,
309 span: Span,
310 ) -> ExprKind<'tcx> {
311 let tcx = self.tcx;
312
313 if self.typeck_results.is_coercion_cast(source.hir_id) {
316 ExprKind::ValueExpr { source: self.mirror_expr(source) }
318 } else if self.typeck_results.expr_ty(source).is_ref() {
319 ExprKind::PointerCoercion {
323 source: self.mirror_expr(source),
324 cast: PointerCoercion::ArrayToPointer,
325 is_from_as_cast: true,
326 }
327 } else if let hir::ExprKind::Path(ref qpath) = source.kind
328 && let res = self.typeck_results.qpath_res(qpath, source.hir_id)
329 && let ty = self.typeck_results.node_type(source.hir_id)
330 && let ty::Adt(adt_def, args) = ty.kind()
331 && let Res::Def(DefKind::Ctor(CtorOf::Variant, CtorKind::Const), variant_ctor_id) = res
332 {
333 let idx = adt_def.variant_index_with_ctor_id(variant_ctor_id);
346 let (discr_did, discr_offset) = adt_def.discriminant_def_for_variant(idx);
347
348 use rustc_middle::ty::util::IntTypeExt;
349 let ty = adt_def.repr().discr_type();
350 let discr_ty = ty.to_ty(tcx);
351
352 let size = tcx
353 .layout_of(self.typing_env.as_query_input(discr_ty))
354 .unwrap_or_else(|e| {
::core::panicking::panic_fmt(format_args!("could not compute layout for {0:?}: {1:?}",
discr_ty, e));
}panic!("could not compute layout for {discr_ty:?}: {e:?}"))
355 .size;
356
357 let (lit, overflowing) = ScalarInt::truncate_from_uint(discr_offset as u128, size);
358 if overflowing {
359 self.tcx.dcx().span_delayed_bug(
361 source.span,
362 "overflowing enum wasn't rejected by hir analysis",
363 );
364 }
365 let kind = ExprKind::NonHirLiteral { lit, user_ty: None };
366 let offset = self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
367
368 let source = match discr_did {
369 Some(did) => {
372 let kind = ExprKind::NamedConst { def_id: did, args, user_ty: None };
373 let lhs =
374 self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind });
375 let bin = ExprKind::Binary { op: BinOp::Add, lhs, rhs: offset };
376 self.thir.exprs.push(Expr { temp_scope_id, ty: discr_ty, span, kind: bin })
377 }
378 None => offset,
379 };
380
381 ExprKind::Cast { source }
382 } else {
383 ExprKind::Cast { source: self.mirror_expr(source) }
386 }
387 }
388
389 {}
let __tracing_attr_span;
let __tracing_attr_guard;
if ::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() || { false }
{
__tracing_attr_span =
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("make_mirror_unadjusted",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(389u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("expr")
}> =
::tracing::__macro_support::FieldName::new("expr");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::SPAN)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let mut interest = ::tracing::subscriber::Interest::never();
if ::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{ interest = __CALLSITE.interest(); !interest.is_never() }
&&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest) {
let meta = __CALLSITE.metadata();
::tracing::Span::new(meta,
&{
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
meta.fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr)
as &dyn ::tracing::field::Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[allow(clippy :: redundant_closure_call)]
let x =
(move ||
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy
:: needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: Expr<'tcx> = loop {};
return __tracing_attr_fake_return;
}
{
let tcx = self.tcx;
let expr_ty = self.typeck_results.expr_ty(expr);
let mk_expr =
|kind, ty|
Expr {
temp_scope_id: expr.hir_id.local_id,
span: expr.span,
ty,
kind,
};
let kind =
match expr.kind {
hir::ExprKind::MethodCall(segment, receiver, args, fn_span)
=> {
if self.typeck_results.is_splatted_call(expr) {
self.convert_splatted_callee(expr, fn_span, args,
SplattedFunc::FnDefReceiver(receiver))
} else {
let expr =
self.method_callee(expr, segment.ident.span, None);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:411",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::INFO,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(411u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::INFO <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::INFO <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Using method span: {0:?}",
expr.span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let args =
std::iter::once(receiver).chain(args.iter()).map(|expr|
self.mirror_expr(expr)).collect();
ExprKind::Call {
ty: expr.ty,
fun: self.thir.exprs.push(expr),
args,
from_hir_call: true,
fn_span,
}
}
}
hir::ExprKind::Call(fun, ref args) => {
if self.typeck_results.is_method_call(expr) {
let method = self.method_callee(expr, fun.span, None);
let arg_tys =
args.iter().map(|e|
self.typeck_results.expr_ty_adjusted(e));
let tupled_args =
Expr {
ty: Ty::new_tup_from_iter(tcx, arg_tys),
temp_scope_id: expr.hir_id.local_id,
span: expr.span,
kind: ExprKind::Tuple { fields: self.mirror_exprs(args) },
};
let tupled_args = self.thir.exprs.push(tupled_args);
ExprKind::Call {
ty: method.ty,
fun: self.thir.exprs.push(method),
args: Box::new([self.mirror_expr(fun), tupled_args]),
from_hir_call: true,
fn_span: expr.span,
}
} else if self.typeck_results.is_splatted_call(expr) {
self.convert_splatted_callee(expr, fun.span, args,
SplattedFunc::FnExpression(fun))
} else {
let adt_data =
if let hir::ExprKind::Path(ref qpath) = fun.kind &&
let Some(adt_def) = expr_ty.ty_adt_def() {
match qpath {
hir::QPath::Resolved(_, path) =>
match path.res {
Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
}
Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
_ => None,
},
hir::QPath::TypeRelative(_ty, _) => {
if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
self.typeck_results.type_dependent_def(fun.hir_id) {
Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
} else { None }
}
}
} else { None };
if let Some((adt_def, index)) = adt_data {
let node_args = self.typeck_results.node_args(fun.hir_id);
let user_provided_types =
self.typeck_results.user_provided_types();
let user_ty =
user_provided_types.get(fun.hir_id).copied().map(|mut u_ty|
{
if let ty::UserTypeKind::TypeOf(did, _) =
&mut u_ty.value.kind {
*did = adt_def.did();
}
Box::new(u_ty)
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:499",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(499u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (call) user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let field_refs =
args.iter().enumerate().map(|(idx, e)|
FieldExpr {
name: FieldIdx::new(idx),
expr: self.mirror_expr(e),
}).collect();
ExprKind::Adt(Box::new(AdtExpr {
adt_def,
args: node_args,
variant_index: index,
fields: field_refs,
user_ty,
base: AdtExprBase::None,
}))
} else {
ExprKind::Call {
ty: self.typeck_results.node_type(fun.hir_id),
fun: self.mirror_expr(fun),
args: self.mirror_exprs(args),
from_hir_call: true,
fn_span: expr.span,
}
}
}
}
hir::ExprKind::Use(expr, span) => {
ExprKind::ByUse { expr: self.mirror_expr(expr), span }
}
hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
ExprKind::Borrow {
borrow_kind: mutbl.to_borrow_kind(),
arg: self.mirror_expr(arg),
}
}
hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg)
=> {
ExprKind::RawBorrow {
mutability,
arg: self.mirror_expr(arg),
}
}
hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr)
=>
match expr_ty.kind() {
&ty::Adt(adt_def, args) if
tcx.is_lang_item(adt_def.did(), LangItem::Pin) => {
let ty = args.type_at(0);
let arg_ty = self.typeck_results.expr_ty(arg_expr);
let mut arg = self.mirror_expr(arg_expr);
if mutbl.is_mut() &&
!arg_ty.is_unpin(self.tcx, self.typing_env) {
let block =
self.thir.blocks.push(Block {
targeted_by_break: false,
region_scope: region::Scope {
local_id: arg_expr.hir_id.local_id,
data: region::ScopeData::Node,
},
span: arg_expr.span,
stmts: Box::new([]),
expr: Some(arg),
safety_mode: BlockSafety::Safe,
});
arg =
self.thir.exprs.push(Expr {
temp_scope_id: arg_expr.hir_id.local_id,
ty: arg_ty,
span: arg_expr.span,
kind: ExprKind::Block { block },
});
}
let expr =
self.thir.exprs.push(Expr {
temp_scope_id: expr.hir_id.local_id,
ty,
span: expr.span,
kind: ExprKind::Borrow {
borrow_kind: mutbl.to_borrow_kind(),
arg,
},
});
ExprKind::Adt(Box::new(AdtExpr {
adt_def,
variant_index: FIRST_VARIANT,
args,
fields: Box::new([FieldExpr {
name: FieldIdx::from(0u32),
expr,
}]),
user_ty: None,
base: AdtExprBase::None,
}))
}
_ =>
bug_impl(Some(expr.span),
format_args!("unexpected type for pinned borrow: {0:?}",
expr_ty), Location::caller()),
},
hir::ExprKind::Block(blk, _) =>
ExprKind::Block { block: self.mirror_block(blk) },
hir::ExprKind::Assign(lhs, rhs, _) => {
ExprKind::Assign {
lhs: self.mirror_expr(lhs),
rhs: self.mirror_expr(rhs),
}
}
hir::ExprKind::AssignOp(op, lhs, rhs) => {
if self.typeck_results.is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let rhs = self.mirror_expr(rhs);
self.overloaded_operator(expr, Box::new([lhs, rhs]))
} else {
ExprKind::AssignOp {
op: assign_op(op.node),
lhs: self.mirror_expr(lhs),
rhs: self.mirror_expr(rhs),
}
}
}
hir::ExprKind::Lit(lit) =>
ExprKind::Literal { lit, neg: false },
hir::ExprKind::Binary(op, lhs, rhs) => {
if self.typeck_results.is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let rhs = self.mirror_expr(rhs);
self.overloaded_operator(expr, Box::new([lhs, rhs]))
} else {
match op.node {
hir::BinOpKind::And =>
ExprKind::LogicalOp {
op: LogicalOp::And,
lhs: self.mirror_expr(lhs),
rhs: self.mirror_expr(rhs),
},
hir::BinOpKind::Or =>
ExprKind::LogicalOp {
op: LogicalOp::Or,
lhs: self.mirror_expr(lhs),
rhs: self.mirror_expr(rhs),
},
_ => {
let op = bin_op(op.node);
ExprKind::Binary {
op,
lhs: self.mirror_expr(lhs),
rhs: self.mirror_expr(rhs),
}
}
}
}
}
hir::ExprKind::Index(lhs, index, brackets_span) => {
if self.typeck_results.is_method_call(expr) {
let lhs = self.mirror_expr(lhs);
let index = self.mirror_expr(index);
self.overloaded_place(expr, expr_ty, None,
Box::new([lhs, index]), brackets_span)
} else {
ExprKind::Index {
lhs: self.mirror_expr(lhs),
index: self.mirror_expr(index),
}
}
}
hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
if self.typeck_results.is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_place(expr, expr_ty, None, Box::new([arg]),
expr.span)
} else { ExprKind::Deref { arg: self.mirror_expr(arg) } }
}
hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
if self.typeck_results.is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_operator(expr, Box::new([arg]))
} else {
ExprKind::Unary {
op: UnOp::Not,
arg: self.mirror_expr(arg),
}
}
}
hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
if self.typeck_results.is_method_call(expr) {
let arg = self.mirror_expr(arg);
self.overloaded_operator(expr, Box::new([arg]))
} else if let hir::ExprKind::Lit(lit) = arg.kind {
ExprKind::Literal { lit, neg: true }
} else {
ExprKind::Unary {
op: UnOp::Neg,
arg: self.mirror_expr(arg),
}
}
}
hir::ExprKind::Struct(qpath, fields, ref base) =>
match expr_ty.kind() {
ty::Adt(adt, args) =>
match adt.adt_kind() {
AdtKind::Struct | AdtKind::Union => {
let user_provided_types =
self.typeck_results.user_provided_types();
let user_ty =
user_provided_types.get(expr.hir_id).copied().map(Box::new);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:688",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(688u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (struct/union) user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
ExprKind::Adt(Box::new(AdtExpr {
adt_def: *adt,
variant_index: FIRST_VARIANT,
args,
user_ty,
fields: self.field_refs(fields),
base: match base {
hir::StructTailExpr::Base(base) =>
AdtExprBase::Base(FruInfo {
base: self.mirror_expr(base),
field_types: self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect(),
}),
hir::StructTailExpr::DefaultFields(_) => {
AdtExprBase::DefaultFields(self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect())
}
hir::StructTailExpr::None |
hir::StructTailExpr::NoneWithError(_) => AdtExprBase::None,
},
}))
}
AdtKind::Enum => {
let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
match res {
Res::Def(DefKind::Variant, variant_id) => {
if !#[allow(non_exhaustive_omitted_patterns)] match base {
hir::StructTailExpr::None |
hir::StructTailExpr::DefaultFields(_) |
hir::StructTailExpr::NoneWithError(_) => true,
_ => false,
} {
::core::panicking::panic("assertion failed: matches!(base, hir::StructTailExpr::None |\n hir::StructTailExpr::DefaultFields(_) |\n hir::StructTailExpr::NoneWithError(_))")
};
let index = adt.variant_index_with_id(variant_id);
let user_provided_types =
self.typeck_results.user_provided_types();
let user_ty =
user_provided_types.get(expr.hir_id).copied().map(Box::new);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:731",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(731u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (variant) user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
ExprKind::Adt(Box::new(AdtExpr {
adt_def: *adt,
variant_index: index,
args,
user_ty,
fields: self.field_refs(fields),
base: match base {
hir::StructTailExpr::DefaultFields(_) => {
AdtExprBase::DefaultFields(self.typeck_results.fru_field_types()[expr.hir_id].iter().copied().collect())
}
hir::StructTailExpr::Base(base) => {
bug_impl(Some(base.span),
format_args!("unexpected res: {0:?}", res),
Location::caller());
}
hir::StructTailExpr::None |
hir::StructTailExpr::NoneWithError(_) => {
AdtExprBase::None
}
},
}))
}
_ => {
bug_impl(Some(expr.span),
format_args!("unexpected res: {0:?}", res),
Location::caller());
}
}
}
},
_ => {
bug_impl(Some(expr.span),
format_args!("unexpected type for struct literal: {0:?}",
expr_ty), Location::caller());
}
},
hir::ExprKind::Closure(hir::Closure { .. }) => {
let closure_ty = self.typeck_results.expr_ty(expr);
let (def_id, args, movability) =
match *closure_ty.kind() {
ty::Closure(def_id, args) =>
(def_id, UpvarArgs::Closure(args), None),
ty::Coroutine(def_id, args) => {
(def_id, UpvarArgs::Coroutine(args),
Some(tcx.coroutine_movability(def_id)))
}
ty::CoroutineClosure(def_id, args) => {
(def_id, UpvarArgs::CoroutineClosure(args), None)
}
_ => {
bug_impl(Some(expr.span),
format_args!("closure expr w/o closure type: {0:?}",
closure_ty), Location::caller());
}
};
let def_id = def_id.expect_local();
let upvars =
self.tcx.closure_captures(def_id).iter().zip_eq(args.upvar_tys()).map(|(captured_place,
ty)|
{
let upvars = self.capture_upvar(expr, captured_place, ty);
self.thir.exprs.push(upvars)
}).collect();
let fake_reads =
match self.typeck_results.closure_fake_reads.get(&def_id) {
Some(fake_reads) =>
fake_reads.iter().map(|(place, cause, hir_id)|
{
let expr =
self.convert_captured_hir_place(expr, place.clone());
(self.thir.exprs.push(expr), *cause, *hir_id)
}).collect(),
None => Vec::new(),
};
ExprKind::Closure(Box::new(ClosureExpr {
closure_id: def_id,
args,
upvars,
movability,
fake_reads,
}))
}
hir::ExprKind::Path(ref qpath) => {
let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
self.convert_path_expr(expr, res)
}
hir::ExprKind::InlineAsm(asm) =>
ExprKind::InlineAsm(Box::new(InlineAsmExpr {
asm_macro: asm.asm_macro,
template: asm.template,
operands: asm.operands.iter().map(|(op, _op_sp)|
match *op {
hir::InlineAsmOperand::In { reg, expr } => {
InlineAsmOperand::In { reg, expr: self.mirror_expr(expr) }
}
hir::InlineAsmOperand::Out { reg, late, ref expr } => {
InlineAsmOperand::Out {
reg,
late,
expr: expr.map(|expr| self.mirror_expr(expr)),
}
}
hir::InlineAsmOperand::InOut { reg, late, expr } => {
InlineAsmOperand::InOut {
reg,
late,
expr: self.mirror_expr(expr),
}
}
hir::InlineAsmOperand::SplitInOut {
reg, late, in_expr, ref out_expr } => {
InlineAsmOperand::SplitInOut {
reg,
late,
in_expr: self.mirror_expr(in_expr),
out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
}
}
hir::InlineAsmOperand::Const { ref anon_const } => {
let ty = self.typeck_results.node_type(anon_const.hir_id);
let did = anon_const.def_id;
let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
let parent_args =
tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx,
typeck_root_def_id));
let args =
InlineConstArgs::new(tcx,
InlineConstArgsParts { parent_args, ty }).args;
let uneval =
mir::UnevaluatedConst::new(did.to_def_id(), args);
let value = mir::Const::Unevaluated(uneval, ty);
InlineAsmOperand::Const { value, span: tcx.def_span(did) }
}
hir::InlineAsmOperand::SymFn { expr } => {
InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
}
hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
InlineAsmOperand::SymStatic { def_id }
}
hir::InlineAsmOperand::Label { block } => {
InlineAsmOperand::Label { block: self.mirror_block(block) }
}
}).collect(),
options: asm.options,
line_spans: asm.line_spans,
})),
hir::ExprKind::OffsetOf(_, _) => {
let offset_of_intrinsic =
tcx.require_lang_item(LangItem::OffsetOf, expr.span);
let mk_u32_kind =
|val: u32|
ExprKind::NonHirLiteral {
lit: ScalarInt::try_from_uint(val,
Size::from_bits(32)).unwrap(),
user_ty: None,
};
let mk_usize_kind =
|val: u64|
ExprKind::NonHirLiteral {
lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
user_ty: None,
};
let mk_call =
|thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx,
field: FieldIdx|
{
let fun_ty =
tcx.type_of(offset_of_intrinsic).instantiate(tcx,
&[ty.into()]).skip_norm_wip();
let fun =
thir.exprs.push(mk_expr(ExprKind::ZstLiteral {
user_ty: None,
}, fun_ty));
let variant =
thir.exprs.push(mk_expr(mk_u32_kind(variant.as_u32()),
tcx.types.u32));
let field =
thir.exprs.push(mk_expr(mk_u32_kind(field.as_u32()),
tcx.types.u32));
let args = Box::new([variant, field]);
ExprKind::Call {
ty: fun_ty,
fun,
args,
from_hir_call: false,
fn_span: expr.span,
}
};
let indices =
self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
let mut expr = None::<ExprKind<'_>>;
for &(container, variant, field) in indices.iter() {
let next =
mk_call(&mut self.thir, container, variant, field);
expr =
Some(match expr.take() {
None => next,
Some(last) => {
let last =
self.thir.exprs.push(mk_expr(last, tcx.types.usize));
let next =
self.thir.exprs.push(mk_expr(next, tcx.types.usize));
ExprKind::Binary { op: BinOp::Add, lhs: last, rhs: next }
}
});
}
expr.unwrap_or_else(|| mk_usize_kind(0))
}
hir::ExprKind::ConstBlock(ref anon_const) => {
let ty = self.typeck_results.node_type(anon_const.hir_id);
let did = anon_const.def_id;
let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
let parent_args =
tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(tcx,
typeck_root_def_id));
let args =
InlineConstArgs::new(tcx,
InlineConstArgsParts { parent_args, ty }).args;
ExprKind::ConstBlock { did: did.to_def_id(), args }
}
hir::ExprKind::Repeat(v, _) => {
let ty = self.typeck_results.expr_ty(expr);
let ty::Array(_, count) =
ty.kind() else {
bug_impl(Some(expr.span),
format_args!("unexpected repeat expr ty: {0:?}", ty),
Location::caller());
};
ExprKind::Repeat {
value: self.mirror_expr(v),
count: *count,
}
}
hir::ExprKind::Ret(v) =>
ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
hir::ExprKind::Become(call) =>
ExprKind::Become { value: self.mirror_expr(call) },
hir::ExprKind::Break(dest, ref value) => {
if {
{
'done:
{
for i in
::rustc_attr_ir::HasAttrs::get_attrs(expr.hir_id, &self.tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(ConstContinue(_)) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some() {
match dest.target_id {
Ok(target_id) => {
let (Some(value), Some(_)) =
(value,
dest.label) else {
let span = expr.span;
self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue {
span,
})
};
ExprKind::ConstContinue {
label: region::Scope {
local_id: target_id.local_id,
data: region::ScopeData::Node,
},
value: self.mirror_expr(value),
}
}
Err(err) =>
bug_impl(None,
format_args!("invalid loop id for break: {0}", err),
Location::caller()),
}
} else {
match dest.target_id {
Ok(target_id) =>
ExprKind::Break {
label: region::Scope {
local_id: target_id.local_id,
data: region::ScopeData::Node,
},
value: value.map(|value| self.mirror_expr(value)),
},
Err(err) =>
bug_impl(None,
format_args!("invalid loop id for break: {0}", err),
Location::caller()),
}
}
}
hir::ExprKind::Continue(dest) =>
match dest.target_id {
Ok(loop_id) =>
ExprKind::Continue {
label: region::Scope {
local_id: loop_id.local_id,
data: region::ScopeData::Node,
},
},
Err(err) =>
bug_impl(None,
format_args!("invalid loop id for continue: {0}", err),
Location::caller()),
},
hir::ExprKind::Let(let_expr) =>
ExprKind::Let {
expr: self.mirror_expr(let_expr.init),
pat: self.pattern_from_hir(let_expr.pat),
},
hir::ExprKind::If(cond, then, else_opt) =>
ExprKind::If {
if_then_scope: region::Scope {
local_id: then.hir_id.local_id,
data: {
if expr.span.at_least_rust_2024() {
region::ScopeData::IfThenRescope
} else { region::ScopeData::IfThen }
},
},
cond: self.mirror_expr(cond),
then: self.mirror_expr(then),
else_opt: else_opt.map(|el| self.mirror_expr(el)),
},
hir::ExprKind::Match(discr, arms, match_source) =>
ExprKind::Match {
scrutinee: self.mirror_expr(discr),
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
match_source,
},
hir::ExprKind::Loop(body, ..) => {
if {
{
'done:
{
for i in
::rustc_attr_ir::HasAttrs::get_attrs(expr.hir_id, &self.tcx)
{
#[allow(unused_imports)]
use ::rustc_attr_ir::AttributeKind::*;
let i: &::rustc_attr_ir::Attribute = i;
match i {
::rustc_attr_ir::Attribute::Parsed(LoopMatch(_)) => {
break 'done Some(());
}
::rustc_attr_ir::Attribute::Unparsed(..) =>
{}
#[deny(unreachable_patterns)]
_ => {}
}
}
None
}
}
}.is_some() {
let dcx = self.tcx.dcx();
let loop_body_expr =
match body.stmts {
[] =>
match body.expr {
Some(expr) => expr,
None =>
dcx.emit_fatal(LoopMatchMissingAssignment {
span: body.span,
}),
},
[single] if body.expr.is_none() =>
match single.kind {
hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) =>
expr,
_ =>
dcx.emit_fatal(LoopMatchMissingAssignment {
span: body.span,
}),
},
[first @ last] | [first, .., last] =>
dcx.emit_fatal(LoopMatchBadStatements {
span: first.span.to(last.span),
}),
};
let hir::ExprKind::Assign(state, rhs_expr, _) =
loop_body_expr.kind else {
dcx.emit_fatal(LoopMatchMissingAssignment {
span: loop_body_expr.span,
})
};
let hir::ExprKind::Block(block_body, _) =
rhs_expr.kind else {
dcx.emit_fatal(LoopMatchBadRhs { span: rhs_expr.span })
};
for stmt in block_body.stmts {
if !#[allow(non_exhaustive_omitted_patterns)] match stmt.kind
{
rustc_hir::StmtKind::Item(_) => true,
_ => false,
} {
dcx.emit_fatal(LoopMatchBadStatements { span: stmt.span })
}
}
let Some(block_body_expr) =
block_body.expr else {
dcx.emit_fatal(LoopMatchBadRhs { span: block_body.span })
};
let hir::ExprKind::Match(scrutinee, arms, _match_source) =
block_body_expr.kind else {
dcx.emit_fatal(LoopMatchBadRhs {
span: block_body_expr.span,
})
};
fn local(cx: &mut ThirBuildCx<'_>,
expr: &rustc_hir::Expr<'_>) -> Option<hir::HirId> {
if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) =
expr.kind && let Res::Local(hir_id) = path.res &&
!cx.is_upvar(hir_id) {
return Some(hir_id);
}
None
}
let Some(scrutinee_hir_id) =
local(self,
scrutinee) else {
dcx.emit_fatal(LoopMatchInvalidMatch {
span: scrutinee.span,
})
};
if local(self, state) != Some(scrutinee_hir_id) {
dcx.emit_fatal(LoopMatchInvalidUpdate {
scrutinee: scrutinee.span,
lhs: state.span,
})
}
ExprKind::LoopMatch {
state: self.mirror_expr(state),
region_scope: region::Scope {
local_id: block_body.hir_id.local_id,
data: region::ScopeData::Node,
},
match_data: Box::new(LoopMatchMatchData {
scrutinee: self.mirror_expr(scrutinee),
arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
span: block_body_expr.span,
}),
}
} else {
let block_ty = self.typeck_results.node_type(body.hir_id);
let block = self.mirror_block(body);
let body =
self.thir.exprs.push(Expr {
ty: block_ty,
temp_scope_id: body.hir_id.local_id,
span: self.thir[block].span,
kind: ExprKind::Block { block },
});
ExprKind::Loop { body }
}
}
hir::ExprKind::Field(source, ..) =>
ExprKind::Field {
lhs: self.mirror_expr(source),
variant_index: FIRST_VARIANT,
name: self.typeck_results.field_index(expr.hir_id),
},
hir::ExprKind::Cast(source, cast_ty) => {
let user_provided_types =
self.typeck_results.user_provided_types();
let user_ty = user_provided_types.get(cast_ty.hir_id);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1121",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1121u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("cast({0:?}) has ty w/ hir_id {1:?} and user provided ty {2:?}",
expr, cast_ty.hir_id, user_ty) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};
let cast =
self.mirror_expr_cast(source, expr.hir_id.local_id,
expr.span);
if let Some(user_ty) = user_ty {
let cast_expr =
self.thir.exprs.push(Expr {
temp_scope_id: expr.hir_id.local_id,
ty: expr_ty,
span: expr.span,
kind: cast,
});
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1137",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1137u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (cast) user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
ExprKind::ValueTypeAscription {
source: cast_expr,
user_ty: Some(Box::new(*user_ty)),
user_ty_span: cast_ty.span,
}
} else { cast }
}
hir::ExprKind::Type(source, ty) => {
let user_provided_types =
self.typeck_results.user_provided_types();
let user_ty =
user_provided_types.get(ty.hir_id).copied().map(Box::new);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1151",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1151u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("make_mirror_unadjusted: (type) user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};
let mirrored = self.mirror_expr(source);
if source.is_syntactic_place_expr() {
ExprKind::PlaceTypeAscription {
source: mirrored,
user_ty,
user_ty_span: ty.span,
}
} else {
ExprKind::ValueTypeAscription {
source: mirrored,
user_ty,
user_ty_span: ty.span,
}
}
}
hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Unwrap,
source, _ty) => {
let mirrored = self.mirror_expr(source);
if source.is_syntactic_place_expr() {
ExprKind::PlaceUnwrapUnsafeBinder { source: mirrored }
} else {
ExprKind::ValueUnwrapUnsafeBinder { source: mirrored }
}
}
hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Wrap,
source, _ty) => {
let mirrored = self.mirror_expr(source);
ExprKind::WrapUnsafeBinder { source: mirrored }
}
hir::ExprKind::DropTemps(source) => {
ExprKind::ValueExpr { source: self.mirror_expr(source) }
}
hir::ExprKind::Array(fields) =>
ExprKind::Array { fields: self.mirror_exprs(fields) },
hir::ExprKind::Tup(fields) =>
ExprKind::Tuple { fields: self.mirror_exprs(fields) },
hir::ExprKind::Yield(v, _) =>
ExprKind::Yield { value: self.mirror_expr(v) },
hir::ExprKind::Err(_) => {
::core::panicking::panic_fmt(format_args!("internal error: entered unreachable code: {0}",
format_args!("cannot lower a `hir::ExprKind::Err` to THIR")));
}
};
mk_expr(kind, expr_ty)
}
})();
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:389",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(389u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&[{
const NAME:
::tracing::__macro_support::FieldName<{
::tracing::__macro_support::FieldName::len("return")
}> =
::tracing::__macro_support::FieldName::new("return");
NAME.as_str()
}], ::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&::tracing::field::debug(&x)
as &dyn ::tracing::field::Value))])
});
} else { ; }
};
x;#[instrument(level = "debug", skip(self), ret)]
390 fn make_mirror_unadjusted(&mut self, expr: &'tcx hir::Expr<'tcx>) -> Expr<'tcx> {
391 let tcx = self.tcx;
392 let expr_ty = self.typeck_results.expr_ty(expr);
393 let mk_expr =
394 |kind, ty| Expr { temp_scope_id: expr.hir_id.local_id, span: expr.span, ty, kind };
395
396 let kind = match expr.kind {
397 hir::ExprKind::MethodCall(segment, receiver, args, fn_span) => {
399 if self.typeck_results.is_splatted_call(expr) {
400 self.convert_splatted_callee(
403 expr,
404 fn_span,
405 args,
406 SplattedFunc::FnDefReceiver(receiver),
407 )
408 } else {
409 let expr = self.method_callee(expr, segment.ident.span, None);
411 info!("Using method span: {:?}", expr.span);
412
413 let args = std::iter::once(receiver)
414 .chain(args.iter())
415 .map(|expr| self.mirror_expr(expr))
416 .collect();
417 ExprKind::Call {
418 ty: expr.ty,
419 fun: self.thir.exprs.push(expr),
420 args,
421 from_hir_call: true,
422 fn_span,
423 }
424 }
425 }
426
427 hir::ExprKind::Call(fun, ref args) => {
428 if self.typeck_results.is_method_call(expr) {
429 let method = self.method_callee(expr, fun.span, None);
437
438 let arg_tys = args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e));
439 let tupled_args = Expr {
440 ty: Ty::new_tup_from_iter(tcx, arg_tys),
441 temp_scope_id: expr.hir_id.local_id,
442 span: expr.span,
443 kind: ExprKind::Tuple { fields: self.mirror_exprs(args) },
444 };
445 let tupled_args = self.thir.exprs.push(tupled_args);
446
447 ExprKind::Call {
448 ty: method.ty,
449 fun: self.thir.exprs.push(method),
450 args: Box::new([self.mirror_expr(fun), tupled_args]),
451 from_hir_call: true,
452 fn_span: expr.span,
453 }
454 } else if self.typeck_results.is_splatted_call(expr) {
455 self.convert_splatted_callee(
458 expr,
459 fun.span,
460 args,
461 SplattedFunc::FnExpression(fun),
462 )
463 } else {
464 let adt_data = if let hir::ExprKind::Path(ref qpath) = fun.kind
466 && let Some(adt_def) = expr_ty.ty_adt_def()
467 {
468 match qpath {
469 hir::QPath::Resolved(_, path) => match path.res {
470 Res::Def(DefKind::Ctor(_, CtorKind::Fn), ctor_id) => {
471 Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
472 }
473 Res::SelfCtor(..) => Some((adt_def, FIRST_VARIANT)),
474 _ => None,
475 },
476 hir::QPath::TypeRelative(_ty, _) => {
477 if let Some((DefKind::Ctor(_, CtorKind::Fn), ctor_id)) =
478 self.typeck_results.type_dependent_def(fun.hir_id)
479 {
480 Some((adt_def, adt_def.variant_index_with_ctor_id(ctor_id)))
481 } else {
482 None
483 }
484 }
485 }
486 } else {
487 None
488 };
489 if let Some((adt_def, index)) = adt_data {
490 let node_args = self.typeck_results.node_args(fun.hir_id);
491 let user_provided_types = self.typeck_results.user_provided_types();
492 let user_ty =
493 user_provided_types.get(fun.hir_id).copied().map(|mut u_ty| {
494 if let ty::UserTypeKind::TypeOf(did, _) = &mut u_ty.value.kind {
495 *did = adt_def.did();
496 }
497 Box::new(u_ty)
498 });
499 debug!("make_mirror_unadjusted: (call) user_ty={:?}", user_ty);
500
501 let field_refs = args
502 .iter()
503 .enumerate()
504 .map(|(idx, e)| FieldExpr {
505 name: FieldIdx::new(idx),
506 expr: self.mirror_expr(e),
507 })
508 .collect();
509 ExprKind::Adt(Box::new(AdtExpr {
510 adt_def,
511 args: node_args,
512 variant_index: index,
513 fields: field_refs,
514 user_ty,
515 base: AdtExprBase::None,
516 }))
517 } else {
518 ExprKind::Call {
519 ty: self.typeck_results.node_type(fun.hir_id),
520 fun: self.mirror_expr(fun),
521 args: self.mirror_exprs(args),
522 from_hir_call: true,
523 fn_span: expr.span,
524 }
525 }
526 }
527 }
528
529 hir::ExprKind::Use(expr, span) => {
530 ExprKind::ByUse { expr: self.mirror_expr(expr), span }
531 }
532
533 hir::ExprKind::AddrOf(hir::BorrowKind::Ref, mutbl, arg) => {
534 ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg: self.mirror_expr(arg) }
535 }
536
537 hir::ExprKind::AddrOf(hir::BorrowKind::Raw, mutability, arg) => {
538 ExprKind::RawBorrow { mutability, arg: self.mirror_expr(arg) }
539 }
540
541 hir::ExprKind::AddrOf(hir::BorrowKind::Pin, mutbl, arg_expr) => match expr_ty.kind() {
544 &ty::Adt(adt_def, args) if tcx.is_lang_item(adt_def.did(), LangItem::Pin) => {
545 let ty = args.type_at(0);
546 let arg_ty = self.typeck_results.expr_ty(arg_expr);
547 let mut arg = self.mirror_expr(arg_expr);
548 if mutbl.is_mut() && !arg_ty.is_unpin(self.tcx, self.typing_env) {
551 let block = self.thir.blocks.push(Block {
552 targeted_by_break: false,
553 region_scope: region::Scope {
554 local_id: arg_expr.hir_id.local_id,
555 data: region::ScopeData::Node,
556 },
557 span: arg_expr.span,
558 stmts: Box::new([]),
559 expr: Some(arg),
560 safety_mode: BlockSafety::Safe,
561 });
562 arg = self.thir.exprs.push(Expr {
563 temp_scope_id: arg_expr.hir_id.local_id,
564 ty: arg_ty,
565 span: arg_expr.span,
566 kind: ExprKind::Block { block },
567 });
568 }
569 let expr = self.thir.exprs.push(Expr {
570 temp_scope_id: expr.hir_id.local_id,
571 ty,
572 span: expr.span,
573 kind: ExprKind::Borrow { borrow_kind: mutbl.to_borrow_kind(), arg },
574 });
575 ExprKind::Adt(Box::new(AdtExpr {
576 adt_def,
577 variant_index: FIRST_VARIANT,
578 args,
579 fields: Box::new([FieldExpr { name: FieldIdx::from(0u32), expr }]),
580 user_ty: None,
581 base: AdtExprBase::None,
582 }))
583 }
584 _ => span_bug!(expr.span, "unexpected type for pinned borrow: {:?}", expr_ty),
585 },
586
587 hir::ExprKind::Block(blk, _) => ExprKind::Block { block: self.mirror_block(blk) },
588
589 hir::ExprKind::Assign(lhs, rhs, _) => {
590 ExprKind::Assign { lhs: self.mirror_expr(lhs), rhs: self.mirror_expr(rhs) }
591 }
592
593 hir::ExprKind::AssignOp(op, lhs, rhs) => {
594 if self.typeck_results.is_method_call(expr) {
595 let lhs = self.mirror_expr(lhs);
596 let rhs = self.mirror_expr(rhs);
597 self.overloaded_operator(expr, Box::new([lhs, rhs]))
598 } else {
599 ExprKind::AssignOp {
600 op: assign_op(op.node),
601 lhs: self.mirror_expr(lhs),
602 rhs: self.mirror_expr(rhs),
603 }
604 }
605 }
606
607 hir::ExprKind::Lit(lit) => ExprKind::Literal { lit, neg: false },
608
609 hir::ExprKind::Binary(op, lhs, rhs) => {
610 if self.typeck_results.is_method_call(expr) {
611 let lhs = self.mirror_expr(lhs);
612 let rhs = self.mirror_expr(rhs);
613 self.overloaded_operator(expr, Box::new([lhs, rhs]))
614 } else {
615 match op.node {
616 hir::BinOpKind::And => ExprKind::LogicalOp {
617 op: LogicalOp::And,
618 lhs: self.mirror_expr(lhs),
619 rhs: self.mirror_expr(rhs),
620 },
621 hir::BinOpKind::Or => ExprKind::LogicalOp {
622 op: LogicalOp::Or,
623 lhs: self.mirror_expr(lhs),
624 rhs: self.mirror_expr(rhs),
625 },
626 _ => {
627 let op = bin_op(op.node);
628 ExprKind::Binary {
629 op,
630 lhs: self.mirror_expr(lhs),
631 rhs: self.mirror_expr(rhs),
632 }
633 }
634 }
635 }
636 }
637
638 hir::ExprKind::Index(lhs, index, brackets_span) => {
639 if self.typeck_results.is_method_call(expr) {
640 let lhs = self.mirror_expr(lhs);
641 let index = self.mirror_expr(index);
642 self.overloaded_place(
643 expr,
644 expr_ty,
645 None,
646 Box::new([lhs, index]),
647 brackets_span,
648 )
649 } else {
650 ExprKind::Index { lhs: self.mirror_expr(lhs), index: self.mirror_expr(index) }
651 }
652 }
653
654 hir::ExprKind::Unary(hir::UnOp::Deref, arg) => {
655 if self.typeck_results.is_method_call(expr) {
656 let arg = self.mirror_expr(arg);
657 self.overloaded_place(expr, expr_ty, None, Box::new([arg]), expr.span)
658 } else {
659 ExprKind::Deref { arg: self.mirror_expr(arg) }
660 }
661 }
662
663 hir::ExprKind::Unary(hir::UnOp::Not, arg) => {
664 if self.typeck_results.is_method_call(expr) {
665 let arg = self.mirror_expr(arg);
666 self.overloaded_operator(expr, Box::new([arg]))
667 } else {
668 ExprKind::Unary { op: UnOp::Not, arg: self.mirror_expr(arg) }
669 }
670 }
671
672 hir::ExprKind::Unary(hir::UnOp::Neg, arg) => {
673 if self.typeck_results.is_method_call(expr) {
674 let arg = self.mirror_expr(arg);
675 self.overloaded_operator(expr, Box::new([arg]))
676 } else if let hir::ExprKind::Lit(lit) = arg.kind {
677 ExprKind::Literal { lit, neg: true }
678 } else {
679 ExprKind::Unary { op: UnOp::Neg, arg: self.mirror_expr(arg) }
680 }
681 }
682
683 hir::ExprKind::Struct(qpath, fields, ref base) => match expr_ty.kind() {
684 ty::Adt(adt, args) => match adt.adt_kind() {
685 AdtKind::Struct | AdtKind::Union => {
686 let user_provided_types = self.typeck_results.user_provided_types();
687 let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
688 debug!("make_mirror_unadjusted: (struct/union) user_ty={:?}", user_ty);
689 ExprKind::Adt(Box::new(AdtExpr {
690 adt_def: *adt,
691 variant_index: FIRST_VARIANT,
692 args,
693 user_ty,
694 fields: self.field_refs(fields),
695 base: match base {
696 hir::StructTailExpr::Base(base) => AdtExprBase::Base(FruInfo {
697 base: self.mirror_expr(base),
698 field_types: self.typeck_results.fru_field_types()[expr.hir_id]
699 .iter()
700 .copied()
701 .collect(),
702 }),
703 hir::StructTailExpr::DefaultFields(_) => {
704 AdtExprBase::DefaultFields(
705 self.typeck_results.fru_field_types()[expr.hir_id]
706 .iter()
707 .copied()
708 .collect(),
709 )
710 }
711 hir::StructTailExpr::None
712 | hir::StructTailExpr::NoneWithError(_) => AdtExprBase::None,
713 },
714 }))
715 }
716 AdtKind::Enum => {
717 let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
718 match res {
719 Res::Def(DefKind::Variant, variant_id) => {
720 assert!(matches!(
721 base,
722 hir::StructTailExpr::None
723 | hir::StructTailExpr::DefaultFields(_)
724 | hir::StructTailExpr::NoneWithError(_)
725 ));
726
727 let index = adt.variant_index_with_id(variant_id);
728 let user_provided_types = self.typeck_results.user_provided_types();
729 let user_ty =
730 user_provided_types.get(expr.hir_id).copied().map(Box::new);
731 debug!("make_mirror_unadjusted: (variant) user_ty={:?}", user_ty);
732 ExprKind::Adt(Box::new(AdtExpr {
733 adt_def: *adt,
734 variant_index: index,
735 args,
736 user_ty,
737 fields: self.field_refs(fields),
738 base: match base {
739 hir::StructTailExpr::DefaultFields(_) => {
740 AdtExprBase::DefaultFields(
741 self.typeck_results.fru_field_types()[expr.hir_id]
742 .iter()
743 .copied()
744 .collect(),
745 )
746 }
747 hir::StructTailExpr::Base(base) => {
748 span_bug!(base.span, "unexpected res: {:?}", res);
749 }
750 hir::StructTailExpr::None
751 | hir::StructTailExpr::NoneWithError(_) => {
752 AdtExprBase::None
753 }
754 },
755 }))
756 }
757 _ => {
758 span_bug!(expr.span, "unexpected res: {:?}", res);
759 }
760 }
761 }
762 },
763 _ => {
764 span_bug!(expr.span, "unexpected type for struct literal: {:?}", expr_ty);
765 }
766 },
767
768 hir::ExprKind::Closure(hir::Closure { .. }) => {
769 let closure_ty = self.typeck_results.expr_ty(expr);
770 let (def_id, args, movability) = match *closure_ty.kind() {
771 ty::Closure(def_id, args) => (def_id, UpvarArgs::Closure(args), None),
772 ty::Coroutine(def_id, args) => {
773 (def_id, UpvarArgs::Coroutine(args), Some(tcx.coroutine_movability(def_id)))
774 }
775 ty::CoroutineClosure(def_id, args) => {
776 (def_id, UpvarArgs::CoroutineClosure(args), None)
777 }
778 _ => {
779 span_bug!(expr.span, "closure expr w/o closure type: {:?}", closure_ty);
780 }
781 };
782 let def_id = def_id.expect_local();
783
784 let upvars = self
785 .tcx
786 .closure_captures(def_id)
787 .iter()
788 .zip_eq(args.upvar_tys())
789 .map(|(captured_place, ty)| {
790 let upvars = self.capture_upvar(expr, captured_place, ty);
791 self.thir.exprs.push(upvars)
792 })
793 .collect();
794
795 let fake_reads = match self.typeck_results.closure_fake_reads.get(&def_id) {
797 Some(fake_reads) => fake_reads
798 .iter()
799 .map(|(place, cause, hir_id)| {
800 let expr = self.convert_captured_hir_place(expr, place.clone());
801 (self.thir.exprs.push(expr), *cause, *hir_id)
802 })
803 .collect(),
804 None => Vec::new(),
805 };
806
807 ExprKind::Closure(Box::new(ClosureExpr {
808 closure_id: def_id,
809 args,
810 upvars,
811 movability,
812 fake_reads,
813 }))
814 }
815
816 hir::ExprKind::Path(ref qpath) => {
817 let res = self.typeck_results.qpath_res(qpath, expr.hir_id);
818 self.convert_path_expr(expr, res)
819 }
820
821 hir::ExprKind::InlineAsm(asm) => ExprKind::InlineAsm(Box::new(InlineAsmExpr {
822 asm_macro: asm.asm_macro,
823 template: asm.template,
824 operands: asm
825 .operands
826 .iter()
827 .map(|(op, _op_sp)| match *op {
828 hir::InlineAsmOperand::In { reg, expr } => {
829 InlineAsmOperand::In { reg, expr: self.mirror_expr(expr) }
830 }
831 hir::InlineAsmOperand::Out { reg, late, ref expr } => {
832 InlineAsmOperand::Out {
833 reg,
834 late,
835 expr: expr.map(|expr| self.mirror_expr(expr)),
836 }
837 }
838 hir::InlineAsmOperand::InOut { reg, late, expr } => {
839 InlineAsmOperand::InOut { reg, late, expr: self.mirror_expr(expr) }
840 }
841 hir::InlineAsmOperand::SplitInOut { reg, late, in_expr, ref out_expr } => {
842 InlineAsmOperand::SplitInOut {
843 reg,
844 late,
845 in_expr: self.mirror_expr(in_expr),
846 out_expr: out_expr.map(|expr| self.mirror_expr(expr)),
847 }
848 }
849 hir::InlineAsmOperand::Const { ref anon_const } => {
850 let ty = self.typeck_results.node_type(anon_const.hir_id);
851 let did = anon_const.def_id;
852 let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
853 let parent_args = tcx.erase_and_anonymize_regions(
854 GenericArgs::identity_for_item(tcx, typeck_root_def_id),
855 );
856 let args =
857 InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty })
858 .args;
859
860 let uneval = mir::UnevaluatedConst::new(did.to_def_id(), args);
861 let value = mir::Const::Unevaluated(uneval, ty);
862 InlineAsmOperand::Const { value, span: tcx.def_span(did) }
863 }
864 hir::InlineAsmOperand::SymFn { expr } => {
865 InlineAsmOperand::SymFn { value: self.mirror_expr(expr) }
866 }
867 hir::InlineAsmOperand::SymStatic { path: _, def_id } => {
868 InlineAsmOperand::SymStatic { def_id }
869 }
870 hir::InlineAsmOperand::Label { block } => {
871 InlineAsmOperand::Label { block: self.mirror_block(block) }
872 }
873 })
874 .collect(),
875 options: asm.options,
876 line_spans: asm.line_spans,
877 })),
878
879 hir::ExprKind::OffsetOf(_, _) => {
880 let offset_of_intrinsic = tcx.require_lang_item(LangItem::OffsetOf, expr.span);
881 let mk_u32_kind = |val: u32| ExprKind::NonHirLiteral {
882 lit: ScalarInt::try_from_uint(val, Size::from_bits(32)).unwrap(),
883 user_ty: None,
884 };
885 let mk_usize_kind = |val: u64| ExprKind::NonHirLiteral {
886 lit: ScalarInt::try_from_target_usize(val, tcx).unwrap(),
887 user_ty: None,
888 };
889 let mk_call =
890 |thir: &mut Thir<'tcx>, ty: Ty<'tcx>, variant: VariantIdx, field: FieldIdx| {
891 let fun_ty = tcx
892 .type_of(offset_of_intrinsic)
893 .instantiate(tcx, &[ty.into()])
894 .skip_norm_wip();
895 let fun = thir
896 .exprs
897 .push(mk_expr(ExprKind::ZstLiteral { user_ty: None }, fun_ty));
898 let variant =
899 thir.exprs.push(mk_expr(mk_u32_kind(variant.as_u32()), tcx.types.u32));
900 let field =
901 thir.exprs.push(mk_expr(mk_u32_kind(field.as_u32()), tcx.types.u32));
902 let args = Box::new([variant, field]);
903 ExprKind::Call {
904 ty: fun_ty,
905 fun,
906 args,
907 from_hir_call: false,
908 fn_span: expr.span,
909 }
910 };
911
912 let indices = self.typeck_results.offset_of_data().get(expr.hir_id).unwrap();
913 let mut expr = None::<ExprKind<'_>>;
914
915 for &(container, variant, field) in indices.iter() {
916 let next = mk_call(&mut self.thir, container, variant, field);
917 expr = Some(match expr.take() {
918 None => next,
919 Some(last) => {
920 let last = self.thir.exprs.push(mk_expr(last, tcx.types.usize));
921 let next = self.thir.exprs.push(mk_expr(next, tcx.types.usize));
922 ExprKind::Binary { op: BinOp::Add, lhs: last, rhs: next }
923 }
924 });
925 }
926
927 expr.unwrap_or_else(|| mk_usize_kind(0))
928 }
929
930 hir::ExprKind::ConstBlock(ref anon_const) => {
931 let ty = self.typeck_results.node_type(anon_const.hir_id);
932 let did = anon_const.def_id;
933 let typeck_root_def_id = tcx.typeck_root_def_id_local(did);
934 let parent_args = tcx.erase_and_anonymize_regions(GenericArgs::identity_for_item(
935 tcx,
936 typeck_root_def_id,
937 ));
938 let args = InlineConstArgs::new(tcx, InlineConstArgsParts { parent_args, ty }).args;
939
940 ExprKind::ConstBlock { did: did.to_def_id(), args }
941 }
942 hir::ExprKind::Repeat(v, _) => {
944 let ty = self.typeck_results.expr_ty(expr);
945 let ty::Array(_, count) = ty.kind() else {
946 span_bug!(expr.span, "unexpected repeat expr ty: {:?}", ty);
947 };
948
949 ExprKind::Repeat { value: self.mirror_expr(v), count: *count }
950 }
951 hir::ExprKind::Ret(v) => ExprKind::Return { value: v.map(|v| self.mirror_expr(v)) },
952 hir::ExprKind::Become(call) => ExprKind::Become { value: self.mirror_expr(call) },
953 hir::ExprKind::Break(dest, ref value) => {
954 if find_attr!(self.tcx, expr.hir_id, ConstContinue(_)) {
955 match dest.target_id {
956 Ok(target_id) => {
957 let (Some(value), Some(_)) = (value, dest.label) else {
958 let span = expr.span;
959 self.tcx.dcx().emit_fatal(ConstContinueMissingLabelOrValue { span })
960 };
961
962 ExprKind::ConstContinue {
963 label: region::Scope {
964 local_id: target_id.local_id,
965 data: region::ScopeData::Node,
966 },
967 value: self.mirror_expr(value),
968 }
969 }
970 Err(err) => bug!("invalid loop id for break: {}", err),
971 }
972 } else {
973 match dest.target_id {
974 Ok(target_id) => ExprKind::Break {
975 label: region::Scope {
976 local_id: target_id.local_id,
977 data: region::ScopeData::Node,
978 },
979 value: value.map(|value| self.mirror_expr(value)),
980 },
981 Err(err) => bug!("invalid loop id for break: {}", err),
982 }
983 }
984 }
985 hir::ExprKind::Continue(dest) => match dest.target_id {
986 Ok(loop_id) => ExprKind::Continue {
987 label: region::Scope {
988 local_id: loop_id.local_id,
989 data: region::ScopeData::Node,
990 },
991 },
992 Err(err) => bug!("invalid loop id for continue: {}", err),
993 },
994 hir::ExprKind::Let(let_expr) => ExprKind::Let {
995 expr: self.mirror_expr(let_expr.init),
996 pat: self.pattern_from_hir(let_expr.pat),
997 },
998 hir::ExprKind::If(cond, then, else_opt) => ExprKind::If {
999 if_then_scope: region::Scope {
1000 local_id: then.hir_id.local_id,
1001 data: {
1002 if expr.span.at_least_rust_2024() {
1003 region::ScopeData::IfThenRescope
1004 } else {
1005 region::ScopeData::IfThen
1006 }
1007 },
1008 },
1009 cond: self.mirror_expr(cond),
1010 then: self.mirror_expr(then),
1011 else_opt: else_opt.map(|el| self.mirror_expr(el)),
1012 },
1013 hir::ExprKind::Match(discr, arms, match_source) => ExprKind::Match {
1014 scrutinee: self.mirror_expr(discr),
1015 arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
1016 match_source,
1017 },
1018 hir::ExprKind::Loop(body, ..) => {
1019 if find_attr!(self.tcx, expr.hir_id, LoopMatch(_)) {
1020 let dcx = self.tcx.dcx();
1021
1022 let loop_body_expr = match body.stmts {
1024 [] => match body.expr {
1025 Some(expr) => expr,
1026 None => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
1027 },
1028 [single] if body.expr.is_none() => match single.kind {
1029 hir::StmtKind::Expr(expr) | hir::StmtKind::Semi(expr) => expr,
1030 _ => dcx.emit_fatal(LoopMatchMissingAssignment { span: body.span }),
1031 },
1032 [first @ last] | [first, .., last] => dcx
1033 .emit_fatal(LoopMatchBadStatements { span: first.span.to(last.span) }),
1034 };
1035
1036 let hir::ExprKind::Assign(state, rhs_expr, _) = loop_body_expr.kind else {
1037 dcx.emit_fatal(LoopMatchMissingAssignment { span: loop_body_expr.span })
1038 };
1039
1040 let hir::ExprKind::Block(block_body, _) = rhs_expr.kind else {
1041 dcx.emit_fatal(LoopMatchBadRhs { span: rhs_expr.span })
1042 };
1043
1044 for stmt in block_body.stmts {
1047 if !matches!(stmt.kind, rustc_hir::StmtKind::Item(_)) {
1048 dcx.emit_fatal(LoopMatchBadStatements { span: stmt.span })
1049 }
1050 }
1051
1052 let Some(block_body_expr) = block_body.expr else {
1053 dcx.emit_fatal(LoopMatchBadRhs { span: block_body.span })
1054 };
1055
1056 let hir::ExprKind::Match(scrutinee, arms, _match_source) = block_body_expr.kind
1057 else {
1058 dcx.emit_fatal(LoopMatchBadRhs { span: block_body_expr.span })
1059 };
1060
1061 fn local(
1062 cx: &mut ThirBuildCx<'_>,
1063 expr: &rustc_hir::Expr<'_>,
1064 ) -> Option<hir::HirId> {
1065 if let hir::ExprKind::Path(hir::QPath::Resolved(_, path)) = expr.kind
1066 && let Res::Local(hir_id) = path.res
1067 && !cx.is_upvar(hir_id)
1068 {
1069 return Some(hir_id);
1070 }
1071
1072 None
1073 }
1074
1075 let Some(scrutinee_hir_id) = local(self, scrutinee) else {
1076 dcx.emit_fatal(LoopMatchInvalidMatch { span: scrutinee.span })
1077 };
1078
1079 if local(self, state) != Some(scrutinee_hir_id) {
1080 dcx.emit_fatal(LoopMatchInvalidUpdate {
1081 scrutinee: scrutinee.span,
1082 lhs: state.span,
1083 })
1084 }
1085
1086 ExprKind::LoopMatch {
1087 state: self.mirror_expr(state),
1088 region_scope: region::Scope {
1089 local_id: block_body.hir_id.local_id,
1090 data: region::ScopeData::Node,
1091 },
1092
1093 match_data: Box::new(LoopMatchMatchData {
1094 scrutinee: self.mirror_expr(scrutinee),
1095 arms: arms.iter().map(|a| self.convert_arm(a)).collect(),
1096 span: block_body_expr.span,
1097 }),
1098 }
1099 } else {
1100 let block_ty = self.typeck_results.node_type(body.hir_id);
1101 let block = self.mirror_block(body);
1102 let body = self.thir.exprs.push(Expr {
1103 ty: block_ty,
1104 temp_scope_id: body.hir_id.local_id,
1105 span: self.thir[block].span,
1106 kind: ExprKind::Block { block },
1107 });
1108 ExprKind::Loop { body }
1109 }
1110 }
1111 hir::ExprKind::Field(source, ..) => ExprKind::Field {
1112 lhs: self.mirror_expr(source),
1113 variant_index: FIRST_VARIANT,
1114 name: self.typeck_results.field_index(expr.hir_id),
1115 },
1116 hir::ExprKind::Cast(source, cast_ty) => {
1117 let user_provided_types = self.typeck_results.user_provided_types();
1119 let user_ty = user_provided_types.get(cast_ty.hir_id);
1120
1121 debug!(
1122 "cast({:?}) has ty w/ hir_id {:?} and user provided ty {:?}",
1123 expr, cast_ty.hir_id, user_ty,
1124 );
1125
1126 let cast = self.mirror_expr_cast(source, expr.hir_id.local_id, expr.span);
1127
1128 if let Some(user_ty) = user_ty {
1129 let cast_expr = self.thir.exprs.push(Expr {
1132 temp_scope_id: expr.hir_id.local_id,
1133 ty: expr_ty,
1134 span: expr.span,
1135 kind: cast,
1136 });
1137 debug!("make_mirror_unadjusted: (cast) user_ty={:?}", user_ty);
1138
1139 ExprKind::ValueTypeAscription {
1140 source: cast_expr,
1141 user_ty: Some(Box::new(*user_ty)),
1142 user_ty_span: cast_ty.span,
1143 }
1144 } else {
1145 cast
1146 }
1147 }
1148 hir::ExprKind::Type(source, ty) => {
1149 let user_provided_types = self.typeck_results.user_provided_types();
1150 let user_ty = user_provided_types.get(ty.hir_id).copied().map(Box::new);
1151 debug!("make_mirror_unadjusted: (type) user_ty={:?}", user_ty);
1152 let mirrored = self.mirror_expr(source);
1153 if source.is_syntactic_place_expr() {
1154 ExprKind::PlaceTypeAscription {
1155 source: mirrored,
1156 user_ty,
1157 user_ty_span: ty.span,
1158 }
1159 } else {
1160 ExprKind::ValueTypeAscription {
1161 source: mirrored,
1162 user_ty,
1163 user_ty_span: ty.span,
1164 }
1165 }
1166 }
1167
1168 hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Unwrap, source, _ty) => {
1169 let mirrored = self.mirror_expr(source);
1171 if source.is_syntactic_place_expr() {
1172 ExprKind::PlaceUnwrapUnsafeBinder { source: mirrored }
1173 } else {
1174 ExprKind::ValueUnwrapUnsafeBinder { source: mirrored }
1175 }
1176 }
1177 hir::ExprKind::UnsafeBinderCast(UnsafeBinderCastKind::Wrap, source, _ty) => {
1178 let mirrored = self.mirror_expr(source);
1180 ExprKind::WrapUnsafeBinder { source: mirrored }
1181 }
1182
1183 hir::ExprKind::DropTemps(source) => {
1184 ExprKind::ValueExpr { source: self.mirror_expr(source) }
1185 }
1186 hir::ExprKind::Array(fields) => ExprKind::Array { fields: self.mirror_exprs(fields) },
1187 hir::ExprKind::Tup(fields) => ExprKind::Tuple { fields: self.mirror_exprs(fields) },
1188
1189 hir::ExprKind::Yield(v, _) => ExprKind::Yield { value: self.mirror_expr(v) },
1190 hir::ExprKind::Err(_) => unreachable!("cannot lower a `hir::ExprKind::Err` to THIR"),
1191 };
1192
1193 mk_expr(kind, expr_ty)
1194 }
1195
1196 fn user_args_applied_to_res(
1197 &mut self,
1198 hir_id: hir::HirId,
1199 res: Res,
1200 ) -> Option<Box<ty::CanonicalUserType<'tcx>>> {
1201 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1201",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1201u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: res={0:?}",
res) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("user_args_applied_to_res: res={:?}", res);
1202 let user_provided_type = match res {
1203 Res::Def(DefKind::Fn, _)
1207 | Res::Def(DefKind::AssocFn, _)
1208 | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1209 | Res::Def(DefKind::Const, _)
1210 | Res::Def(DefKind::AssocConst, _) => {
1211 self.typeck_results.user_provided_types().get(hir_id).copied().map(Box::new)
1212 }
1213
1214 Res::Def(DefKind::Ctor(_, CtorKind::Const), _) => {
1219 self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new)
1220 }
1221
1222 Res::SelfCtor(_) => self.user_args_applied_to_ty_of_hir_id(hir_id).map(Box::new),
1224
1225 _ => bug_impl(None,
format_args!("user_args_applied_to_res: unexpected res {0:?} at {1:?}",
res, hir_id), Location::caller())bug!("user_args_applied_to_res: unexpected res {:?} at {:?}", res, hir_id),
1226 };
1227 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1227",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1227u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("user_args_applied_to_res: user_provided_type={0:?}",
user_provided_type) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("user_args_applied_to_res: user_provided_type={:?}", user_provided_type);
1228 user_provided_type
1229 }
1230
1231 fn method_callee(
1232 &mut self,
1233 expr: &hir::Expr<'_>,
1234 span: Span,
1235 overloaded_callee: Option<Ty<'tcx>>,
1236 ) -> Expr<'tcx> {
1237 let (ty, user_ty) = match overloaded_callee {
1238 Some(fn_def) => (fn_def, None),
1239 None => {
1240 let (kind, def_id) =
1241 self.typeck_results.type_dependent_def(expr.hir_id).unwrap_or_else(|| {
1242 bug_impl(Some(expr.span),
format_args!("no type-dependent def for method callee"),
Location::caller())span_bug!(expr.span, "no type-dependent def for method callee")
1243 });
1244 let user_ty = self.user_args_applied_to_res(expr.hir_id, Res::Def(kind, def_id));
1245 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1245",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1245u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("method_callee: user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("method_callee: user_ty={:?}", user_ty);
1246 (
1247 self.tcx
1248 .type_of(def_id)
1249 .instantiate(self.tcx, self.typeck_results.node_args(expr.hir_id))
1250 .skip_norm_wip(),
1251 user_ty,
1252 )
1253 }
1254 };
1255 Expr {
1256 temp_scope_id: expr.hir_id.local_id,
1257 ty,
1258 span,
1259 kind: ExprKind::ZstLiteral { user_ty },
1260 }
1261 }
1262
1263 fn convert_splatted_callee(
1267 &mut self,
1268 call_expr: &'tcx hir::Expr<'_>,
1269 fn_span: Span,
1270 args: &'tcx [hir::Expr<'tcx>],
1271 receiver_or_func: SplattedFunc<'tcx>,
1272 ) -> ExprKind<'tcx> {
1273 let tcx = self.tcx;
1274
1275 let splatted_def =
1277 self.typeck_results.splatted_def(call_expr.hir_id).unwrap_or_else(|| {
1278 bug_impl(Some(call_expr.span),
format_args!("no splatted def for function or method callee"),
Location::caller())span_bug!(call_expr.span, "no splatted def for function or method callee")
1279 });
1280
1281 let tupled_arg_index = usize::from(splatted_def.arg_index());
1282 let tupled_args_count = usize::from(splatted_def.arg_count());
1283
1284 if tupled_arg_index + tupled_args_count > args.len() {
1287 bug_impl(Some(call_expr.span),
format_args!("splatted arg index out of bounds of function args: {0:?} + {1:?} > {2:?} for function call: {3:?}, args {4:?}",
tupled_arg_index, tupled_args_count, args.len(), receiver_or_func,
args), Location::caller());span_bug!(
1288 call_expr.span,
1289 "splatted arg index out of bounds of function args: {:?} + {:?} > {:?} for function call: {:?}, args {:?}",
1290 tupled_arg_index,
1291 tupled_args_count,
1292 args.len(),
1293 receiver_or_func,
1294 args,
1295 );
1296 }
1297
1298 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1298",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1298u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("Using splatted function span: {0:?}",
fn_span) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("Using splatted function span: {:?}", fn_span);
1299
1300 let initial_non_tupled_args =
1302 args.iter().take(tupled_arg_index).map(|e| self.mirror_expr(e)).collect_vec();
1303 let tupled_args = if tupled_arg_index == args.len() || tupled_args_count == 0 {
1304 Default::default()
1306 } else {
1307 &args[tupled_arg_index..(tupled_arg_index + tupled_args_count)]
1308 };
1309 let final_non_tupled_args = args
1310 .iter()
1311 .skip(tupled_arg_index + tupled_args_count)
1312 .map(|e| self.mirror_expr(e))
1313 .collect_vec();
1314
1315 let tupled_arg_tys = tupled_args.iter().map(|e| self.typeck_results.expr_ty_adjusted(e));
1316
1317 let tupled_args = Expr {
1320 ty: Ty::new_tup_from_iter(tcx, tupled_arg_tys),
1321 temp_scope_id: call_expr.hir_id.local_id,
1322 span: call_expr.span,
1323 kind: ExprKind::Tuple { fields: self.mirror_exprs(tupled_args) },
1324 };
1325
1326 let tupled_args = self.thir.exprs.push(tupled_args);
1327
1328 let mut args = Vec::with_capacity(
1330 usize::from(receiver_or_func.has_receiver())
1331 + initial_non_tupled_args.len()
1332 + 1
1333 + final_non_tupled_args.len(),
1334 );
1335 if let Some(receiver) = receiver_or_func.receiver() {
1336 args.push(self.mirror_expr(receiver));
1337 }
1338 args.extend(initial_non_tupled_args);
1339 args.push(tupled_args);
1340 args.extend(final_non_tupled_args);
1341
1342 let fn_span = if receiver_or_func.has_receiver() { fn_span } else { call_expr.span };
1343
1344 let (fn_ty, fun_expr) = match (splatted_def, receiver_or_func.fn_expression()) {
1345 (SplattedDef::FnDef { def_id, arg_index, arg_count }, _) => {
1347 let def_kind = self.tcx.def_kind(def_id);
1351 let user_ty =
1352 self.user_args_applied_to_res(call_expr.hir_id, Res::Def(def_kind, def_id));
1353 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1353",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1353u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("splatted_callee FnDef: user_ty={0:?} def_kind={1:?} def_id={2:?} arg_index={3:?} arg_count={4:?}",
user_ty, def_kind, def_id, arg_index, arg_count) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1354 "splatted_callee FnDef: user_ty={:?} def_kind={:?} def_id={:?} arg_index={:?} arg_count={:?}",
1355 user_ty, def_kind, def_id, arg_index, arg_count,
1356 );
1357
1358 let callee_expr = Expr {
1360 temp_scope_id: call_expr.hir_id.local_id,
1361 ty: self
1362 .tcx
1363 .type_of(def_id)
1364 .instantiate(self.tcx, self.typeck_results.node_args(call_expr.hir_id))
1365 .skip_norm_wip(),
1366 span: fn_span,
1367 kind: ExprKind::ZstLiteral { user_ty },
1368 };
1369 (callee_expr.ty, self.thir.exprs.push(callee_expr))
1370 }
1371
1372 (SplattedDef::FnPtr { fn_ptr_type, arg_index, arg_count }, Some(fn_expression)) => {
1375 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1375",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1375u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("splatted_callee FnPtr: fn_ty={0:?} arg_index={1:?} arg_count={2:?}",
fn_ptr_type, arg_index, arg_count) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1376 "splatted_callee FnPtr: fn_ty={:?} arg_index={:?} arg_count={:?}",
1377 fn_ptr_type, arg_index, arg_count,
1378 );
1379
1380 if !fn_ptr_type.is_fn() {
1381 bug_impl(Some(call_expr.span),
format_args!("splatted FnPtr side-tables were not populated correctly, non-fn type received: {0:?}",
fn_ptr_type), Location::caller())span_bug!(
1382 call_expr.span,
1383 "splatted FnPtr side-tables were not populated correctly, non-fn type received: {:?}",
1384 fn_ptr_type
1385 )
1386 }
1387
1388 (fn_ptr_type, self.mirror_expr(fn_expression))
1390 }
1391 (SplattedDef::FnPtr { .. }, None) => {
1393 bug_impl(Some(call_expr.span),
format_args!("convert_splatted_callee: FnPtr without fn expression (or with receiver) is invalid: splatted_def={0:?}, receiver_or_func={1:?}",
splatted_def, receiver_or_func), Location::caller());span_bug!(
1394 call_expr.span,
1395 "convert_splatted_callee: FnPtr without fn expression (or with receiver) is invalid: splatted_def={:?}, receiver_or_func={:?}",
1396 splatted_def,
1397 receiver_or_func,
1398 );
1399 }
1400 };
1401
1402 ExprKind::Call {
1403 ty: fn_ty,
1404 fun: fun_expr,
1405 args: args.into_boxed_slice(),
1406 from_hir_call: true,
1407 fn_span,
1408 }
1409 }
1410
1411 fn convert_arm(&mut self, arm: &'tcx hir::Arm<'tcx>) -> ArmId {
1412 let arm = Arm {
1413 pattern: self.pattern_from_hir(&arm.pat),
1414 guard: arm.guard.as_ref().map(|g| self.mirror_expr(g)),
1415 body: self.mirror_expr(arm.body),
1416 hir_id: arm.hir_id,
1417 scope: region::Scope { local_id: arm.hir_id.local_id, data: region::ScopeData::Node },
1418 span: arm.span,
1419 };
1420 self.thir.arms.push(arm)
1421 }
1422
1423 fn convert_path_expr(&mut self, expr: &'tcx hir::Expr<'tcx>, res: Res) -> ExprKind<'tcx> {
1424 let args = self.typeck_results.node_args(expr.hir_id);
1425 match res {
1426 Res::Def(DefKind::Fn, _)
1428 | Res::Def(DefKind::AssocFn, _)
1429 | Res::Def(DefKind::Ctor(_, CtorKind::Fn), _)
1430 | Res::SelfCtor(_) => {
1431 let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1432 ExprKind::ZstLiteral { user_ty }
1433 }
1434
1435 Res::Def(DefKind::ConstParam, def_id) => {
1436 let hir_id = self.tcx.local_def_id_to_hir_id(def_id.expect_local());
1437 let generics = self.tcx.generics_of(hir_id.owner);
1438 let Some(&index) = generics.param_def_id_to_index.get(&def_id) else {
1439 bug_impl(Some(expr.span),
format_args!("Should have already errored about late bound consts: {0:?}",
def_id), Location::caller());span_bug!(
1440 expr.span,
1441 "Should have already errored about late bound consts: {def_id:?}"
1442 );
1443 };
1444 let name = self.tcx.hir_name(hir_id);
1445 let param = ty::ParamConst::new(index, name);
1446
1447 ExprKind::ConstParam { param, def_id }
1448 }
1449
1450 Res::Def(DefKind::Const, def_id) | Res::Def(DefKind::AssocConst, def_id) => {
1451 let user_ty = self.user_args_applied_to_res(expr.hir_id, res);
1452 ExprKind::NamedConst { def_id, args, user_ty }
1453 }
1454
1455 Res::Def(DefKind::Ctor(_, CtorKind::Const), def_id) => {
1456 let user_provided_types = self.typeck_results.user_provided_types();
1457 let user_ty = user_provided_types.get(expr.hir_id).copied().map(Box::new);
1458 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1458",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1458u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("convert_path_expr: user_ty={0:?}",
user_ty) as &dyn ::tracing::field::Value))])
});
} else { ; }
};debug!("convert_path_expr: user_ty={:?}", user_ty);
1459 let ty = self.typeck_results.node_type(expr.hir_id);
1460 match ty.kind() {
1461 ty::Adt(adt_def, args) => ExprKind::Adt(Box::new(AdtExpr {
1464 adt_def: *adt_def,
1465 variant_index: adt_def.variant_index_with_ctor_id(def_id),
1466 args,
1467 user_ty,
1468 fields: Box::new([]),
1469 base: AdtExprBase::None,
1470 })),
1471 _ => bug_impl(None, format_args!("unexpected ty: {0:?}", ty), Location::caller())bug!("unexpected ty: {:?}", ty),
1472 }
1473 }
1474
1475 Res::Def(DefKind::Static { .. }, id) => {
1479 let ty = self.tcx.static_ptr_ty(id, self.typing_env);
1481 let kind = if self.tcx.is_thread_local_static(id) {
1482 ExprKind::ThreadLocalRef(id)
1483 } else {
1484 let alloc_id = self.tcx.reserve_and_set_static_alloc(id);
1485 ExprKind::StaticRef { alloc_id, ty, def_id: id }
1486 };
1487 ExprKind::Deref {
1488 arg: self.thir.exprs.push(Expr {
1489 ty,
1490 temp_scope_id: expr.hir_id.local_id,
1491 span: expr.span,
1492 kind,
1493 }),
1494 }
1495 }
1496
1497 Res::Local(var_hir_id) => self.convert_var(var_hir_id),
1498
1499 _ => bug_impl(Some(expr.span),
format_args!("res `{0:?}` not yet implemented", res), Location::caller())span_bug!(expr.span, "res `{:?}` not yet implemented", res),
1500 }
1501 }
1502
1503 fn convert_var(&mut self, var_hir_id: hir::HirId) -> ExprKind<'tcx> {
1504 let is_upvar = self.is_upvar(var_hir_id);
1507
1508 {
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event /rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs:1508",
"rustc_mir_build::thir::cx::expr", ::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("/rustc-dev/923c95cdf5ba65cea505aa2ea829f578e1506ed8/compiler/rustc_mir_build/src/thir/cx/expr.rs"),
::tracing_core::__macro_support::Option::Some(1508u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::thir::cx::expr"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <= ::tracing::level_filters::STATIC_MAX_LEVEL
&&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
__CALLSITE.metadata().fields().value_set_all(&[(::tracing::__macro_support::Option::Some(&format_args!("convert_var({0:?}): is_upvar={1}, body_owner={2:?}",
var_hir_id, is_upvar, self.body_owner) as
&dyn ::tracing::field::Value))])
});
} else { ; }
};debug!(
1509 "convert_var({:?}): is_upvar={}, body_owner={:?}",
1510 var_hir_id, is_upvar, self.body_owner
1511 );
1512
1513 if is_upvar {
1514 ExprKind::UpvarRef {
1515 closure_def_id: self.body_owner,
1516 var_hir_id: LocalVarId(var_hir_id),
1517 }
1518 } else {
1519 ExprKind::VarRef { id: LocalVarId(var_hir_id) }
1520 }
1521 }
1522
1523 fn overloaded_operator(
1524 &mut self,
1525 expr: &'tcx hir::Expr<'tcx>,
1526 args: Box<[ExprId]>,
1527 ) -> ExprKind<'tcx> {
1528 let fun = self.method_callee(expr, expr.span, None);
1529 let fun = self.thir.exprs.push(fun);
1530 ExprKind::Call {
1531 ty: self.thir[fun].ty,
1532 fun,
1533 args,
1534 from_hir_call: false,
1535 fn_span: expr.span,
1536 }
1537 }
1538
1539 fn overloaded_place(
1540 &mut self,
1541 expr: &'tcx hir::Expr<'tcx>,
1542 place_ty: Ty<'tcx>,
1543 overloaded_callee: Option<Ty<'tcx>>,
1544 args: Box<[ExprId]>,
1545 span: Span,
1546 ) -> ExprKind<'tcx> {
1547 let ty::Ref(region, _, mutbl) = *self.thir[args[0]].ty.kind() else {
1555 bug_impl(Some(span),
format_args!("overloaded_place: receiver is not a reference"),
Location::caller());span_bug!(span, "overloaded_place: receiver is not a reference");
1556 };
1557 let ref_ty = Ty::new_ref(self.tcx, region, place_ty, mutbl);
1558
1559 let fun = self.method_callee(expr, span, overloaded_callee);
1562 let fun = self.thir.exprs.push(fun);
1563 let fun_ty = self.thir[fun].ty;
1564 let ref_expr = self.thir.exprs.push(Expr {
1565 temp_scope_id: expr.hir_id.local_id,
1566 ty: ref_ty,
1567 span,
1568 kind: ExprKind::Call { ty: fun_ty, fun, args, from_hir_call: false, fn_span: span },
1569 });
1570
1571 ExprKind::Deref { arg: ref_expr }
1573 }
1574
1575 fn convert_captured_hir_place(
1576 &mut self,
1577 closure_expr: &'tcx hir::Expr<'tcx>,
1578 place: HirPlace<'tcx>,
1579 ) -> Expr<'tcx> {
1580 let temp_scope_id = closure_expr.hir_id.local_id;
1581 let var_ty = place.base_ty;
1582
1583 let var_hir_id = match place.base {
1589 HirPlaceBase::Upvar(upvar_id) => upvar_id.var_path.hir_id,
1590 base => bug_impl(None, format_args!("Expected an upvar, found {0:?}", base),
Location::caller())bug!("Expected an upvar, found {:?}", base),
1591 };
1592
1593 let mut captured_place_expr = Expr {
1594 temp_scope_id,
1595 ty: var_ty,
1596 span: closure_expr.span,
1597 kind: self.convert_var(var_hir_id),
1598 };
1599
1600 for proj in place.projections.iter() {
1601 let kind = match proj.kind {
1602 HirProjectionKind::Deref => {
1603 ExprKind::Deref { arg: self.thir.exprs.push(captured_place_expr) }
1604 }
1605 HirProjectionKind::Field(field, variant_index) => ExprKind::Field {
1606 lhs: self.thir.exprs.push(captured_place_expr),
1607 variant_index,
1608 name: field,
1609 },
1610 HirProjectionKind::OpaqueCast => {
1611 ExprKind::ValueExpr { source: self.thir.exprs.push(captured_place_expr) }
1612 }
1613 HirProjectionKind::UnwrapUnsafeBinder => ExprKind::PlaceUnwrapUnsafeBinder {
1614 source: self.thir.exprs.push(captured_place_expr),
1615 },
1616 HirProjectionKind::Index | HirProjectionKind::Subslice => {
1617 continue;
1619 }
1620 };
1621
1622 captured_place_expr =
1623 Expr { temp_scope_id, ty: proj.ty, span: closure_expr.span, kind };
1624 }
1625
1626 captured_place_expr
1627 }
1628
1629 fn capture_upvar(
1630 &mut self,
1631 closure_expr: &'tcx hir::Expr<'tcx>,
1632 captured_place: &'tcx ty::CapturedPlace<'tcx>,
1633 upvar_ty: Ty<'tcx>,
1634 ) -> Expr<'tcx> {
1635 let upvar_capture = captured_place.info.capture_kind;
1636 let captured_place_expr =
1637 self.convert_captured_hir_place(closure_expr, captured_place.place.clone());
1638 let temp_scope_id = closure_expr.hir_id.local_id;
1639
1640 match upvar_capture {
1641 ty::UpvarCapture::ByValue => captured_place_expr,
1642 ty::UpvarCapture::ByUse => {
1643 let span = captured_place_expr.span;
1644 let expr_id = self.thir.exprs.push(captured_place_expr);
1645
1646 Expr {
1647 temp_scope_id,
1648 ty: upvar_ty,
1649 span: closure_expr.span,
1650 kind: ExprKind::ByUse { expr: expr_id, span },
1651 }
1652 }
1653 ty::UpvarCapture::ByRef(upvar_borrow) => {
1654 let borrow_kind = match upvar_borrow {
1655 ty::BorrowKind::Immutable => BorrowKind::Shared,
1656 ty::BorrowKind::UniqueImmutable => {
1657 BorrowKind::Mut { kind: mir::MutBorrowKind::ClosureCapture }
1658 }
1659 ty::BorrowKind::Mutable => {
1660 BorrowKind::Mut { kind: mir::MutBorrowKind::Default }
1661 }
1662 };
1663 Expr {
1664 temp_scope_id,
1665 ty: upvar_ty,
1666 span: closure_expr.span,
1667 kind: ExprKind::Borrow {
1668 borrow_kind,
1669 arg: self.thir.exprs.push(captured_place_expr),
1670 },
1671 }
1672 }
1673 }
1674 }
1675
1676 fn is_upvar(&mut self, var_hir_id: hir::HirId) -> bool {
1677 self.tcx
1678 .upvars_mentioned(self.body_owner)
1679 .is_some_and(|upvars| upvars.contains_key(&var_hir_id))
1680 }
1681
1682 fn field_refs(&mut self, fields: &'tcx [hir::ExprField<'tcx>]) -> Box<[FieldExpr]> {
1684 fields
1685 .iter()
1686 .map(|field| FieldExpr {
1687 name: self.typeck_results.field_index(field.hir_id),
1688 expr: self.mirror_expr(field.expr),
1689 })
1690 .collect()
1691 }
1692}
1693
1694trait ToBorrowKind {
1695 fn to_borrow_kind(&self) -> BorrowKind;
1696}
1697
1698impl ToBorrowKind for AutoBorrowMutability {
1699 fn to_borrow_kind(&self) -> BorrowKind {
1700 use rustc_middle::ty::adjustment::AllowTwoPhase;
1701 match *self {
1702 AutoBorrowMutability::Mut { allow_two_phase_borrow } => BorrowKind::Mut {
1703 kind: match allow_two_phase_borrow {
1704 AllowTwoPhase::Yes => mir::MutBorrowKind::TwoPhaseBorrow,
1705 AllowTwoPhase::No => mir::MutBorrowKind::Default,
1706 },
1707 },
1708 AutoBorrowMutability::Not => BorrowKind::Shared,
1709 }
1710 }
1711}
1712
1713impl ToBorrowKind for hir::Mutability {
1714 fn to_borrow_kind(&self) -> BorrowKind {
1715 match *self {
1716 hir::Mutability::Mut => BorrowKind::Mut { kind: mir::MutBorrowKind::Default },
1717 hir::Mutability::Not => BorrowKind::Shared,
1718 }
1719 }
1720}
1721
1722fn bin_op(op: hir::BinOpKind) -> BinOp {
1723 match op {
1724 hir::BinOpKind::Add => BinOp::Add,
1725 hir::BinOpKind::Sub => BinOp::Sub,
1726 hir::BinOpKind::Mul => BinOp::Mul,
1727 hir::BinOpKind::Div => BinOp::Div,
1728 hir::BinOpKind::Rem => BinOp::Rem,
1729 hir::BinOpKind::BitXor => BinOp::BitXor,
1730 hir::BinOpKind::BitAnd => BinOp::BitAnd,
1731 hir::BinOpKind::BitOr => BinOp::BitOr,
1732 hir::BinOpKind::Shl => BinOp::Shl,
1733 hir::BinOpKind::Shr => BinOp::Shr,
1734 hir::BinOpKind::Eq => BinOp::Eq,
1735 hir::BinOpKind::Lt => BinOp::Lt,
1736 hir::BinOpKind::Le => BinOp::Le,
1737 hir::BinOpKind::Ne => BinOp::Ne,
1738 hir::BinOpKind::Ge => BinOp::Ge,
1739 hir::BinOpKind::Gt => BinOp::Gt,
1740 _ => bug_impl(None, format_args!("no equivalent for ast binop {0:?}", op),
Location::caller())bug!("no equivalent for ast binop {:?}", op),
1741 }
1742}
1743
1744fn assign_op(op: hir::AssignOpKind) -> AssignOp {
1745 match op {
1746 hir::AssignOpKind::AddAssign => AssignOp::AddAssign,
1747 hir::AssignOpKind::SubAssign => AssignOp::SubAssign,
1748 hir::AssignOpKind::MulAssign => AssignOp::MulAssign,
1749 hir::AssignOpKind::DivAssign => AssignOp::DivAssign,
1750 hir::AssignOpKind::RemAssign => AssignOp::RemAssign,
1751 hir::AssignOpKind::BitXorAssign => AssignOp::BitXorAssign,
1752 hir::AssignOpKind::BitAndAssign => AssignOp::BitAndAssign,
1753 hir::AssignOpKind::BitOrAssign => AssignOp::BitOrAssign,
1754 hir::AssignOpKind::ShlAssign => AssignOp::ShlAssign,
1755 hir::AssignOpKind::ShrAssign => AssignOp::ShrAssign,
1756 }
1757}