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, HasMatchGuard};
19use crate::builder::scope::LintLevel;
20use crate::builder::{BlockAnd, BlockAndExtension, BlockFrame, Builder, NeedsTemporary};
21use crate::errors::{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();
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:465",
"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(465u32),
::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))]
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 this.cfg.goto(body_block_end, source_info, loop_block);
242
243 None
245 })
246 }
247 ExprKind::LoopMatch {
248 state,
249 region_scope,
250 match_data: box LoopMatchMatchData { box ref arms, span: match_span, scrutinee },
251 } => {
252 fn is_supported_loop_match_type(ty: Ty<'_>) -> bool {
260 match ty.kind() {
261 ty::Uint(_) | ty::Int(_) | ty::Float(_) | ty::Bool | ty::Char => true,
262 ty::Adt(adt_def, _) => match adt_def.adt_kind() {
263 ty::AdtKind::Struct | ty::AdtKind::Union => false,
264 ty::AdtKind::Enum => {
265 adt_def.variants().iter().all(|v| v.fields.is_empty())
266 }
267 },
268 _ => false,
269 }
270 }
271
272 let state_ty = this.thir.exprs[state].ty;
273 if !is_supported_loop_match_type(state_ty) {
274 let span = this.thir.exprs[state].span;
275 this.tcx.dcx().emit_fatal(LoopMatchUnsupportedType { span, ty: state_ty })
276 }
277
278 let loop_block = this.cfg.start_new_block();
279
280 this.cfg.goto(block, source_info, loop_block);
282
283 this.in_breakable_scope(Some(loop_block), destination, expr_span, |this| {
284 let mut body_block = this.cfg.start_new_block();
286 this.cfg.terminate(
287 loop_block,
288 source_info,
289 TerminatorKind::FalseUnwind {
290 real_target: body_block,
291 unwind: UnwindAction::Continue,
292 },
293 );
294 this.diverge_from(loop_block);
295
296 let scrutinee_span = this.thir.exprs[scrutinee].span;
298 let scrutinee_place_builder = unpack!(
299 body_block = this.lower_scrutinee(body_block, scrutinee, scrutinee_span)
300 );
301
302 let match_start_span = match_span.shrink_to_lo().to(scrutinee_span);
303
304 let mut patterns = Vec::with_capacity(arms.len());
305 for &arm_id in arms.iter() {
306 let arm = &this.thir[arm_id];
307
308 if let Some(guard) = arm.guard {
309 let span = this.thir.exprs[guard].span;
310 this.tcx.dcx().emit_fatal(LoopMatchArmWithGuard { span })
311 }
312
313 patterns.push((&*arm.pattern, HasMatchGuard::No));
314 }
315
316 let built_tree = this.lower_match_tree(
320 body_block,
321 scrutinee_span,
322 &scrutinee_place_builder,
323 match_start_span,
324 patterns,
325 false,
326 );
327
328 let state_place = scrutinee_place_builder.to_place(this);
329
330 unpack!(
337 body_block = this.in_scope(
338 (region_scope, source_info),
339 LintLevel::Inherited,
340 move |this| {
341 this.in_breakable_scope(None, state_place, expr_span, |this| {
342 Some(this.in_const_continuable_scope(
343 Box::from(arms),
344 built_tree.clone(),
345 state_place,
346 expr_span,
347 |this| {
348 this.lower_match_arms(
349 state_place,
350 scrutinee_place_builder,
351 scrutinee_span,
352 arms,
353 built_tree,
354 this.source_info(match_span),
355 )
356 },
357 ))
358 })
359 }
360 )
361 );
362
363 this.cfg.goto(body_block, source_info, loop_block);
364
365 None
367 })
368 }
369 ExprKind::Call { ty, fun, ref args, .. }
372 if let ty::FnDef(def_id, generic_args) = *ty.kind()
373 && let Some(intrinsic) = this.tcx.intrinsic(def_id)
374 && matches!(intrinsic.name, sym::write_via_move | sym::write_box_via_move) =>
375 {
376 let _fun = unpack!(block = this.as_local_operand(block, fun));
379
380 match intrinsic.name {
381 sym::write_via_move => {
382 assert!(destination.ty(&this.local_decls, this.tcx).ty.is_unit());
387
388 let [ptr, val] = **args else {
390 span_bug!(expr_span, "invalid write_via_move call")
391 };
392 let Some(ptr) = unpack!(block = this.as_local_operand(block, ptr)).place()
393 else {
394 span_bug!(expr_span, "invalid write_via_move call")
395 };
396 let ptr_deref = ptr.project_deeper(&[ProjectionElem::Deref], this.tcx);
397 this.expr_into_dest(ptr_deref, block, val)
398 }
399 sym::write_box_via_move => {
400 let [b, val] = **args else {
414 span_bug!(expr_span, "invalid init_box_via_move call")
415 };
416 let Some(b) = unpack!(block = this.as_local_operand(block, b)).place()
417 else {
418 span_bug!(expr_span, "invalid init_box_via_move call")
419 };
420 let tcx = this.tcx;
421 let decls = &this.local_decls;
422
423 let place = b.project_deeper(&[ProjectionElem::Deref], tcx);
425 let place = place.project_to_field(FieldIdx::from_u32(1), decls, tcx);
427 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
429 let place = place.project_to_field(FieldIdx::ZERO, decls, tcx);
431 assert_eq!(place.ty(decls, tcx).ty, generic_args.type_at(0));
433
434 unpack!(block = this.expr_into_dest(place, block, val));
436
437 this.cfg.push_assign(
439 block,
440 source_info,
441 destination,
442 Rvalue::Use(Operand::Move(b)),
444 );
445 block.unit()
446 }
447 _ => rustc_middle::bug!(),
448 }
449 }
450 ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => {
451 let fun = unpack!(block = this.as_local_operand(block, fun));
452 let args: Box<[_]> = args
453 .into_iter()
454 .copied()
455 .map(|arg| Spanned {
456 node: unpack!(block = this.as_local_call_operand(block, arg)),
457 span: this.thir.exprs[arg].span,
458 })
459 .collect();
460
461 let success = this.cfg.start_new_block();
462
463 this.record_operands_moved(&args);
464
465 debug!("expr_into_dest: fn_span={:?}", fn_span);
466
467 this.cfg.terminate(
468 block,
469 source_info,
470 TerminatorKind::Call {
471 func: fun,
472 args,
473 unwind: UnwindAction::Continue,
474 destination,
475 target: Some(success),
476 call_source: if from_hir_call {
477 CallSource::Normal
478 } else {
479 CallSource::OverloadedOperator
480 },
481 fn_span,
482 },
483 );
484 this.diverge_from(block);
485 success.unit()
486 }
487 ExprKind::ByUse { expr, span } => {
488 let place = unpack!(block = this.as_place(block, expr));
489 let ty = place.ty(&this.local_decls, this.tcx).ty;
490
491 if this.tcx.type_is_copy_modulo_regions(this.infcx.typing_env(this.param_env), ty) {
492 this.cfg.push_assign(
493 block,
494 source_info,
495 destination,
496 Rvalue::Use(Operand::Copy(place)),
497 );
498 block.unit()
499 } else if this.infcx.type_is_use_cloned_modulo_regions(this.param_env, ty) {
500 let success = this.cfg.start_new_block();
502 let clone_trait = this.tcx.require_lang_item(LangItem::Clone, span);
503 let clone_fn = this.tcx.associated_item_def_ids(clone_trait)[0];
504 let func = Operand::function_handle(this.tcx, clone_fn, [ty.into()], expr_span);
505 let ref_ty = Ty::new_imm_ref(this.tcx, this.tcx.lifetimes.re_erased, ty);
506 let ref_place = this.temp(ref_ty, span);
507 this.cfg.push_assign(
508 block,
509 source_info,
510 ref_place,
511 Rvalue::Ref(this.tcx.lifetimes.re_erased, BorrowKind::Shared, place),
512 );
513 this.cfg.terminate(
514 block,
515 source_info,
516 TerminatorKind::Call {
517 func,
518 args: [Spanned { node: Operand::Move(ref_place), span: DUMMY_SP }]
519 .into(),
520 destination,
521 target: Some(success),
522 unwind: UnwindAction::Unreachable,
523 call_source: CallSource::Use,
524 fn_span: expr_span,
525 },
526 );
527 success.unit()
528 } else {
529 this.cfg.push_assign(
530 block,
531 source_info,
532 destination,
533 Rvalue::Use(Operand::Move(place)),
534 );
535 block.unit()
536 }
537 }
538 ExprKind::Use { source } => this.expr_into_dest(destination, block, source),
539 ExprKind::Borrow { arg, borrow_kind } => {
540 let arg_place = match borrow_kind {
546 BorrowKind::Shared => {
547 unpack!(block = this.as_read_only_place(block, arg))
548 }
549 _ => unpack!(block = this.as_place(block, arg)),
550 };
551 let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place);
552 this.cfg.push_assign(block, source_info, destination, borrow);
553 block.unit()
554 }
555 ExprKind::RawBorrow { mutability, arg } => {
556 let place = match mutability {
557 hir::Mutability::Not => this.as_read_only_place(block, arg),
558 hir::Mutability::Mut => this.as_place(block, arg),
559 };
560 let address_of = Rvalue::RawPtr(mutability.into(), unpack!(block = place));
561 this.cfg.push_assign(block, source_info, destination, address_of);
562 block.unit()
563 }
564 ExprKind::Adt(box AdtExpr {
565 adt_def,
566 variant_index,
567 args,
568 ref user_ty,
569 ref fields,
570 ref base,
571 }) => {
572 let is_union = adt_def.is_union();
575 let active_field_index = is_union.then(|| fields[0].name);
576
577 let scope = this.local_temp_lifetime();
578
579 let fields_map: FxHashMap<_, _> = fields
582 .into_iter()
583 .map(|f| {
584 (
585 f.name,
586 unpack!(
587 block = this.as_operand(
588 block,
589 scope,
590 f.expr,
591 LocalInfo::AggregateTemp,
592 NeedsTemporary::Maybe,
593 )
594 ),
595 )
596 })
597 .collect();
598
599 let variant = adt_def.variant(variant_index);
600 let field_names = variant.fields.indices();
601
602 let fields = match base {
603 AdtExprBase::None => {
604 field_names.filter_map(|n| fields_map.get(&n).cloned()).collect()
605 }
606 AdtExprBase::Base(FruInfo { base, field_types }) => {
607 let place_builder = unpack!(block = this.as_place_builder(block, *base));
608
609 itertools::zip_eq(field_names, &**field_types)
613 .map(|(n, ty)| match fields_map.get(&n) {
614 Some(v) => v.clone(),
615 None => {
616 let place =
617 place_builder.clone_project(PlaceElem::Field(n, *ty));
618 this.consume_by_copy_or_move(place.to_place(this))
619 }
620 })
621 .collect()
622 }
623 AdtExprBase::DefaultFields(field_types) => {
624 itertools::zip_eq(field_names, field_types)
625 .map(|(n, &ty)| match fields_map.get(&n) {
626 Some(v) => v.clone(),
627 None => match variant.fields[n].value {
628 Some(def) => {
629 let value = Const::Unevaluated(
630 UnevaluatedConst::new(def, args),
631 ty,
632 );
633 Operand::Constant(Box::new(ConstOperand {
634 span: expr_span,
635 user_ty: None,
636 const_: value,
637 }))
638 }
639 None => {
640 let name = variant.fields[n].name;
641 span_bug!(
642 expr_span,
643 "missing mandatory field `{name}` of type `{ty}`",
644 );
645 }
646 },
647 })
648 .collect()
649 }
650 };
651
652 let inferred_ty = expr.ty;
653 let user_ty = user_ty.as_ref().map(|user_ty| {
654 this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation {
655 span: source_info.span,
656 user_ty: user_ty.clone(),
657 inferred_ty,
658 })
659 });
660 let adt = Box::new(AggregateKind::Adt(
661 adt_def.did(),
662 variant_index,
663 args,
664 user_ty,
665 active_field_index,
666 ));
667 this.cfg.push_assign(
668 block,
669 source_info,
670 destination,
671 Rvalue::Aggregate(adt, fields),
672 );
673 block.unit()
674 }
675 ExprKind::InlineAsm(box InlineAsmExpr {
676 asm_macro,
677 template,
678 ref operands,
679 options,
680 line_spans,
681 }) => {
682 use rustc_middle::{mir, thir};
683
684 let destination_block = this.cfg.start_new_block();
685 let mut targets =
686 if asm_macro.diverges(options) { vec![] } else { vec![destination_block] };
687
688 let operands = operands
689 .into_iter()
690 .map(|op| match *op {
691 thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In {
692 reg,
693 value: unpack!(block = this.as_local_operand(block, expr)),
694 },
695 thir::InlineAsmOperand::Out { reg, late, expr } => {
696 mir::InlineAsmOperand::Out {
697 reg,
698 late,
699 place: expr.map(|expr| unpack!(block = this.as_place(block, expr))),
700 }
701 }
702 thir::InlineAsmOperand::InOut { reg, late, expr } => {
703 let place = unpack!(block = this.as_place(block, expr));
704 mir::InlineAsmOperand::InOut {
705 reg,
706 late,
707 in_value: Operand::Copy(place),
709 out_place: Some(place),
710 }
711 }
712 thir::InlineAsmOperand::SplitInOut { reg, late, in_expr, out_expr } => {
713 mir::InlineAsmOperand::InOut {
714 reg,
715 late,
716 in_value: unpack!(block = this.as_local_operand(block, in_expr)),
717 out_place: out_expr.map(|out_expr| {
718 unpack!(block = this.as_place(block, out_expr))
719 }),
720 }
721 }
722 thir::InlineAsmOperand::Const { value, span } => {
723 mir::InlineAsmOperand::Const {
724 value: Box::new(ConstOperand {
725 span,
726 user_ty: None,
727 const_: value,
728 }),
729 }
730 }
731 thir::InlineAsmOperand::SymFn { value } => mir::InlineAsmOperand::SymFn {
732 value: Box::new(this.as_constant(&this.thir[value])),
733 },
734 thir::InlineAsmOperand::SymStatic { def_id } => {
735 mir::InlineAsmOperand::SymStatic { def_id }
736 }
737 thir::InlineAsmOperand::Label { block } => {
738 let target = this.cfg.start_new_block();
739 let target_index = targets.len();
740 targets.push(target);
741
742 let tmp = this.get_unit_temp();
743 let target =
744 this.ast_block(tmp, target, block, source_info).into_block();
745 this.cfg.terminate(
746 target,
747 source_info,
748 TerminatorKind::Goto { target: destination_block },
749 );
750
751 mir::InlineAsmOperand::Label { target_index }
752 }
753 })
754 .collect();
755
756 if !expr.ty.is_never() {
757 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
758 }
759
760 let asm_macro = match asm_macro {
761 AsmMacro::Asm | AsmMacro::GlobalAsm => InlineAsmMacro::Asm,
762 AsmMacro::NakedAsm => InlineAsmMacro::NakedAsm,
763 };
764
765 this.cfg.terminate(
766 block,
767 source_info,
768 TerminatorKind::InlineAsm {
769 asm_macro,
770 template,
771 operands,
772 options,
773 line_spans,
774 targets: targets.into_boxed_slice(),
775 unwind: if options.contains(InlineAsmOptions::MAY_UNWIND) {
776 UnwindAction::Continue
777 } else {
778 UnwindAction::Unreachable
779 },
780 },
781 );
782 if options.contains(InlineAsmOptions::MAY_UNWIND) {
783 this.diverge_from(block);
784 }
785 destination_block.unit()
786 }
787
788 ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => {
790 block = this.stmt_expr(block, expr_id, None).into_block();
791 this.cfg.push_assign_unit(block, source_info, destination, this.tcx);
792 block.unit()
793 }
794
795 ExprKind::Continue { .. }
796 | ExprKind::ConstContinue { .. }
797 | ExprKind::Break { .. }
798 | ExprKind::Return { .. }
799 | ExprKind::Become { .. } => {
800 block = this.stmt_expr(block, expr_id, None).into_block();
801 block.unit()
803 }
804
805 ExprKind::VarRef { .. }
807 | ExprKind::UpvarRef { .. }
808 | ExprKind::PlaceTypeAscription { .. }
809 | ExprKind::ValueTypeAscription { .. }
810 | ExprKind::PlaceUnwrapUnsafeBinder { .. }
811 | ExprKind::ValueUnwrapUnsafeBinder { .. } => {
812 debug_assert!(Category::of(&expr.kind) == Some(Category::Place));
813
814 let place = unpack!(block = this.as_place(block, expr_id));
815 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
816 this.cfg.push_assign(block, source_info, destination, rvalue);
817 block.unit()
818 }
819 ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => {
820 debug_assert_eq!(Category::of(&expr.kind), Some(Category::Place));
821
822 if !destination.projection.is_empty() {
826 this.local_decls.push(LocalDecl::new(expr.ty, expr.span));
827 }
828
829 let place = unpack!(block = this.as_place(block, expr_id));
830 let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place));
831 this.cfg.push_assign(block, source_info, destination, rvalue);
832 block.unit()
833 }
834
835 ExprKind::Yield { value } => {
836 let scope = this.local_temp_lifetime();
837 let value = unpack!(
838 block =
839 this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No)
840 );
841 let resume = this.cfg.start_new_block();
842 this.cfg.terminate(
843 block,
844 source_info,
845 TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None },
846 );
847 this.coroutine_drop_cleanup(block);
848 resume.unit()
849 }
850
851 ExprKind::Unary { .. }
853 | ExprKind::Binary { .. }
854 | ExprKind::Cast { .. }
855 | ExprKind::PointerCoercion { .. }
856 | ExprKind::Repeat { .. }
857 | ExprKind::Array { .. }
858 | ExprKind::Tuple { .. }
859 | ExprKind::Closure { .. }
860 | ExprKind::ConstBlock { .. }
861 | ExprKind::Literal { .. }
862 | ExprKind::NamedConst { .. }
863 | ExprKind::NonHirLiteral { .. }
864 | ExprKind::ZstLiteral { .. }
865 | ExprKind::ConstParam { .. }
866 | ExprKind::ThreadLocalRef(_)
867 | ExprKind::StaticRef { .. }
868 | ExprKind::WrapUnsafeBinder { .. } => {
869 debug_assert!(match Category::of(&expr.kind).unwrap() {
870 Category::Rvalue(RvalueFunc::Into) => false,
872
873 Category::Place => false,
877
878 _ => true,
879 });
880
881 let rvalue = unpack!(block = this.as_local_rvalue(block, expr_id));
882 this.cfg.push_assign(block, source_info, destination, rvalue);
883 block.unit()
884 }
885 };
886
887 if !expr_is_block_or_scope {
888 let popped = this.block_context.pop();
889 assert!(popped.is_some());
890 }
891
892 block_and
893 }
894
895 fn is_let(&self, expr: ExprId) -> bool {
896 match self.thir[expr].kind {
897 ExprKind::Let { .. } => true,
898 ExprKind::Scope { value, .. } => self.is_let(value),
899 _ => false,
900 }
901 }
902}