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