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::source_map::Spanned;
14use rustc_span::{DUMMY_SP, sym};
15use rustc_trait_selection::infer::InferCtxtExt;
16use tracing::{debug, instrument};
17
18use crate::builder::expr::category::{Category, RvalueFunc};
19use crate::builder::matches::{DeclareLetBindings, HasMatchGuard};
20use crate::builder::scope::LintLevel;
21use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, NeedsTemporary};
22use crate::errors::{LoopMatchArmWithGuard, LoopMatchUnsupportedType};
23
24impl<'a, 'tcx> Builder<'a, 'tcx> {
25 #[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(27u32),
::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();
this.cfg.goto(body_block_end, source_info, loop_block);
None
})
}
ExprKind::LoopMatch {
state,
region_scope,
match_data: box LoopMatchMatchData {
box 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,
false);
let state_place = scrutinee_place_builder.to_place(this);
{
let BlockAnd(b, v) =
this.in_scope((region_scope, source_info),
LintLevel::Inherited,
move |this|
{
this.in_breakable_scope(None, state_place, expr_span,
|this|
{
Some(this.in_const_continuable_scope(Box::from(arms),
built_tree.clone(), state_place, expr_span,
|this|
{
this.lower_match_arms(state_place, scrutinee_place_builder,
scrutinee_span, arms, built_tree,
this.source_info(match_span))
}))
})
});
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)));
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:466",
"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(466u32),
::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)));
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)));
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(box 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(box 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));
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));
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()
}
};
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))]
28 pub(crate) fn expr_into_dest(
29 &mut self,
30 destination: Place<'tcx>,
31 mut block: BasicBlock,
32 expr_id: ExprId,
33 ) -> BlockAnd<()> {
34 let this = self; let expr = &this.thir[expr_id];
39 let expr_span = expr.span;
40 let source_info = this.source_info(expr_span);
41
42 let expr_is_block_or_scope =
43 matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. });
44
45 if !expr_is_block_or_scope {
46 this.block_context.push(BlockFrame::SubExpr);
47 }
48
49 let block_and = match expr.kind {
50 ExprKind::Scope { region_scope, hir_id, value } => {
51 let region_scope = (region_scope, source_info);
52 ensure_sufficient_stack(|| {
53 this.in_scope(region_scope, LintLevel::Explicit(hir_id), |this| {
54 this.expr_into_dest(destination, block, value)
55 })
56 })
57 }
58 ExprKind::Block { block: ast_block } => {
59 this.ast_block(destination, block, ast_block, source_info)
60 }
61 ExprKind::Match { scrutinee, ref arms, .. } => this.match_expr(
62 destination,
63 block,
64 scrutinee,
65 arms,
66 expr_span,
67 this.thir[scrutinee].span,
68 ),
69 ExprKind::If { cond, then, else_opt, if_then_scope } => {
70 let then_span = this.thir[then].span;
71 let then_source_info = this.source_info(then_span);
72 let condition_scope = this.local_scope();
73
74 let then_and_else_blocks = this.in_scope(
75 (if_then_scope, then_source_info),
76 LintLevel::Inherited,
77 |this| {
78 let source_info = if this.is_let(cond) {
80 let variable_scope =
81 this.new_source_scope(then_span, LintLevel::Inherited);
82 this.source_scope = variable_scope;
83 SourceInfo { span: then_span, scope: variable_scope }
84 } else {
85 this.source_info(then_span)
86 };
87
88 let (then_block, else_block) =
90 this.in_if_then_scope(condition_scope, then_span, |this| {
91 let then_blk = this
92 .then_else_break(
93 block,
94 cond,
95 Some(condition_scope), source_info,
97 DeclareLetBindings::Yes, )
99 .into_block();
100
101 this.expr_into_dest(destination, then_blk, then)
103 });
104
105 then_block.and(else_block)
107 },
108 );
109
110 let (then_blk, mut else_blk);
112 else_blk = unpack!(then_blk = then_and_else_blocks);
113
114 if let Some(else_expr) = else_opt {
116 else_blk = this.expr_into_dest(destination, else_blk, else_expr).into_block();
117 } else {
118 let correct_si = this.source_info(expr_span.shrink_to_hi());
121 this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx);
122 }
123
124 let join_block = this.cfg.start_new_block();
127 this.cfg.goto(then_blk, source_info, join_block);
128 this.cfg.goto(else_blk, source_info, join_block);
129 join_block.unit()
130 }
131 ExprKind::Let { .. } => {
132 span_bug!(expr_span, "unexpected let expression outside of if or match-guard");
137 }
138 ExprKind::NeverToAny { source } => {
139 let source_expr = &this.thir[source];
140 let is_call =
141 matches!(source_expr.kind, ExprKind::Call { .. } | ExprKind::InlineAsm { .. });
142
143 unpack!(
146 block =
147 this.as_temp(block, this.local_temp_lifetime(), source, Mutability::Mut)
148 );
149
150 if is_call {
153 block.unit()
154 } else {
155 this.cfg.terminate(block, source_info, TerminatorKind::Unreachable);
156 let end_block = this.cfg.start_new_block();
157 end_block.unit()
158 }
159 }
160 ExprKind::LogicalOp { op, lhs, rhs } => {
161 let condition_scope = this.local_scope();
162 let source_info = this.source_info(expr.span);
163
164 let (then_block, else_block) =
166 this.in_if_then_scope(condition_scope, expr.span, |this| {
167 this.then_else_break(
168 block,
169 lhs,
170 Some(condition_scope), source_info,
172 DeclareLetBindings::LetNotPermitted,
175 )
176 });
177 let (short_circuit, continuation, constant) = match op {
178 LogicalOp::And => (else_block, then_block, false),
179 LogicalOp::Or => (then_block, else_block, true),
180 };
181 this.cfg.push_assign_constant(
188 short_circuit,
189 source_info,
190 destination,
191 ConstOperand {
192 span: expr.span,
193 user_ty: None,
194 const_: Const::from_bool(this.tcx, constant),
195 },
196 );
197 let mut rhs_block =
198 this.expr_into_dest(destination, continuation, rhs).into_block();
199 this.visit_coverage_standalone_condition(rhs, destination, &mut rhs_block);
202
203 let target = this.cfg.start_new_block();
204 this.cfg.goto(rhs_block, source_info, target);
205 this.cfg.goto(short_circuit, source_info, target);
206 target.unit()
207 }
208 ExprKind::Loop { body } => {
209 let loop_block = this.cfg.start_new_block();
220
221 this.cfg.goto(block, source_info, loop_block);
223
224 this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| {
225 let body_block = this.cfg.start_new_block();
227 this.cfg.terminate(
228 loop_block,
229 source_info,
230 TerminatorKind::FalseUnwind {
231 real_target: body_block,
232 unwind: UnwindAction::Continue,
233 },
234 );
235 this.diverge_from(loop_block);
236
237 let tmp = this.get_unit_temp();
240 let body_block_end = this.expr_into_dest(tmp, body_block, body).into_block();
242 this.cfg.goto(body_block_end, source_info, loop_block);
243
244 None
246 })
247 }
248 ExprKind::LoopMatch {
249 state,
250 region_scope,
251 match_data: box LoopMatchMatchData { box ref arms, span: match_span, scrutinee },
252 } => {
253 fn is_supported_loop_match_type(ty: Ty<'_>) -> bool {
261 match ty.kind() {
262 ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Bool | ty::Char => true,
263 ty::Adt(adt_def, _) => match adt_def.adt_kind() {
264 ty::AdtKind::Struct | ty::AdtKind::Union => false,
265 ty::AdtKind::Enum => {
266 adt_def.variants().iter().all(|v| v.fields.is_empty())
267 }
268 },
269 _ => false,
270 }
271 }
272
273 let state_ty = this.thir.exprs[state].ty;
274 if !is_supported_loop_match_type(state_ty) {
275 let span = this.thir.exprs[state].span;
276 this.tcx.dcx().emit_fatal(LoopMatchUnsupportedType { span, ty: state_ty })
277 }
278
279 let loop_block = this.cfg.start_new_block();
280
281 this.cfg.goto(block, source_info, loop_block);
283
284 this.in_breakable_scope(Some(loop_block), destination, expr_span, |this| {
285 let mut body_block = this.cfg.start_new_block();
287 this.cfg.terminate(
288 loop_block,
289 source_info,
290 TerminatorKind::FalseUnwind {
291 real_target: body_block,
292 unwind: UnwindAction::Continue,
293 },
294 );
295 this.diverge_from(loop_block);
296
297 let scrutinee_span = this.thir.exprs[scrutinee].span;
299 let scrutinee_place_builder = unpack!(
300 body_block = this.lower_scrutinee(body_block, scrutinee, scrutinee_span)
301 );
302
303 let match_start_span = match_span.shrink_to_lo().to(scrutinee_span);
304
305 let mut patterns = Vec::with_capacity(arms.len());
306 for &arm_id in arms.iter() {
307 let arm = &this.thir[arm_id];
308
309 if let Some(guard) = arm.guard {
310 let span = this.thir.exprs[guard].span;
311 this.tcx.dcx().emit_fatal(LoopMatchArmWithGuard { span })
312 }
313
314 patterns.push((&*arm.pattern, HasMatchGuard::No));
315 }
316
317 let built_tree = this.lower_match_tree(
321 body_block,
322 scrutinee_span,
323 &scrutinee_place_builder,
324 match_start_span,
325 patterns,
326 false,
327 );
328
329 let state_place = scrutinee_place_builder.to_place(this);
330
331 unpack!(
338 body_block = this.in_scope(
339 (region_scope, source_info),
340 LintLevel::Inherited,
341 move |this| {
342 this.in_breakable_scope(None, state_place, expr_span, |this| {
343 Some(this.in_const_continuable_scope(
344 Box::from(arms),
345 built_tree.clone(),
346 state_place,
347 expr_span,
348 |this| {
349 this.lower_match_arms(
350 state_place,
351 scrutinee_place_builder,
352 scrutinee_span,
353 arms,
354 built_tree,
355 this.source_info(match_span),
356 )
357 },
358 ))
359 })
360 }
361 )
362 );
363
364 this.cfg.goto(body_block, source_info, loop_block);
365
366 None
368 })
369 }
370 ExprKind::Call { ty, fun, ref args, .. }
373 if let ty::FnDef(def_id, generic_args) = ty.kind()
374 && let Some(intrinsic) = this.tcx.intrinsic(def_id)
375 && matches!(intrinsic.name, sym::write_via_move | sym::write_box_via_move) =>
376 {
377 let _fun = unpack!(block = this.as_local_operand(block, fun));
380
381 match intrinsic.name {
382 sym::write_via_move => {
383 assert!(destination.ty(&this.local_decls, this.tcx).ty.is_unit());
388
389 let [ptr, val] = **args else {
391 span_bug!(expr_span, "invalid write_via_move call")
392 };
393 let Some(ptr) = unpack!(block = this.as_local_operand(block, ptr)).place()
394 else {
395 span_bug!(expr_span, "invalid write_via_move call")
396 };
397 let ptr_deref = ptr.project_deeper(&[ProjectionElem::Deref], this.tcx);
398 this.expr_into_dest(ptr_deref, block, val)
399 }
400 sym::write_box_via_move => {
401 let [b, val] = **args else {
415 span_bug!(expr_span, "invalid init_box_via_move call")
416 };
417 let Some(b) = unpack!(block = this.as_local_operand(block, b)).place()
418 else {
419 span_bug!(expr_span, "invalid init_box_via_move call")
420 };
421 let tcx = this.tcx;
422 let decls = &this.local_decls;
423
424 let place = b.project_deeper(&[ProjectionElem::Deref], tcx);
426 let place = place.project_to_field(FieldIdx::from_u32(1), decls, tcx);
428 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
430 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
432 assert_eq!(place.ty(decls, tcx).ty, generic_args.type_at(0));
434
435 unpack!(block = this.expr_into_dest(place, block, val));
437
438 this.cfg.push_assign(
440 block,
441 source_info,
442 destination,
443 Rvalue::Use(Operand::Move(b)),
445 );
446 block.unit()
447 }
448 _ => rustc_middle::bug!(),
449 }
450 }
451 ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => {
452 let fun = unpack!(block = this.as_local_operand(block, fun));
453 let args: Box<[_]> = args
454 .into_iter()
455 .copied()
456 .map(|arg| Spanned {
457 node: unpack!(block = this.as_local_call_operand(block, arg)),
458 span: this.thir.exprs[arg].span,
459 })
460 .collect();
461
462 let success = this.cfg.start_new_block();
463
464 this.record_operands_moved(&args);
465
466 debug!("expr_into_dest: fn_span={:?}", fn_span);
467
468 this.cfg.terminate(
469 block,
470 source_info,
471 TerminatorKind::Call {
472 func: fun,
473 args,
474 unwind: UnwindAction::Continue,
475 destination,
476 target: Some(success),
477 call_source: if from_hir_call {
478 CallSource::Normal
479 } else {
480 CallSource::OverloadedOperator
481 },
482 fn_span,
483 },
484 );
485 this.diverge_from(block);
486 success.unit()
487 }
488 ExprKind::ByUse { expr, span } => {
489 let place = unpack!(block = this.as_place(block, expr));
490 let ty = place.ty(&this.local_decls, this.tcx).ty;
491
492 if this.tcx.type_is_copy_modulo_regions(this.infcx.typing_env(this.param_env), ty) {
493 this.cfg.push_assign(
494 block,
495 source_info,
496 destination,
497 Rvalue::Use(Operand::Copy(place)),
498 );
499 block.unit()
500 } else if this.infcx.type_is_use_cloned_modulo_regions(this.param_env, ty) {
501 let success = this.cfg.start_new_block();
503 let clone_trait = this.tcx.require_lang_item(LangItem::Clone, span);
504 let clone_fn = this.tcx.associated_item_def_ids(clone_trait)[0];
505 let func = Operand::function_handle(this.tcx, clone_fn, [ty.into()], expr_span);
506 let ref_ty = Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty);
507 let ref_place = this.temp(ref_ty, span);
508 this.cfg.push_assign(
509 block,
510 source_info,
511 ref_place,
512 Rvalue::Ref(this.tcx.lifetimes.re_erased, BorrowKind::Shared, place),
513 );
514 this.cfg.terminate(
515 block,
516 source_info,
517 TerminatorKind::Call {
518 func,
519 args: [Spanned { node: Operand::Move(ref_place), span: DUMMY_SP }]
520 .into(),
521 destination,
522 target: Some(success),
523 unwind: UnwindAction::Unreachable,
524 call_source: CallSource::Use,
525 fn_span: expr_span,
526 },
527 );
528 success.unit()
529 } else {
530 this.cfg.push_assign(
531 block,
532 source_info,
533 destination,
534 Rvalue::Use(Operand::Move(place)),
535 );
536 block.unit()
537 }
538 }
539 ExprKind::Use { source } => this.expr_into_dest(destination, block, source),
540 ExprKind::Borrow { arg, borrow_kind } => {
541 let arg_place = match borrow_kind {
547 BorrowKind::Shared => {
548 unpack!(block = this.as_read_only_place(block, arg))
549 }
550 _ => unpack!(block = this.as_place(block, arg)),
551 };
552 let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place);
553 this.cfg.push_assign(block, source_info, destination, borrow);
554 block.unit()
555 }
556 ExprKind::RawBorrow { mutability, arg } => {
557 let place = match mutability {
558 hir::Mutability::Not => this.as_read_only_place(block, arg),
559 hir::Mutability::Mut => this.as_place(block, arg),
560 };
561 let address_of = Rvalue::RawPtr(mutability.into(), unpack!(block = place));
562 this.cfg.push_assign(block, source_info, destination, address_of);
563 block.unit()
564 }
565 ExprKind::Adt(box AdtExpr {
566 adt_def,
567 variant_index,
568 args,
569 ref user_ty,
570 ref fields,
571 ref base,
572 }) => {
573 let is_union = adt_def.is_union();
576 let active_field_index = is_union.then(|| fields[0].name);
577
578 let scope = this.local_temp_lifetime();
579
580 let fields_map: FxHashMap<_, _> = fields
583 .into_iter()
584 .map(|f| {
585 (
586 f.name,
587 unpack!(
588 block = this.as_operand(
589 block,
590 scope,
591 f.expr,
592 LocalInfo::AggregateTemp,
593 NeedsTemporary::Maybe,
594 )
595 ),
596 )
597 })
598 .collect();
599
600 let variant = adt_def.variant(variant_index);
601 let field_names = variant.fields.indices();
602
603 let fields = match base {
604 AdtExprBase::None => {
605 field_names.filter_map(|n| fields_map.get(&n).cloned()).collect()
606 }
607 AdtExprBase::Base(FruInfo { base, field_types }) => {
608 let place_builder = unpack!(block = this.as_place_builder(block, *base));
609
610 itertools::zip_eq(field_names, &**field_types)
614 .map(|(n, ty)| match fields_map.get(&n) {
615 Some(v) => v.clone(),
616 None => {
617 let place =
618 place_builder.clone_project(PlaceElem::Field(n, *ty));
619 this.consume_by_copy_or_move(place.to_place(this))
620 }
621 })
622 .collect()
623 }
624 AdtExprBase::DefaultFields(field_types) => {
625 itertools::zip_eq(field_names, field_types)
626 .map(|(n, &ty)| match fields_map.get(&n) {
627 Some(v) => v.clone(),
628 None => match variant.fields[n].value {
629 Some(def) => {
630 let value = Const::Unevaluated(
631 UnevaluatedConst::new(def, args),
632 ty,
633 );
634 Operand::Constant(Box::new(ConstOperand {
635 span: expr_span,
636 user_ty: None,
637 const_: value,
638 }))
639 }
640 None => {
641 let name = variant.fields[n].name;
642 span_bug!(
643 expr_span,
644 "missing mandatory field `{name}` of type `{ty}`",
645 );
646 }
647 },
648 })
649 .collect()
650 }
651 };
652
653 let inferred_ty = expr.ty;
654 let user_ty = user_ty.as_ref().map(|user_ty| {
655 this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
656 span: source_info.span,
657 user_ty: user_ty.clone(),
658 inferred_ty,
659 })
660 });
661 let adt = Box::new(AggregateKind::Adt(
662 adt_def.did(),
663 variant_index,
664 args,
665 user_ty,
666 active_field_index,
667 ));
668 this.cfg.push_assign(
669 block,
670 source_info,
671 destination,
672 Rvalue::Aggregate(adt, fields),
673 );
674 block.unit()
675 }
676 ExprKind::InlineAsm(box InlineAsmExpr {
677 asm_macro,
678 template,
679 ref operands,
680 options,
681 line_spans,
682 }) => {
683 use rustc_middle::{mir, thir};
684
685 let destination_block = this.cfg.start_new_block();
686 let mut targets =
687 if asm_macro.diverges(options) { vec![] } else { vec![destination_block] };
688
689 let operands = operands
690 .into_iter()
691 .map(|op| match *op {
692 thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In {
693 reg,
694 value: unpack!(block = this.as_local_operand(block, expr)),
695 },
696 thir::InlineAsmOperand::Out { reg, late, expr } => {
697 mir::InlineAsmOperand::Out {
698 reg,
699 late,
700 place: expr.map(|expr| unpack!(block = this.as_place(block, expr))),
701 }
702 }
703 thir::InlineAsmOperand::InOut { reg, late, expr } => {
704 let place = unpack!(block = this.as_place(block, expr));
705 mir::InlineAsmOperand::InOut {
706 reg,
707 late,
708 in_value: Operand::Copy(place),
710 out_place: Some(place),
711 }
712 }
713 thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => {
714 mir::InlineAsmOperand::InOut {
715 reg,
716 late,
717 in_value: unpack!(block = this.as_local_operand(block, in_expr)),
718 out_place: out_expr.map(|out_expr| {
719 unpack!(block = this.as_place(block, out_expr))
720 }),
721 }
722 }
723 thir::InlineAsmOperand::Const { value, span } => {
724 mir::InlineAsmOperand::Const {
725 value: Box::new(ConstOperand {
726 span,
727 user_ty: None,
728 const_: value,
729 }),
730 }
731 }
732 thir::InlineAsmOperand::SymFn { value } => mir::InlineAsmOperand::SymFn {
733 value: Box::new(this.as_constant(&this.thir[value])),
734 },
735 thir::InlineAsmOperand::SymStatic { def_id } => {
736 mir::InlineAsmOperand::SymStatic { def_id }
737 }
738 thir::InlineAsmOperand::Label { block } => {
739 let target = this.cfg.start_new_block();
740 let target_index = targets.len();
741 targets.push(target);
742
743 let tmp = this.get_unit_temp();
744 let target =
745 this.ast_block(tmp, target, block, source_info).into_block();
746 this.cfg.terminate(
747 target,
748 source_info,
749 TerminatorKind::Goto { target: destination_block },
750 );
751
752 mir::InlineAsmOperand::Label { target_index }
753 }
754 })
755 .collect();
756
757 if !expr.ty.is_never() {
758 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
759 }
760
761 let asm_macro = match asm_macro {
762 AsmMacro::Asm | AsmMacro::GlobalAsm => InlineAsmMacro::Asm,
763 AsmMacro::NakedAsm => InlineAsmMacro::NakedAsm,
764 };
765
766 this.cfg.terminate(
767 block,
768 source_info,
769 TerminatorKind::InlineAsm {
770 asm_macro,
771 template,
772 operands,
773 options,
774 line_spans,
775 targets: targets.into_boxed_slice(),
776 unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
777 UnwindAction::Continue
778 } else {
779 UnwindAction::Unreachable
780 },
781 },
782 );
783 if options.contains(InlineAsmOptions::MAY_UNWIND) {
784 this.diverge_from(block);
785 }
786 destination_block.unit()
787 }
788
789 ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
791 block = this.stmt_expr(block, expr_id, None).into_block();
792 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
793 block.unit()
794 }
795
796 ExprKind::Continue { .. }
797 | ExprKind::ConstContinue { .. }
798 | ExprKind::Break { .. }
799 | ExprKind::Return { .. }
800 | ExprKind::Become { .. } => {
801 block = this.stmt_expr(block, expr_id, None).into_block();
802 block.unit()
804 }
805
806 ExprKind::VarRef { .. }
808 | ExprKind::UpvarRef { .. }
809 | ExprKind::PlaceTypeAscription { .. }
810 | ExprKind::ValueTypeAscription { .. }
811 | ExprKind::PlaceUnwrapUnsafeBinder { .. }
812 | ExprKind::ValueUnwrapUnsafeBinder { .. } => {
813 debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
814
815 let place = unpack!(block = this.as_place(block, expr_id));
816 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
817 this.cfg.push_assign(block, source_info, destination, rvalue);
818 block.unit()
819 }
820 ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
821 debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));
822
823 if !destination.projection.is_empty() {
827 this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
828 }
829
830 let place = unpack!(block = this.as_place(block, expr_id));
831 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
832 this.cfg.push_assign(block, source_info, destination, rvalue);
833 block.unit()
834 }
835
836 ExprKind::Yield { value } => {
837 let scope = this.local_temp_lifetime();
838 let value = unpack!(
839 block =
840 this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
841 );
842 let resume = this.cfg.start_new_block();
843 this.cfg.terminate(
844 block,
845 source_info,
846 TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
847 );
848 this.coroutine_drop_cleanup(block);
849 resume.unit()
850 }
851
852 ExprKind::Unary { .. }
854 | ExprKind::Binary { .. }
855 | ExprKind::Cast { .. }
856 | ExprKind::PointerCoercion { .. }
857 | ExprKind::Repeat { .. }
858 | ExprKind::Array { .. }
859 | ExprKind::Tuple { .. }
860 | ExprKind::Closure { .. }
861 | ExprKind::ConstBlock { .. }
862 | ExprKind::Literal { .. }
863 | ExprKind::NamedConst { .. }
864 | ExprKind::NonHirLiteral { .. }
865 | ExprKind::ZstLiteral { .. }
866 | ExprKind::ConstParam { .. }
867 | ExprKind::ThreadLocalRef(_)
868 | ExprKind::StaticRef { .. }
869 | ExprKind::WrapUnsafeBinder { .. } => {
870 debug_assert!(match Category::of(&expr.kind).unwrap() {
871 Category::Rvalue(RvalueFunc::Into) => false,
873
874 Category::Place => false,
878
879 _ => true,
880 });
881
882 let rvalue = unpack!(block = this.as_local_rvalue(block, expr_id));
883 this.cfg.push_assign(block, source_info, destination, rvalue);
884 block.unit()
885 }
886 };
887
888 if !expr_is_block_or_scope {
889 let popped = this.block_context.pop();
890 assert!(popped.is_some());
891 }
892
893 block_and
894 }
895
896 fn is_let(&self, expr: ExprId) -> bool {
897 match self.thir[expr].kind {
898 ExprKind::Let { .. } => true,
899 ExprKind::Scope { value, .. } => self.is_let(value),
900 _ => false,
901 }
902 }
903}