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