1use rustc_abi::FieldIdx;
4use rustc_ast::{AsmMacro, InlineAsmOptions};
5use rustc_data_structures::fx::FxHashMap;
6use rustc_data_structures::stack::ensure_sufficient_stack;
7use rustc_hir as hir;
8use rustc_hir::lang_items::LangItem;
9use rustc_middle::mir::*;
10use rustc_middle::span_bug;
11use rustc_middle::thir::*;
12use rustc_middle::ty::{self, CanonicalUserTypeAnnotation, Ty};
13use rustc_span::{DUMMY_SP, Spanned, sym};
14use rustc_trait_selection::infer::InferCtxtExt;
15use tracing::{debug, instrument};
16
17use crate::builder::expr::category::{Category, RvalueFunc};
18use crate::builder::matches::{DeclareLetBindings, Exhaustive, HasMatchGuard};
19use crate::builder::scope::LintLevel;
20use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, NeedsTemporary};
21use crate::diagnostics::{LoopMatchArmWithGuard, LoopMatchUnsupportedType};
22
23impl<'a, 'tcx> Builder<'a, 'tcx> {
24 #[allow(clippy :: suspicious_else_formatting)]
{
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("expr_into_dest",
"rustc_mir_build::builder::expr::into",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/builder/expr/into.rs"),
::tracing_core::__macro_support::Option::Some(26u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::builder::expr::into"),
::tracing_core::field::FieldSet::new(&["destination",
"block", "expr_id"],
::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};
let mut iter = meta.fields().iter();
meta.fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&destination)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&block)
as &dyn Value)),
(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&::tracing::field::debug(&expr_id)
as &dyn Value))])
})
} else {
let span =
::tracing::__macro_support::__disabled_span(__CALLSITE.metadata());
{};
span
}
};
__tracing_attr_guard = __tracing_attr_span.enter();
}
#[warn(clippy :: suspicious_else_formatting)]
{
#[allow(unknown_lints, unreachable_code, clippy ::
diverging_sub_expression, clippy :: empty_loop, clippy ::
let_unit_value, clippy :: let_with_type_underscore, clippy ::
needless_return, clippy :: unreachable)]
if false {
let __tracing_attr_fake_return: BlockAnd<()> = loop {};
return __tracing_attr_fake_return;
}
{
let this = self;
let expr = &this.thir[expr_id];
let expr_span = expr.span;
let source_info = this.source_info(expr_span);
let expr_is_block_or_scope =
#[allow(non_exhaustive_omitted_patterns)] match expr.kind {
ExprKind::Block { .. } | ExprKind::Scope { .. } => true,
_ => false,
};
if !expr_is_block_or_scope {
this.block_context.push(BlockFrame::SubExpr);
}
let block_and =
match expr.kind {
ExprKind::Scope { region_scope, hir_id, value } => {
let region_scope = (region_scope, source_info);
ensure_sufficient_stack(||
{
this.in_scope(region_scope, LintLevel::Explicit(hir_id),
|this| { this.expr_into_dest(destination, block, value) })
})
}
ExprKind::Block { block: ast_block } => {
this.ast_block(destination, block, ast_block, source_info)
}
ExprKind::Match { scrutinee, ref arms, .. } =>
this.match_expr(destination, block, scrutinee, arms,
expr_span, this.thir[scrutinee].span),
ExprKind::If { cond, then, else_opt, if_then_scope } => {
let then_span = this.thir[then].span;
let then_source_info = this.source_info(then_span);
let condition_scope = this.local_scope();
let then_and_else_blocks =
this.in_scope((if_then_scope, then_source_info),
LintLevel::Inherited,
|this|
{
let source_info =
if this.is_let(cond) {
let variable_scope =
this.new_source_scope(then_span, LintLevel::Inherited);
this.source_scope = variable_scope;
SourceInfo { span: then_span, scope: variable_scope }
} else { this.source_info(then_span) };
let (then_block, else_block) =
this.in_if_then_scope(condition_scope, then_span,
|this|
{
let then_blk =
this.then_else_break(block, cond, Some(condition_scope),
source_info, DeclareLetBindings::Yes).into_block();
this.expr_into_dest(destination, then_blk, then)
});
then_block.and(else_block)
});
let (then_blk, mut else_blk);
else_blk =
{
let BlockAnd(b, v) = then_and_else_blocks;
then_blk = b;
v
};
if let Some(else_expr) = else_opt {
else_blk =
this.expr_into_dest(destination, else_blk,
else_expr).into_block();
} else {
let correct_si = this.source_info(expr_span.shrink_to_hi());
this.cfg.push_assign_unit(else_blk, correct_si, destination,
this.tcx);
}
let join_block = this.cfg.start_new_block();
this.cfg.goto(then_blk, source_info, join_block);
this.cfg.goto(else_blk, source_info, join_block);
join_block.unit()
}
ExprKind::Let { .. } => {
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("unexpected let expression outside of if or match-guard"));
}
ExprKind::NeverToAny { source } => {
let source_expr = &this.thir[source];
let is_call =
#[allow(non_exhaustive_omitted_patterns)] match source_expr.kind
{
ExprKind::Call { .. } | ExprKind::InlineAsm { .. } => true,
_ => false,
};
{
let BlockAnd(b, v) =
this.as_temp(block, this.local_temp_lifetime(), source,
Mutability::Mut);
block = b;
v
};
if is_call {
block.unit()
} else {
this.cfg.terminate(block, source_info,
TerminatorKind::Unreachable);
let end_block = this.cfg.start_new_block();
end_block.unit()
}
}
ExprKind::LogicalOp { op, lhs, rhs } => {
let condition_scope = this.local_scope();
let source_info = this.source_info(expr.span);
let (then_block, else_block) =
this.in_if_then_scope(condition_scope, expr.span,
|this|
{
this.then_else_break(block, lhs, Some(condition_scope),
source_info, DeclareLetBindings::LetNotPermitted)
});
let (short_circuit, continuation, constant) =
match op {
LogicalOp::And => (else_block, then_block, false),
LogicalOp::Or => (then_block, else_block, true),
};
this.cfg.push_assign_constant(short_circuit, source_info,
destination,
ConstOperand {
span: expr.span,
user_ty: None,
const_: Const::from_bool(this.tcx, constant),
});
let mut rhs_block =
this.expr_into_dest(destination, continuation,
rhs).into_block();
this.visit_coverage_standalone_condition(rhs, destination,
&mut rhs_block);
let target = this.cfg.start_new_block();
this.cfg.goto(rhs_block, source_info, target);
this.cfg.goto(short_circuit, source_info, target);
target.unit()
}
ExprKind::Loop { body } => {
let loop_block = this.cfg.start_new_block();
this.cfg.goto(block, source_info, loop_block);
this.in_breakable_scope(Some(loop_block), destination,
expr_span,
move |this|
{
let body_block = this.cfg.start_new_block();
this.cfg.terminate(loop_block, source_info,
TerminatorKind::FalseUnwind {
real_target: body_block,
unwind: UnwindAction::Continue,
});
this.diverge_from(loop_block);
let tmp = this.get_unit_temp();
let body_block_end =
this.expr_into_dest(tmp, body_block, body).into_block();
let goto =
this.cfg.goto(body_block_end, source_info, loop_block);
if let Some(attrs) = this.thir.attributes.get(&expr_id) {
goto.attributes = attrs.clone();
}
None
})
}
ExprKind::LoopMatch {
state,
region_scope,
match_data: LoopMatchMatchData {
ref arms, span: match_span, scrutinee
} } => {
fn is_supported_loop_match_type(ty: Ty<'_>) -> bool {
match ty.kind() {
ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Bool |
ty::Char => true,
ty::Adt(adt_def, _) =>
match adt_def.adt_kind() {
ty::AdtKind::Struct | ty::AdtKind::Union => false,
ty::AdtKind::Enum => {
adt_def.variants().iter().all(|v| v.fields.is_empty())
}
},
_ => false,
}
}
let state_ty = this.thir.exprs[state].ty;
if !is_supported_loop_match_type(state_ty) {
let span = this.thir.exprs[state].span;
this.tcx.dcx().emit_fatal(LoopMatchUnsupportedType {
span,
ty: state_ty,
})
}
let loop_block = this.cfg.start_new_block();
this.cfg.goto(block, source_info, loop_block);
this.in_breakable_scope(Some(loop_block), destination,
expr_span,
|this|
{
let mut body_block = this.cfg.start_new_block();
this.cfg.terminate(loop_block, source_info,
TerminatorKind::FalseUnwind {
real_target: body_block,
unwind: UnwindAction::Continue,
});
this.diverge_from(loop_block);
let scrutinee_span = this.thir.exprs[scrutinee].span;
let scrutinee_place_builder =
{
let BlockAnd(b, v) =
this.lower_scrutinee(body_block, scrutinee, scrutinee_span);
body_block = b;
v
};
let match_start_span =
match_span.shrink_to_lo().to(scrutinee_span);
let mut patterns = Vec::with_capacity(arms.len());
for &arm_id in arms.iter() {
let arm = &this.thir[arm_id];
if let Some(guard) = arm.guard {
let span = this.thir.exprs[guard].span;
this.tcx.dcx().emit_fatal(LoopMatchArmWithGuard { span })
}
patterns.push((&*arm.pattern, HasMatchGuard::No));
}
let built_tree =
this.lower_match_tree(body_block, scrutinee_span,
&scrutinee_place_builder, match_start_span, patterns,
Exhaustive::Yes);
let state_place = scrutinee_place_builder.to_place(this);
let state_result = this.temp(state_ty, expr_span);
let state_result_place = Place::from(state_result);
{
let BlockAnd(b, v) =
this.in_scope((region_scope, source_info),
LintLevel::Inherited,
move |this|
{
this.in_const_continuable_scope(arms.clone(),
built_tree.clone(), state_place, expr_span,
|this|
{
let block =
this.in_breakable_scope(None, state_result_place, expr_span,
|this|
{
Some(this.lower_match_arms(state_result_place,
scrutinee_place_builder, scrutinee_span, arms, built_tree,
this.source_info(match_span)))
}).into_block();
this.cfg.push_assign(block, source_info, state_place,
Rvalue::Use(this.consume_by_copy_or_move(state_result_place),
WithRetag::Yes));
block.unit()
})
});
body_block = b;
v
};
this.cfg.goto(body_block, source_info, loop_block);
None
})
}
ExprKind::Call { ty, fun, ref args, .. } if
let ty::FnDef(def_id, generic_args) = *ty.kind() &&
let Some(intrinsic) = this.tcx.intrinsic(def_id) &&
#[allow(non_exhaustive_omitted_patterns)] match intrinsic.name
{
sym::write_via_move | sym::write_box_via_move => true,
_ => false,
} => {
let _fun =
{
let BlockAnd(b, v) = this.as_local_operand(block, fun);
block = b;
v
};
match intrinsic.name {
sym::write_via_move => {
if !destination.ty(&this.local_decls, this.tcx).ty.is_unit()
{
::core::panicking::panic("assertion failed: destination.ty(&this.local_decls, this.tcx).ty.is_unit()")
};
let [ptr, val] =
**args else {
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("invalid write_via_move call"))
};
let Some(ptr) =
{
let BlockAnd(b, v) = this.as_local_operand(block, ptr);
block = b;
v
}.place() else {
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("invalid write_via_move call"))
};
let ptr_deref =
ptr.project_deeper(&[ProjectionElem::Deref], this.tcx);
this.expr_into_dest(ptr_deref, block, val)
}
sym::write_box_via_move => {
let [b, val] =
**args else {
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("invalid init_box_via_move call"))
};
let Some(b) =
{
let BlockAnd(b, v) = this.as_local_operand(block, b);
block = b;
v
}.place() else {
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("invalid init_box_via_move call"))
};
let tcx = this.tcx;
let decls = &this.local_decls;
let place = b.project_deeper(&[ProjectionElem::Deref], tcx);
let place =
place.project_to_field(FieldIdx::from_u32(1), decls, tcx);
let place =
place.project_to_field(FieldIdx::ZERO, decls, tcx);
let place =
place.project_to_field(FieldIdx::ZERO, decls, tcx);
match (&place.ty(decls, tcx).ty, &generic_args.type_at(0)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
{
let BlockAnd(b, v) = this.expr_into_dest(place, block, val);
block = b;
v
};
this.cfg.push_assign(block, source_info, destination,
Rvalue::Use(Operand::Move(b), WithRetag::Yes));
block.unit()
}
_ =>
::rustc_middle::util::bug::bug_fmt(format_args!("impossible case reached")),
}
}
ExprKind::Call {
ty: _, fun, ref args, from_hir_call, fn_span } => {
let fun =
{
let BlockAnd(b, v) = this.as_local_operand(block, fun);
block = b;
v
};
let args: Box<[_]> =
args.into_iter().copied().map(|arg|
Spanned {
node: {
let BlockAnd(b, v) = this.as_local_call_operand(block, arg);
block = b;
v
},
span: this.thir.exprs[arg].span,
}).collect();
let success = this.cfg.start_new_block();
this.record_operands_moved(&args);
{
use ::tracing::__macro_support::Callsite as _;
static __CALLSITE: ::tracing::callsite::DefaultCallsite =
{
static META: ::tracing::Metadata<'static> =
{
::tracing_core::metadata::Metadata::new("event compiler/rustc_mir_build/src/builder/expr/into.rs:495",
"rustc_mir_build::builder::expr::into",
::tracing::Level::DEBUG,
::tracing_core::__macro_support::Option::Some("compiler/rustc_mir_build/src/builder/expr/into.rs"),
::tracing_core::__macro_support::Option::Some(495u32),
::tracing_core::__macro_support::Option::Some("rustc_mir_build::builder::expr::into"),
::tracing_core::field::FieldSet::new(&["message"],
::tracing_core::callsite::Identifier(&__CALLSITE)),
::tracing::metadata::Kind::EVENT)
};
::tracing::callsite::DefaultCallsite::new(&META)
};
let enabled =
::tracing::Level::DEBUG <=
::tracing::level_filters::STATIC_MAX_LEVEL &&
::tracing::Level::DEBUG <=
::tracing::level_filters::LevelFilter::current() &&
{
let interest = __CALLSITE.interest();
!interest.is_never() &&
::tracing::__macro_support::__is_enabled(__CALLSITE.metadata(),
interest)
};
if enabled {
(|value_set: ::tracing::field::ValueSet|
{
let meta = __CALLSITE.metadata();
::tracing::Event::dispatch(meta, &value_set);
;
})({
#[allow(unused_imports)]
use ::tracing::field::{debug, display, Value};
let mut iter = __CALLSITE.metadata().fields().iter();
__CALLSITE.metadata().fields().value_set(&[(&::tracing::__macro_support::Iterator::next(&mut iter).expect("FieldSet corrupted (this is a bug)"),
::tracing::__macro_support::Option::Some(&format_args!("expr_into_dest: fn_span={0:?}",
fn_span) as &dyn Value))])
});
} else { ; }
};
this.cfg.terminate(block, source_info,
TerminatorKind::Call {
func: fun,
args,
unwind: UnwindAction::Continue,
destination,
target: Some(success),
call_source: if from_hir_call {
CallSource::Normal
} else { CallSource::OverloadedOperator },
fn_span,
});
this.diverge_from(block);
success.unit()
}
ExprKind::ByUse { expr, span } => {
let place =
{
let BlockAnd(b, v) = this.as_place(block, expr);
block = b;
v
};
let ty = place.ty(&this.local_decls, this.tcx).ty;
if this.tcx.type_is_copy_modulo_regions(this.infcx.typing_env(this.param_env),
ty) {
this.cfg.push_assign(block, source_info, destination,
Rvalue::Use(Operand::Copy(place), WithRetag::Yes));
block.unit()
} else if this.infcx.type_is_use_cloned_modulo_regions(this.param_env,
ty) {
let success = this.cfg.start_new_block();
let clone_trait =
this.tcx.require_lang_item(LangItem::Clone, span);
let clone_fn =
this.tcx.associated_item_def_ids(clone_trait)[0];
let func =
Operand::function_handle(this.tcx, clone_fn, [ty.into()],
expr_span);
let ref_ty =
Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty);
let ref_place = this.temp(ref_ty, span);
this.cfg.push_assign(block, source_info, ref_place,
Rvalue::Ref(this.tcx.lifetimes.re_erased,
BorrowKind::Shared, place));
this.cfg.terminate(block, source_info,
TerminatorKind::Call {
func,
args: [Spanned {
node: Operand::Move(ref_place),
span: DUMMY_SP,
}].into(),
destination,
target: Some(success),
unwind: UnwindAction::Unreachable,
call_source: CallSource::Use,
fn_span: expr_span,
});
success.unit()
} else {
this.cfg.push_assign(block, source_info, destination,
Rvalue::Use(Operand::Move(place), WithRetag::Yes));
block.unit()
}
}
ExprKind::Use { source } =>
this.expr_into_dest(destination, block, source),
ExprKind::Borrow { arg, borrow_kind } => {
let arg_place =
match borrow_kind {
BorrowKind::Shared => {
{
let BlockAnd(b, v) = this.as_read_only_place(block, arg);
block = b;
v
}
}
_ => {
let BlockAnd(b, v) = this.as_place(block, arg);
block = b;
v
}
};
let borrow =
Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind,
arg_place);
this.cfg.push_assign(block, source_info, destination,
borrow);
block.unit()
}
ExprKind::RawBorrow { mutability, arg } => {
let place =
match mutability {
hir::Mutability::Not => this.as_read_only_place(block, arg),
hir::Mutability::Mut => this.as_place(block, arg),
};
let address_of =
Rvalue::RawPtr(mutability.into(),
{ let BlockAnd(b, v) = place; block = b; v });
this.cfg.push_assign(block, source_info, destination,
address_of);
block.unit()
}
ExprKind::Adt(AdtExpr {
adt_def,
variant_index,
args,
ref user_ty,
ref fields,
ref base }) => {
let is_union = adt_def.is_union();
let active_field_index = is_union.then(|| fields[0].name);
let scope = this.local_temp_lifetime();
let fields_map: FxHashMap<_, _> =
fields.into_iter().map(|f|
{
(f.name,
{
let BlockAnd(b, v) =
this.as_operand(block, scope, f.expr,
LocalInfo::AggregateTemp, NeedsTemporary::Maybe);
block = b;
v
})
}).collect();
let variant = adt_def.variant(variant_index);
let field_names = variant.fields.indices();
let fields =
match base {
AdtExprBase::None => {
field_names.filter_map(|n|
fields_map.get(&n).cloned()).collect()
}
AdtExprBase::Base(FruInfo { base, field_types }) => {
let place_builder =
{
let BlockAnd(b, v) = this.as_place_builder(block, *base);
block = b;
v
};
itertools::zip_eq(field_names,
&**field_types).map(|(n, ty)|
match fields_map.get(&n) {
Some(v) => v.clone(),
None => {
let place =
place_builder.clone_project(PlaceElem::Field(n, *ty));
this.consume_by_copy_or_move(place.to_place(this))
}
}).collect()
}
AdtExprBase::DefaultFields(field_types) => {
itertools::zip_eq(field_names,
field_types).map(|(n, &ty)|
match fields_map.get(&n) {
Some(v) => v.clone(),
None =>
match variant.fields[n].value {
Some(def) => {
let value =
Const::Unevaluated(UnevaluatedConst::new(def, args), ty);
Operand::Constant(Box::new(ConstOperand {
span: expr_span,
user_ty: None,
const_: value,
}))
}
None => {
let name = variant.fields[n].name;
::rustc_middle::util::bug::span_bug_fmt(expr_span,
format_args!("missing mandatory field `{0}` of type `{1}`",
name, ty));
}
},
}).collect()
}
};
let inferred_ty = expr.ty;
let user_ty =
user_ty.as_ref().map(|user_ty|
{
this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
span: source_info.span,
user_ty: user_ty.clone(),
inferred_ty,
})
});
let adt =
Box::new(AggregateKind::Adt(adt_def.did(), variant_index,
args, user_ty, active_field_index));
this.cfg.push_assign(block, source_info, destination,
Rvalue::Aggregate(adt, fields));
block.unit()
}
ExprKind::InlineAsm(InlineAsmExpr {
asm_macro, template, ref operands, options, line_spans }) =>
{
use rustc_middle::{mir, thir};
let destination_block = this.cfg.start_new_block();
let mut targets =
if asm_macro.diverges(options) {
::alloc::vec::Vec::new()
} else {
::alloc::boxed::box_assume_init_into_vec_unsafe(::alloc::intrinsics::write_box_via_move(::alloc::boxed::Box::new_uninit(),
[destination_block]))
};
let operands =
operands.into_iter().map(|op|
match *op {
thir::InlineAsmOperand::In { reg, expr } =>
mir::InlineAsmOperand::In {
reg,
value: {
let BlockAnd(b, v) = this.as_local_operand(block, expr);
block = b;
v
},
},
thir::InlineAsmOperand::Out { reg, late, expr } => {
mir::InlineAsmOperand::Out {
reg,
late,
place: expr.map(|expr|
{
let BlockAnd(b, v) = this.as_place(block, expr);
block = b;
v
}),
}
}
thir::InlineAsmOperand::InOut { reg, late, expr } => {
let place =
{
let BlockAnd(b, v) = this.as_place(block, expr);
block = b;
v
};
mir::InlineAsmOperand::InOut {
reg,
late,
in_value: Operand::Copy(place),
out_place: Some(place),
}
}
thir::InlineAsmOperand::SplitInOut {
reg, late, in_expr, out_expr } => {
mir::InlineAsmOperand::InOut {
reg,
late,
in_value: {
let BlockAnd(b, v) = this.as_local_operand(block, in_expr);
block = b;
v
},
out_place: out_expr.map(|out_expr|
{
{
let BlockAnd(b, v) = this.as_place(block, out_expr);
block = b;
v
}
}),
}
}
thir::InlineAsmOperand::Const { value, span } => {
mir::InlineAsmOperand::Const {
value: Box::new(ConstOperand {
span,
user_ty: None,
const_: value,
}),
}
}
thir::InlineAsmOperand::SymFn { value } =>
mir::InlineAsmOperand::SymFn {
value: Box::new(this.as_constant(&this.thir[value])),
},
thir::InlineAsmOperand::SymStatic { def_id } => {
mir::InlineAsmOperand::SymStatic { def_id }
}
thir::InlineAsmOperand::Label { block } => {
let target = this.cfg.start_new_block();
let target_index = targets.len();
targets.push(target);
let tmp = this.get_unit_temp();
let target =
this.ast_block(tmp, target, block,
source_info).into_block();
this.cfg.terminate(target, source_info,
TerminatorKind::Goto { target: destination_block });
mir::InlineAsmOperand::Label { target_index }
}
}).collect();
if !expr.ty.is_never() {
this.cfg.push_assign_unit(block, source_info, destination,
this.tcx);
}
let asm_macro =
match asm_macro {
AsmMacro::Asm | AsmMacro::GlobalAsm => InlineAsmMacro::Asm,
AsmMacro::NakedAsm => InlineAsmMacro::NakedAsm,
};
this.cfg.terminate(block, source_info,
TerminatorKind::InlineAsm {
asm_macro,
template,
operands,
options,
line_spans,
targets: targets.into_boxed_slice(),
unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
UnwindAction::Continue
} else { UnwindAction::Unreachable },
});
if options.contains(InlineAsmOptions::MAY_UNWIND) {
this.diverge_from(block);
}
destination_block.unit()
}
ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
block = this.stmt_expr(block, expr_id, None).into_block();
this.cfg.push_assign_unit(block, source_info, destination,
this.tcx);
block.unit()
}
ExprKind::Continue { .. } | ExprKind::ConstContinue { .. } |
ExprKind::Break { .. } | ExprKind::Return { .. } |
ExprKind::Become { .. } => {
block = this.stmt_expr(block, expr_id, None).into_block();
block.unit()
}
ExprKind::VarRef { .. } | ExprKind::UpvarRef { .. } |
ExprKind::PlaceTypeAscription { .. } |
ExprKind::ValueTypeAscription { .. } |
ExprKind::PlaceUnwrapUnsafeBinder { .. } |
ExprKind::ValueUnwrapUnsafeBinder { .. } => {
if true {
if !(Category::of(&expr.kind) == Some(Category::Place)) {
::core::panicking::panic("assertion failed: Category::of(&expr.kind) == Some(Category::Place)")
};
};
let place =
{
let BlockAnd(b, v) = this.as_place(block, expr_id);
block = b;
v
};
let rvalue =
Rvalue::Use(this.consume_by_copy_or_move(place),
WithRetag::Yes);
this.cfg.push_assign(block, source_info, destination,
rvalue);
block.unit()
}
ExprKind::Index { .. } | ExprKind::Deref { .. } |
ExprKind::Field { .. } => {
if true {
match (&Category::of(&expr.kind), &Some(Category::Place)) {
(left_val, right_val) => {
if !(*left_val == *right_val) {
let kind = ::core::panicking::AssertKind::Eq;
::core::panicking::assert_failed(kind, &*left_val,
&*right_val, ::core::option::Option::None);
}
}
};
};
if !destination.projection.is_empty() {
this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
}
let place =
{
let BlockAnd(b, v) = this.as_place(block, expr_id);
block = b;
v
};
let rvalue =
Rvalue::Use(this.consume_by_copy_or_move(place),
WithRetag::Yes);
this.cfg.push_assign(block, source_info, destination,
rvalue);
block.unit()
}
ExprKind::Yield { value } => {
let scope = this.local_temp_lifetime();
let value =
{
let BlockAnd(b, v) =
this.as_operand(block, scope, value, LocalInfo::Boring,
NeedsTemporary::No);
block = b;
v
};
let resume = this.cfg.start_new_block();
this.cfg.terminate(block, source_info,
TerminatorKind::Yield {
value,
resume,
resume_arg: destination,
drop: None,
});
this.coroutine_drop_cleanup(block);
resume.unit()
}
ExprKind::Unary { .. } | ExprKind::Binary { .. } |
ExprKind::Cast { .. } | ExprKind::PointerCoercion { .. } |
ExprKind::Repeat { .. } | ExprKind::Array { .. } |
ExprKind::Tuple { .. } | ExprKind::Closure { .. } |
ExprKind::ConstBlock { .. } | ExprKind::Literal { .. } |
ExprKind::NamedConst { .. } | ExprKind::NonHirLiteral { .. }
| ExprKind::ZstLiteral { .. } | ExprKind::ConstParam { .. }
| ExprKind::ThreadLocalRef(_) | ExprKind::StaticRef { .. } |
ExprKind::WrapUnsafeBinder { .. } => {
if true {
if !match Category::of(&expr.kind).unwrap() {
Category::Rvalue(RvalueFunc::Into) => false,
Category::Place => false,
_ => true,
} {
::core::panicking::panic("assertion failed: match Category::of(&expr.kind).unwrap() {\n Category::Rvalue(RvalueFunc::Into) => false,\n Category::Place => false,\n _ => true,\n}")
};
};
let rvalue =
{
let BlockAnd(b, v) = this.as_local_rvalue(block, expr_id);
block = b;
v
};
this.cfg.push_assign(block, source_info, destination,
rvalue);
block.unit()
}
ExprKind::Reborrow { source, mutability, target } => {
let place =
{
let BlockAnd(b, v) = this.as_place(block, source);
block = b;
v
};
this.cfg.push_assign(block, source_info, destination,
Rvalue::Reborrow(target, mutability, place));
block.unit()
}
};
if !expr_is_block_or_scope {
let popped = this.block_context.pop();
if !popped.is_some() {
::core::panicking::panic("assertion failed: popped.is_some()")
};
}
block_and
}
}
}#[instrument(level = "debug", skip(self))]
27 pub(crate) fn expr_into_dest(
28 &mut self,
29 destination: Place<'tcx>,
30 mut block: BasicBlock,
31 expr_id: ExprId,
32 ) -> BlockAnd<()> {
33 let this = self; let expr = &this.thir[expr_id];
38 let expr_span = expr.span;
39 let source_info = this.source_info(expr_span);
40
41 let expr_is_block_or_scope =
42 matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. });
43
44 if !expr_is_block_or_scope {
45 this.block_context.push(BlockFrame::SubExpr);
46 }
47
48 let block_and = match expr.kind {
49 ExprKind::Scope { region_scope, hir_id, value } => {
50 let region_scope = (region_scope, source_info);
51 ensure_sufficient_stack(|| {
52 this.in_scope(region_scope, LintLevel::Explicit(hir_id), |this| {
53 this.expr_into_dest(destination, block, value)
54 })
55 })
56 }
57 ExprKind::Block { block: ast_block } => {
58 this.ast_block(destination, block, ast_block, source_info)
59 }
60 ExprKind::Match { scrutinee, ref arms, .. } => this.match_expr(
61 destination,
62 block,
63 scrutinee,
64 arms,
65 expr_span,
66 this.thir[scrutinee].span,
67 ),
68 ExprKind::If { cond, then, else_opt, if_then_scope } => {
69 let then_span = this.thir[then].span;
70 let then_source_info = this.source_info(then_span);
71 let condition_scope = this.local_scope();
72
73 let then_and_else_blocks = this.in_scope(
74 (if_then_scope, then_source_info),
75 LintLevel::Inherited,
76 |this| {
77 let source_info = if this.is_let(cond) {
79 let variable_scope =
80 this.new_source_scope(then_span, LintLevel::Inherited);
81 this.source_scope = variable_scope;
82 SourceInfo { span: then_span, scope: variable_scope }
83 } else {
84 this.source_info(then_span)
85 };
86
87 let (then_block, else_block) =
89 this.in_if_then_scope(condition_scope, then_span, |this| {
90 let then_blk = this
91 .then_else_break(
92 block,
93 cond,
94 Some(condition_scope), source_info,
96 DeclareLetBindings::Yes, )
98 .into_block();
99
100 this.expr_into_dest(destination, then_blk, then)
102 });
103
104 then_block.and(else_block)
106 },
107 );
108
109 let (then_blk, mut else_blk);
111 else_blk = unpack!(then_blk = then_and_else_blocks);
112
113 if let Some(else_expr) = else_opt {
115 else_blk = this.expr_into_dest(destination, else_blk, else_expr).into_block();
116 } else {
117 let correct_si = this.source_info(expr_span.shrink_to_hi());
120 this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx);
121 }
122
123 let join_block = this.cfg.start_new_block();
126 this.cfg.goto(then_blk, source_info, join_block);
127 this.cfg.goto(else_blk, source_info, join_block);
128 join_block.unit()
129 }
130 ExprKind::Let { .. } => {
131 span_bug!(expr_span, "unexpected let expression outside of if or match-guard");
136 }
137 ExprKind::NeverToAny { source } => {
138 let source_expr = &this.thir[source];
139 let is_call =
140 matches!(source_expr.kind, ExprKind::Call { .. } | ExprKind::InlineAsm { .. });
141
142 unpack!(
145 block =
146 this.as_temp(block, this.local_temp_lifetime(), source, Mutability::Mut)
147 );
148
149 if is_call {
152 block.unit()
153 } else {
154 this.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
155 let end_block = this.cfg.start_new_block();
156 end_block.unit()
157 }
158 }
159 ExprKind::LogicalOp { op, lhs, rhs } => {
160 let condition_scope = this.local_scope();
161 let source_info = this.source_info(expr.span);
162
163 let (then_block, else_block) =
165 this.in_if_then_scope(condition_scope, expr.span, |this| {
166 this.then_else_break(
167 block,
168 lhs,
169 Some(condition_scope), source_info,
171 DeclareLetBindings::LetNotPermitted,
174 )
175 });
176 let (short_circuit, continuation, constant) = match op {
177 LogicalOp::And => (else_block, then_block, false),
178 LogicalOp::Or => (then_block, else_block, true),
179 };
180 this.cfg.push_assign_constant(
187 short_circuit,
188 source_info,
189 destination,
190 ConstOperand {
191 span: expr.span,
192 user_ty: None,
193 const_: Const::from_bool(this.tcx, constant),
194 },
195 );
196 let mut rhs_block =
197 this.expr_into_dest(destination, continuation, rhs).into_block();
198 this.visit_coverage_standalone_condition(rhs, destination, &mut rhs_block);
201
202 let target = this.cfg.start_new_block();
203 this.cfg.goto(rhs_block, source_info, target);
204 this.cfg.goto(short_circuit, source_info, target);
205 target.unit()
206 }
207 ExprKind::Loop { body } => {
208 let loop_block = this.cfg.start_new_block();
219
220 this.cfg.goto(block, source_info, loop_block);
222
223 this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| {
224 let body_block = this.cfg.start_new_block();
226 this.cfg.terminate(
227 loop_block,
228 source_info,
229 TerminatorKind::FalseUnwind {
230 real_target: body_block,
231 unwind: UnwindAction::Continue,
232 },
233 );
234 this.diverge_from(loop_block);
235
236 let tmp = this.get_unit_temp();
239 let body_block_end = this.expr_into_dest(tmp, body_block, body).into_block();
241
242 let goto = this.cfg.goto(body_block_end, source_info, loop_block);
243 if let Some(attrs) = this.thir.attributes.get(&expr_id) {
244 goto.attributes = attrs.clone();
245 }
246
247 None
249 })
250 }
251 ExprKind::LoopMatch {
252 state,
253 region_scope,
254 match_data: LoopMatchMatchData { ref arms, span: match_span, scrutinee },
255 } => {
256 fn is_supported_loop_match_type(ty: Ty<'_>) -> bool {
264 match ty.kind() {
265 ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Bool | ty::Char => true,
266 ty::Adt(adt_def, _) => match adt_def.adt_kind() {
267 ty::AdtKind::Struct | ty::AdtKind::Union => false,
268 ty::AdtKind::Enum => {
269 adt_def.variants().iter().all(|v| v.fields.is_empty())
270 }
271 },
272 _ => false,
273 }
274 }
275
276 let state_ty = this.thir.exprs[state].ty;
277 if !is_supported_loop_match_type(state_ty) {
278 let span = this.thir.exprs[state].span;
279 this.tcx.dcx().emit_fatal(LoopMatchUnsupportedType { span, ty: state_ty })
280 }
281
282 let loop_block = this.cfg.start_new_block();
283
284 this.cfg.goto(block, source_info, loop_block);
286
287 this.in_breakable_scope(Some(loop_block), destination, expr_span, |this| {
288 let mut body_block = this.cfg.start_new_block();
290 this.cfg.terminate(
291 loop_block,
292 source_info,
293 TerminatorKind::FalseUnwind {
294 real_target: body_block,
295 unwind: UnwindAction::Continue,
296 },
297 );
298 this.diverge_from(loop_block);
299
300 let scrutinee_span = this.thir.exprs[scrutinee].span;
302 let scrutinee_place_builder = unpack!(
303 body_block = this.lower_scrutinee(body_block, scrutinee, scrutinee_span)
304 );
305
306 let match_start_span = match_span.shrink_to_lo().to(scrutinee_span);
307
308 let mut patterns = Vec::with_capacity(arms.len());
309 for &arm_id in arms.iter() {
310 let arm = &this.thir[arm_id];
311
312 if let Some(guard) = arm.guard {
313 let span = this.thir.exprs[guard].span;
314 this.tcx.dcx().emit_fatal(LoopMatchArmWithGuard { span })
315 }
316
317 patterns.push((&*arm.pattern, HasMatchGuard::No));
318 }
319
320 let built_tree = this.lower_match_tree(
324 body_block,
325 scrutinee_span,
326 &scrutinee_place_builder,
327 match_start_span,
328 patterns,
329 Exhaustive::Yes,
330 );
331
332 let state_place = scrutinee_place_builder.to_place(this);
333 let state_result = this.temp(state_ty, expr_span);
334 let state_result_place = Place::from(state_result);
335
336 unpack!(
349 body_block = this.in_scope(
350 (region_scope, source_info),
351 LintLevel::Inherited,
352 move |this| {
353 this.in_const_continuable_scope(
354 arms.clone(),
355 built_tree.clone(),
356 state_place,
357 expr_span,
358 |this| {
359 let block = this
360 .in_breakable_scope(
361 None,
362 state_result_place,
363 expr_span,
364 |this| {
365 Some(this.lower_match_arms(
366 state_result_place,
367 scrutinee_place_builder,
368 scrutinee_span,
369 arms,
370 built_tree,
371 this.source_info(match_span),
372 ))
373 },
374 )
375 .into_block();
376
377 this.cfg.push_assign(
378 block,
379 source_info,
380 state_place,
381 Rvalue::Use(
382 this.consume_by_copy_or_move(state_result_place),
383 WithRetag::Yes,
384 ),
385 );
386 block.unit()
387 },
388 )
389 }
390 )
391 );
392
393 this.cfg.goto(body_block, source_info, loop_block);
394
395 None
397 })
398 }
399 ExprKind::Call { ty, fun, ref args, .. }
402 if let ty::FnDef(def_id, generic_args) = *ty.kind()
403 && let Some(intrinsic) = this.tcx.intrinsic(def_id)
404 && matches!(intrinsic.name, sym::write_via_move | sym::write_box_via_move) =>
405 {
406 let _fun = unpack!(block = this.as_local_operand(block, fun));
409
410 match intrinsic.name {
411 sym::write_via_move => {
412 assert!(destination.ty(&this.local_decls, this.tcx).ty.is_unit());
417
418 let [ptr, val] = **args else {
420 span_bug!(expr_span, "invalid write_via_move call")
421 };
422 let Some(ptr) = unpack!(block = this.as_local_operand(block, ptr)).place()
423 else {
424 span_bug!(expr_span, "invalid write_via_move call")
425 };
426 let ptr_deref = ptr.project_deeper(&[ProjectionElem::Deref], this.tcx);
427 this.expr_into_dest(ptr_deref, block, val)
428 }
429 sym::write_box_via_move => {
430 let [b, val] = **args else {
444 span_bug!(expr_span, "invalid init_box_via_move call")
445 };
446 let Some(b) = unpack!(block = this.as_local_operand(block, b)).place()
447 else {
448 span_bug!(expr_span, "invalid init_box_via_move call")
449 };
450 let tcx = this.tcx;
451 let decls = &this.local_decls;
452
453 let place = b.project_deeper(&[ProjectionElem::Deref], tcx);
455 let place = place.project_to_field(FieldIdx::from_u32(1), decls, tcx);
457 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
459 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
461 assert_eq!(place.ty(decls, tcx).ty, generic_args.type_at(0));
463
464 unpack!(block = this.expr_into_dest(place, block, val));
466
467 this.cfg.push_assign(
469 block,
470 source_info,
471 destination,
472 Rvalue::Use(Operand::Move(b), WithRetag::Yes),
474 );
475 block.unit()
476 }
477 _ => rustc_middle::bug!(),
478 }
479 }
480 ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => {
481 let fun = unpack!(block = this.as_local_operand(block, fun));
482 let args: Box<[_]> = args
483 .into_iter()
484 .copied()
485 .map(|arg| Spanned {
486 node: unpack!(block = this.as_local_call_operand(block, arg)),
487 span: this.thir.exprs[arg].span,
488 })
489 .collect();
490
491 let success = this.cfg.start_new_block();
492
493 this.record_operands_moved(&args);
494
495 debug!("expr_into_dest: fn_span={:?}", fn_span);
496
497 this.cfg.terminate(
498 block,
499 source_info,
500 TerminatorKind::Call {
501 func: fun,
502 args,
503 unwind: UnwindAction::Continue,
504 destination,
505 target: Some(success),
506 call_source: if from_hir_call {
507 CallSource::Normal
508 } else {
509 CallSource::OverloadedOperator
510 },
511 fn_span,
512 },
513 );
514 this.diverge_from(block);
515 success.unit()
516 }
517 ExprKind::ByUse { expr, span } => {
518 let place = unpack!(block = this.as_place(block, expr));
519 let ty = place.ty(&this.local_decls, this.tcx).ty;
520
521 if this.tcx.type_is_copy_modulo_regions(this.infcx.typing_env(this.param_env), ty) {
522 this.cfg.push_assign(
523 block,
524 source_info,
525 destination,
526 Rvalue::Use(Operand::Copy(place), WithRetag::Yes),
527 );
528 block.unit()
529 } else if this.infcx.type_is_use_cloned_modulo_regions(this.param_env, ty) {
530 let success = this.cfg.start_new_block();
532 let clone_trait = this.tcx.require_lang_item(LangItem::Clone, span);
533 let clone_fn = this.tcx.associated_item_def_ids(clone_trait)[0];
534 let func = Operand::function_handle(this.tcx, clone_fn, [ty.into()], expr_span);
535 let ref_ty = Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty);
536 let ref_place = this.temp(ref_ty, span);
537 this.cfg.push_assign(
538 block,
539 source_info,
540 ref_place,
541 Rvalue::Ref(this.tcx.lifetimes.re_erased, BorrowKind::Shared, place),
542 );
543 this.cfg.terminate(
544 block,
545 source_info,
546 TerminatorKind::Call {
547 func,
548 args: [Spanned { node: Operand::Move(ref_place), span: DUMMY_SP }]
549 .into(),
550 destination,
551 target: Some(success),
552 unwind: UnwindAction::Unreachable,
553 call_source: CallSource::Use,
554 fn_span: expr_span,
555 },
556 );
557 success.unit()
558 } else {
559 this.cfg.push_assign(
560 block,
561 source_info,
562 destination,
563 Rvalue::Use(Operand::Move(place), WithRetag::Yes),
564 );
565 block.unit()
566 }
567 }
568 ExprKind::Use { source } => this.expr_into_dest(destination, block, source),
569 ExprKind::Borrow { arg, borrow_kind } => {
570 let arg_place = match borrow_kind {
576 BorrowKind::Shared => {
577 unpack!(block = this.as_read_only_place(block, arg))
578 }
579 _ => unpack!(block = this.as_place(block, arg)),
580 };
581 let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place);
582 this.cfg.push_assign(block, source_info, destination, borrow);
583 block.unit()
584 }
585 ExprKind::RawBorrow { mutability, arg } => {
586 let place = match mutability {
587 hir::Mutability::Not => this.as_read_only_place(block, arg),
588 hir::Mutability::Mut => this.as_place(block, arg),
589 };
590 let address_of = Rvalue::RawPtr(mutability.into(), unpack!(block = place));
591 this.cfg.push_assign(block, source_info, destination, address_of);
592 block.unit()
593 }
594 ExprKind::Adt(AdtExpr {
595 adt_def,
596 variant_index,
597 args,
598 ref user_ty,
599 ref fields,
600 ref base,
601 }) => {
602 let is_union = adt_def.is_union();
605 let active_field_index = is_union.then(|| fields[0].name);
606
607 let scope = this.local_temp_lifetime();
608
609 let fields_map: FxHashMap<_, _> = fields
612 .into_iter()
613 .map(|f| {
614 (
615 f.name,
616 unpack!(
617 block = this.as_operand(
618 block,
619 scope,
620 f.expr,
621 LocalInfo::AggregateTemp,
622 NeedsTemporary::Maybe,
623 )
624 ),
625 )
626 })
627 .collect();
628
629 let variant = adt_def.variant(variant_index);
630 let field_names = variant.fields.indices();
631
632 let fields = match base {
633 AdtExprBase::None => {
634 field_names.filter_map(|n| fields_map.get(&n).cloned()).collect()
635 }
636 AdtExprBase::Base(FruInfo { base, field_types }) => {
637 let place_builder = unpack!(block = this.as_place_builder(block, *base));
638
639 itertools::zip_eq(field_names, &**field_types)
643 .map(|(n, ty)| match fields_map.get(&n) {
644 Some(v) => v.clone(),
645 None => {
646 let place =
647 place_builder.clone_project(PlaceElem::Field(n, *ty));
648 this.consume_by_copy_or_move(place.to_place(this))
649 }
650 })
651 .collect()
652 }
653 AdtExprBase::DefaultFields(field_types) => {
654 itertools::zip_eq(field_names, field_types)
655 .map(|(n, &ty)| match fields_map.get(&n) {
656 Some(v) => v.clone(),
657 None => match variant.fields[n].value {
658 Some(def) => {
659 let value = Const::Unevaluated(
660 UnevaluatedConst::new(def, args),
661 ty,
662 );
663 Operand::Constant(Box::new(ConstOperand {
664 span: expr_span,
665 user_ty: None,
666 const_: value,
667 }))
668 }
669 None => {
670 let name = variant.fields[n].name;
671 span_bug!(
672 expr_span,
673 "missing mandatory field `{name}` of type `{ty}`",
674 );
675 }
676 },
677 })
678 .collect()
679 }
680 };
681
682 let inferred_ty = expr.ty;
683 let user_ty = user_ty.as_ref().map(|user_ty| {
684 this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
685 span: source_info.span,
686 user_ty: user_ty.clone(),
687 inferred_ty,
688 })
689 });
690 let adt = Box::new(AggregateKind::Adt(
691 adt_def.did(),
692 variant_index,
693 args,
694 user_ty,
695 active_field_index,
696 ));
697 this.cfg.push_assign(
698 block,
699 source_info,
700 destination,
701 Rvalue::Aggregate(adt, fields),
702 );
703 block.unit()
704 }
705 ExprKind::InlineAsm(InlineAsmExpr {
706 asm_macro,
707 template,
708 ref operands,
709 options,
710 line_spans,
711 }) => {
712 use rustc_middle::{mir, thir};
713
714 let destination_block = this.cfg.start_new_block();
715 let mut targets =
716 if asm_macro.diverges(options) { vec![] } else { vec![destination_block] };
717
718 let operands = operands
719 .into_iter()
720 .map(|op| match *op {
721 thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In {
722 reg,
723 value: unpack!(block = this.as_local_operand(block, expr)),
724 },
725 thir::InlineAsmOperand::Out { reg, late, expr } => {
726 mir::InlineAsmOperand::Out {
727 reg,
728 late,
729 place: expr.map(|expr| unpack!(block = this.as_place(block, expr))),
730 }
731 }
732 thir::InlineAsmOperand::InOut { reg, late, expr } => {
733 let place = unpack!(block = this.as_place(block, expr));
734 mir::InlineAsmOperand::InOut {
735 reg,
736 late,
737 in_value: Operand::Copy(place),
739 out_place: Some(place),
740 }
741 }
742 thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => {
743 mir::InlineAsmOperand::InOut {
744 reg,
745 late,
746 in_value: unpack!(block = this.as_local_operand(block, in_expr)),
747 out_place: out_expr.map(|out_expr| {
748 unpack!(block = this.as_place(block, out_expr))
749 }),
750 }
751 }
752 thir::InlineAsmOperand::Const { value, span } => {
753 mir::InlineAsmOperand::Const {
754 value: Box::new(ConstOperand {
755 span,
756 user_ty: None,
757 const_: value,
758 }),
759 }
760 }
761 thir::InlineAsmOperand::SymFn { value } => mir::InlineAsmOperand::SymFn {
762 value: Box::new(this.as_constant(&this.thir[value])),
763 },
764 thir::InlineAsmOperand::SymStatic { def_id } => {
765 mir::InlineAsmOperand::SymStatic { def_id }
766 }
767 thir::InlineAsmOperand::Label { block } => {
768 let target = this.cfg.start_new_block();
769 let target_index = targets.len();
770 targets.push(target);
771
772 let tmp = this.get_unit_temp();
773 let target =
774 this.ast_block(tmp, target, block, source_info).into_block();
775 this.cfg.terminate(
776 target,
777 source_info,
778 TerminatorKind::Goto { target: destination_block },
779 );
780
781 mir::InlineAsmOperand::Label { target_index }
782 }
783 })
784 .collect();
785
786 if !expr.ty.is_never() {
787 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
788 }
789
790 let asm_macro = match asm_macro {
791 AsmMacro::Asm | AsmMacro::GlobalAsm => InlineAsmMacro::Asm,
792 AsmMacro::NakedAsm => InlineAsmMacro::NakedAsm,
793 };
794
795 this.cfg.terminate(
796 block,
797 source_info,
798 TerminatorKind::InlineAsm {
799 asm_macro,
800 template,
801 operands,
802 options,
803 line_spans,
804 targets: targets.into_boxed_slice(),
805 unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
806 UnwindAction::Continue
807 } else {
808 UnwindAction::Unreachable
809 },
810 },
811 );
812 if options.contains(InlineAsmOptions::MAY_UNWIND) {
813 this.diverge_from(block);
814 }
815 destination_block.unit()
816 }
817
818 ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
820 block = this.stmt_expr(block, expr_id, None).into_block();
821 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
822 block.unit()
823 }
824
825 ExprKind::Continue { .. }
826 | ExprKind::ConstContinue { .. }
827 | ExprKind::Break { .. }
828 | ExprKind::Return { .. }
829 | ExprKind::Become { .. } => {
830 block = this.stmt_expr(block, expr_id, None).into_block();
831 block.unit()
833 }
834
835 ExprKind::VarRef { .. }
837 | ExprKind::UpvarRef { .. }
838 | ExprKind::PlaceTypeAscription { .. }
839 | ExprKind::ValueTypeAscription { .. }
840 | ExprKind::PlaceUnwrapUnsafeBinder { .. }
841 | ExprKind::ValueUnwrapUnsafeBinder { .. } => {
842 debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
843
844 let place = unpack!(block = this.as_place(block, expr_id));
845 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place), WithRetag::Yes);
846 this.cfg.push_assign(block, source_info, destination, rvalue);
847 block.unit()
848 }
849 ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
850 debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));
851
852 if !destination.projection.is_empty() {
856 this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
857 }
858
859 let place = unpack!(block = this.as_place(block, expr_id));
860 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place), WithRetag::Yes);
861 this.cfg.push_assign(block, source_info, destination, rvalue);
862 block.unit()
863 }
864
865 ExprKind::Yield { value } => {
866 let scope = this.local_temp_lifetime();
867 let value = unpack!(
868 block =
869 this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
870 );
871 let resume = this.cfg.start_new_block();
872 this.cfg.terminate(
873 block,
874 source_info,
875 TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
876 );
877 this.coroutine_drop_cleanup(block);
878 resume.unit()
879 }
880
881 ExprKind::Unary { .. }
883 | ExprKind::Binary { .. }
884 | ExprKind::Cast { .. }
885 | ExprKind::PointerCoercion { .. }
886 | ExprKind::Repeat { .. }
887 | ExprKind::Array { .. }
888 | ExprKind::Tuple { .. }
889 | ExprKind::Closure { .. }
890 | ExprKind::ConstBlock { .. }
891 | ExprKind::Literal { .. }
892 | ExprKind::NamedConst { .. }
893 | ExprKind::NonHirLiteral { .. }
894 | ExprKind::ZstLiteral { .. }
895 | ExprKind::ConstParam { .. }
896 | ExprKind::ThreadLocalRef(_)
897 | ExprKind::StaticRef { .. }
898 | ExprKind::WrapUnsafeBinder { .. } => {
899 debug_assert!(match Category::of(&expr.kind).unwrap() {
900 Category::Rvalue(RvalueFunc::Into) => false,
902
903 Category::Place => false,
907
908 _ => true,
909 });
910
911 let rvalue = unpack!(block = this.as_local_rvalue(block, expr_id));
912 this.cfg.push_assign(block, source_info, destination, rvalue);
913 block.unit()
914 }
915 ExprKind::Reborrow { source, mutability, target } => {
916 let place = unpack!(block = this.as_place(block, source));
917 this.cfg.push_assign(
918 block,
919 source_info,
920 destination,
921 Rvalue::Reborrow(target, mutability, place),
922 );
923 block.unit()
924 }
925 };
926
927 if !expr_is_block_or_scope {
928 let popped = this.block_context.pop();
929 assert!(popped.is_some());
930 }
931
932 block_and
933 }
934
935 fn is_let(&self, expr: ExprId) -> bool {
936 match self.thir[expr].kind {
937 ExprKind::Let { .. } => true,
938 ExprKind::Scope { value, .. } => self.is_let(value),
939 _ => false,
940 }
941 }
942}