diff --git a/compiler/rustc_mir_build/src/builder/block.rs b/compiler/rustc_mir_build/src/builder/block.rs index cc99d2b42eebc..72a3f33734e91 100644 --- a/compiler/rustc_mir_build/src/builder/block.rs +++ b/compiler/rustc_mir_build/src/builder/block.rs @@ -39,8 +39,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr: Option, region_scope: Scope, ) -> BlockAnd<()> { - let this = self; - // This convoluted structure is to avoid using recursion as we walk down a list // of statements. Basically, the structure we get back is something like: // @@ -58,21 +56,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // // First we build all the statements in the block. let mut let_scope_stack = Vec::with_capacity(8); - let outer_source_scope = this.source_scope; + let outer_source_scope = self.source_scope; // This scope information is kept for breaking out of the parent remainder scope in case // one let-else pattern matching fails. // By doing so, we can be sure that even temporaries that receive extended lifetime // assignments are dropped, too. let mut last_remainder_scope = region_scope; - let source_info = this.source_info(span); + let source_info = self.source_info(span); for stmt in stmts { - let Stmt { ref kind } = this.thir[*stmt]; + let Stmt { ref kind } = self.thir[*stmt]; match kind { StmtKind::Expr { scope, expr } => { - this.block_context.push(BlockFrame::Statement { ignores_expr_result: true }); + self.block_context.push(BlockFrame::Statement { ignores_expr_result: true }); let si = (*scope, source_info); - block = this + block = self .in_scope(si, LintLevel::Inherited, |this| { this.stmt_expr(block, *expr, Some(*scope)) }) @@ -156,42 +154,42 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // └────────────────┘ let ignores_expr_result = matches!(pattern.kind, PatKind::Wild); - this.block_context.push(BlockFrame::Statement { ignores_expr_result }); + self.block_context.push(BlockFrame::Statement { ignores_expr_result }); // Lower the `else` block first because its parent scope is actually // enclosing the rest of the `let .. else ..` parts. - let else_block_span = this.thir[*else_block].span; + let else_block_span = self.thir[*else_block].span; // This place is not really used because this destination place // should never be used to take values at the end of the failure // block. - let dummy_place = this.temp(this.tcx.types.never, else_block_span); - let failure_entry = this.cfg.start_new_block(); + let dummy_place = self.temp(self.tcx.types.never, else_block_span); + let failure_entry = self.cfg.start_new_block(); let failure_block; - failure_block = this + failure_block = self .ast_block( dummy_place, failure_entry, *else_block, - this.source_info(else_block_span), + self.source_info(else_block_span), ) .into_block(); - this.cfg.terminate( + self.cfg.terminate( failure_block, - this.source_info(else_block_span), + self.source_info(else_block_span), TerminatorKind::Unreachable, ); // Declare the bindings, which may create a source scope. - let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree); - this.push_scope((*remainder_scope, source_info)); + let remainder_span = remainder_scope.span(self.tcx, self.region_scope_tree); + self.push_scope((*remainder_scope, source_info)); let_scope_stack.push(remainder_scope); let visibility_scope = - Some(this.new_source_scope(remainder_span, LintLevel::Inherited)); + Some(self.new_source_scope(remainder_span, LintLevel::Inherited)); - let initializer_span = this.thir[*initializer].span; + let initializer_span = self.thir[*initializer].span; let scope = (*init_scope, source_info); - let failure_and_block = this.in_scope(scope, *lint_level, |this| { + let failure_and_block = self.in_scope(scope, *lint_level, |this| { this.declare_bindings( visibility_scope, remainder_span, @@ -199,7 +197,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { None, Some((Some(&destination), initializer_span)), ); - let else_block_span = this.thir[*else_block].span; + let else_block_span = self.thir[*else_block].span; let (matching, failure) = this.in_if_then_scope(last_remainder_scope, else_block_span, |this| { this.lower_let_expr( @@ -214,16 +212,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { matching.and(failure) }); let failure = unpack!(block = failure_and_block); - this.cfg.goto(failure, source_info, failure_entry); + self.cfg.goto(failure, source_info, failure_entry); if let Some(source_scope) = visibility_scope { - this.source_scope = source_scope; + self.source_scope = source_scope; } last_remainder_scope = *remainder_scope; } StmtKind::Let { init_scope, initializer: None, else_block: Some(_), .. } => { span_bug!( - init_scope.span(this.tcx, this.region_scope_tree), + init_scope.span(self.tcx, self.region_scope_tree), "initializer is missing, but else block is present in this let binding", ) } @@ -237,24 +235,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { span: _, } => { let ignores_expr_result = matches!(pattern.kind, PatKind::Wild); - this.block_context.push(BlockFrame::Statement { ignores_expr_result }); + self.block_context.push(BlockFrame::Statement { ignores_expr_result }); // Enter the remainder scope, i.e., the bindings' destruction scope. - this.push_scope((*remainder_scope, source_info)); + self.push_scope((*remainder_scope, source_info)); let_scope_stack.push(remainder_scope); // Declare the bindings, which may create a source scope. - let remainder_span = remainder_scope.span(this.tcx, this.region_scope_tree); + let remainder_span = remainder_scope.span(self.tcx, self.region_scope_tree); let visibility_scope = - Some(this.new_source_scope(remainder_span, LintLevel::Inherited)); + Some(self.new_source_scope(remainder_span, LintLevel::Inherited)); // Evaluate the initializer, if present. if let Some(init) = *initializer { - let initializer_span = this.thir[init].span; + let initializer_span = self.thir[init].span; let scope = (*init_scope, source_info); - block = this + block = self .in_scope(scope, *lint_level, |this| { this.declare_bindings( visibility_scope, @@ -269,7 +267,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .into_block(); } else { let scope = (*init_scope, source_info); - let _: BlockAnd<()> = this.in_scope(scope, *lint_level, |this| { + let _: BlockAnd<()> = self.in_scope(scope, *lint_level, |this| { this.declare_bindings( visibility_scope, remainder_span, @@ -281,7 +279,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }); debug!("ast_block_stmts: pattern={:?}", pattern); - this.visit_primary_bindings(pattern, &mut |this, node, span| { + self.visit_primary_bindings(pattern, &mut |this, node, span| { this.storage_live_binding( block, node, @@ -296,30 +294,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Enter the visibility scope, after evaluating the initializer. if let Some(source_scope) = visibility_scope { - this.source_scope = source_scope; + self.source_scope = source_scope; } last_remainder_scope = *remainder_scope; } } - let popped = this.block_context.pop(); + let popped = self.block_context.pop(); assert!(popped.is_some_and(|bf| bf.is_statement())); } // Then, the block may have an optional trailing expression which is a “return” value // of the block, which is stored into `destination`. - let tcx = this.tcx; - let destination_ty = destination.ty(&this.local_decls, tcx).ty; + let tcx = self.tcx; + let destination_ty = destination.ty(&self.local_decls, tcx).ty; if let Some(expr_id) = expr { - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; let tail_result_is_ignored = - destination_ty.is_unit() || this.block_context.currently_ignores_tail_results(); - this.block_context.push(BlockFrame::TailExpr { + destination_ty.is_unit() || self.block_context.currently_ignores_tail_results(); + self.block_context.push(BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored, span: expr.span }, }); - block = this.expr_into_dest(destination, block, expr_id).into_block(); - let popped = this.block_context.pop(); + block = self.expr_into_dest(destination, block, expr_id).into_block(); + let popped = self.block_context.pop(); assert!(popped.is_some_and(|bf| bf.is_tail_expr())); } else { @@ -334,16 +332,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { { // We only want to assign an implicit `()` as the return value of the block if the // block does not diverge. (Otherwise, we may try to assign a unit to a `!`-type.) - this.cfg.push_assign_unit(block, source_info, destination, this.tcx); + self.cfg.push_assign_unit(block, source_info, destination, self.tcx); } } // Finally, we pop all the let scopes before exiting out from the scope of block // itself. for scope in let_scope_stack.into_iter().rev() { - block = this.pop_scope((*scope, source_info), block).into_block(); + block = self.pop_scope((*scope, source_info), block).into_block(); } // Restore the original source scope. - this.source_scope = outer_source_scope; + self.source_scope = outer_source_scope; block.unit() } } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs index 0e0c7a7fa4f0b..d860750b0de82 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_constant.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_constant.rs @@ -19,17 +19,16 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// Compile `expr`, yielding a compile-time constant. Assumes that /// `expr` is a valid compile-time constant! pub(crate) fn as_constant(&mut self, expr: &Expr<'tcx>) -> ConstOperand<'tcx> { - let this = self; - let tcx = this.tcx; + let tcx = self.tcx; let Expr { ty, temp_lifetime: _, span, ref kind } = *expr; match kind { ExprKind::Scope { region_scope: _, lint_level: _, value } => { - this.as_constant(&this.thir[*value]) + self.as_constant(&self.thir[*value]) } _ => as_constant_inner( expr, |user_ty| { - Some(this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + Some(self.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { span, user_ty: user_ty.clone(), inferred_ty: ty, diff --git a/compiler/rustc_mir_build/src/builder/expr/as_operand.rs b/compiler/rustc_mir_build/src/builder/expr/as_operand.rs index 6a42222399041..5fbe113f9a28c 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_operand.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_operand.rs @@ -118,13 +118,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { local_info: LocalInfo<'tcx>, needs_temporary: NeedsTemporary, ) -> BlockAnd> { - let this = self; - - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind { - let source_info = this.source_info(expr.span); + let source_info = self.source_info(expr.span); let region_scope = (region_scope, source_info); - return this.in_scope(region_scope, lint_level, |this| { + return self.in_scope(region_scope, lint_level, |this| { this.as_operand(block, scope, value, local_info, needs_temporary) }); } @@ -134,17 +132,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { match category { Category::Constant if matches!(needs_temporary, NeedsTemporary::No) - || !expr.ty.needs_drop(this.tcx, this.typing_env()) => + || !expr.ty.needs_drop(self.tcx, self.typing_env()) => { - let constant = this.as_constant(expr); + let constant = self.as_constant(expr); block.and(Operand::Constant(Box::new(constant))) } Category::Constant | Category::Place | Category::Rvalue(..) => { - let operand = unpack!(block = this.as_temp(block, scope, expr_id, Mutability::Mut)); + let operand = unpack!(block = self.as_temp(block, scope, expr_id, Mutability::Mut)); // Overwrite temp local info if we have something more interesting to record. if !matches!(local_info, LocalInfo::Boring) { let decl_info = - this.local_decls[operand].local_info.as_mut().unwrap_crate_local(); + self.local_decls[operand].local_info.as_mut().unwrap_crate_local(); if let LocalInfo::Boring | LocalInfo::BlockTailTemp(_) = **decl_info { **decl_info = local_info; } @@ -160,31 +158,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scope: TempLifetime, expr_id: ExprId, ) -> BlockAnd> { - let this = self; - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; debug!("as_call_operand(block={:?}, expr={:?})", block, expr); if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind { - let source_info = this.source_info(expr.span); + let source_info = self.source_info(expr.span); let region_scope = (region_scope, source_info); - return this.in_scope(region_scope, lint_level, |this| { + return self.in_scope(region_scope, lint_level, |this| { this.as_call_operand(block, scope, value) }); } - let tcx = this.tcx; + let tcx = self.tcx; if tcx.features().unsized_fn_params() { let ty = expr.ty; - if !ty.is_sized(tcx, this.typing_env()) { + if !ty.is_sized(tcx, self.typing_env()) { // !sized means !copy, so this is an unsized move - assert!(!tcx.type_is_copy_modulo_regions(this.typing_env(), ty)); + assert!(!tcx.type_is_copy_modulo_regions(self.typing_env(), ty)); // As described above, detect the case where we are passing a value of unsized // type, and that value is coming from the deref of a box. if let ExprKind::Deref { arg } = expr.kind { // Generate let tmp0 = arg0 - let operand = unpack!(block = this.as_temp(block, scope, arg, Mutability::Mut)); + let operand = unpack!(block = self.as_temp(block, scope, arg, Mutability::Mut)); // Return the operand *tmp0 to be used as the call argument let place = Place { @@ -197,6 +194,6 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - this.as_operand(block, scope, expr_id, LocalInfo::Boring, NeedsTemporary::Maybe) + self.as_operand(block, scope, expr_id, LocalInfo::Boring, NeedsTemporary::Maybe) } } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_place.rs b/compiler/rustc_mir_build/src/builder/expr/as_place.rs index 1b143f37a585f..4e035aae83c6e 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_place.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_place.rs @@ -423,19 +423,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let expr = &self.thir[expr_id]; debug!("expr_as_place(block={:?}, expr={:?}, mutability={:?})", block, expr, mutability); - let this = self; let expr_span = expr.span; - let source_info = this.source_info(expr_span); + let source_info = self.source_info(expr_span); match expr.kind { ExprKind::Scope { region_scope, lint_level, value } => { - this.in_scope((region_scope, source_info), lint_level, |this| { + self.in_scope((region_scope, source_info), lint_level, |this| { this.expr_as_place(block, value, mutability, fake_borrow_temps) }) } ExprKind::Field { lhs, variant_index, name } => { - let lhs_expr = &this.thir[lhs]; + let lhs_expr = &self.thir[lhs]; let mut place_builder = - unpack!(block = this.expr_as_place(block, lhs, mutability, fake_borrow_temps,)); + unpack!(block = self.expr_as_place(block, lhs, mutability, fake_borrow_temps,)); if let ty::Adt(adt_def, _) = lhs_expr.ty.kind() { if adt_def.is_enum() { place_builder = place_builder.downcast(*adt_def, variant_index); @@ -445,10 +444,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ExprKind::Deref { arg } => { let place_builder = - unpack!(block = this.expr_as_place(block, arg, mutability, fake_borrow_temps,)); + unpack!(block = self.expr_as_place(block, arg, mutability, fake_borrow_temps,)); block.and(place_builder.deref()) } - ExprKind::Index { lhs, index } => this.lower_index_expression( + ExprKind::Index { lhs, index } => self.lower_index_expression( block, lhs, index, @@ -458,15 +457,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { source_info, ), ExprKind::UpvarRef { closure_def_id, var_hir_id } => { - this.lower_captured_upvar(block, closure_def_id.expect_local(), var_hir_id) + self.lower_captured_upvar(block, closure_def_id.expect_local(), var_hir_id) } ExprKind::VarRef { id } => { - let place_builder = if this.is_bound_var_in_guard(id) { - let index = this.var_local_id(id, RefWithinGuard); + let place_builder = if self.is_bound_var_in_guard(id) { + let index = self.var_local_id(id, RefWithinGuard); PlaceBuilder::from(index).deref() } else { - let index = this.var_local_id(id, OutsideGuard); + let index = self.var_local_id(id, OutsideGuard); PlaceBuilder::from(index) }; block.and(place_builder) @@ -474,19 +473,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ExprKind::PlaceTypeAscription { source, ref user_ty, user_ty_span } => { let place_builder = unpack!( - block = this.expr_as_place(block, source, mutability, fake_borrow_temps,) + block = self.expr_as_place(block, source, mutability, fake_borrow_temps,) ); if let Some(user_ty) = user_ty { - let ty_source_info = this.source_info(user_ty_span); + let ty_source_info = self.source_info(user_ty_span); let annotation_index = - this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + self.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { span: user_ty_span, user_ty: user_ty.clone(), inferred_ty: expr.ty, }); - let place = place_builder.to_place(this); - this.cfg.push( + let place = place_builder.to_place(self); + self.cfg.push( block, Statement::new( ty_source_info, @@ -503,19 +502,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(place_builder) } ExprKind::ValueTypeAscription { source, ref user_ty, user_ty_span } => { - let source_expr = &this.thir[source]; + let source_expr = &self.thir[source]; let temp = unpack!( - block = this.as_temp(block, source_expr.temp_lifetime, source, mutability) + block = self.as_temp(block, source_expr.temp_lifetime, source, mutability) ); if let Some(user_ty) = user_ty { - let ty_source_info = this.source_info(user_ty_span); + let ty_source_info = self.source_info(user_ty_span); let annotation_index = - this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + self.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { span: user_ty_span, user_ty: user_ty.clone(), inferred_ty: expr.ty, }); - this.cfg.push( + self.cfg.push( block, Statement::new( ty_source_info, @@ -534,14 +533,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ExprKind::PlaceUnwrapUnsafeBinder { source } => { let place_builder = unpack!( - block = this.expr_as_place(block, source, mutability, fake_borrow_temps,) + block = self.expr_as_place(block, source, mutability, fake_borrow_temps,) ); block.and(place_builder.project(PlaceElem::UnwrapUnsafeBinder(expr.ty))) } ExprKind::ValueUnwrapUnsafeBinder { source } => { - let source_expr = &this.thir[source]; + let source_expr = &self.thir[source]; let temp = unpack!( - block = this.as_temp(block, source_expr.temp_lifetime, source, mutability) + block = self.as_temp(block, source_expr.temp_lifetime, source, mutability) ); block.and(PlaceBuilder::from(temp).project(PlaceElem::UnwrapUnsafeBinder(expr.ty))) } @@ -591,7 +590,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // these are not places, so we need to make a temporary. debug_assert!(!matches!(Category::of(&expr.kind), Some(Category::Place))); let temp = - unpack!(block = this.as_temp(block, expr.temp_lifetime, expr_id, mutability)); + unpack!(block = self.as_temp(block, expr.temp_lifetime, expr_id, mutability)); block.and(PlaceBuilder::from(temp)) } } diff --git a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs index 546bfc8ea547a..ffbb786ddbeed 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_rvalue.rs @@ -47,25 +47,24 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scope: TempLifetime, expr_id: ExprId, ) -> BlockAnd> { - let this = self; - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; debug!("expr_as_rvalue(block={:?}, scope={:?}, expr={:?})", block, scope, expr); let expr_span = expr.span; - let source_info = this.source_info(expr_span); + let source_info = self.source_info(expr_span); match expr.kind { ExprKind::ThreadLocalRef(did) => block.and(Rvalue::ThreadLocalRef(did)), ExprKind::Scope { region_scope, lint_level, value } => { let region_scope = (region_scope, source_info); - this.in_scope(region_scope, lint_level, |this| this.as_rvalue(block, scope, value)) + self.in_scope(region_scope, lint_level, |this| this.as_rvalue(block, scope, value)) } ExprKind::Repeat { value, count } => { - if Some(0) == count.try_to_target_usize(this.tcx) { - this.build_zero_repeat(block, value, scope, source_info) + if Some(0) == count.try_to_target_usize(self.tcx) { + self.build_zero_repeat(block, value, scope, source_info) } else { let value_operand = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, value, @@ -78,7 +77,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ExprKind::Binary { op, lhs, rhs } => { let lhs = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, lhs, @@ -88,30 +87,30 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); let rhs = unpack!( block = - this.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No) + self.as_operand(block, scope, rhs, LocalInfo::Boring, NeedsTemporary::No) ); - this.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs) + self.build_binary_op(block, op, expr_span, expr.ty, lhs, rhs) } ExprKind::Unary { op, arg } => { let arg = unpack!( block = - this.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No) + self.as_operand(block, scope, arg, LocalInfo::Boring, NeedsTemporary::No) ); // Check for -MIN on signed integers - if this.check_overflow && op == UnOp::Neg && expr.ty.is_signed() { - let bool_ty = this.tcx.types.bool; + if self.check_overflow && op == UnOp::Neg && expr.ty.is_signed() { + let bool_ty = self.tcx.types.bool; - let minval = this.minval_literal(expr_span, expr.ty); - let is_min = this.temp(bool_ty, expr_span); + let minval = self.minval_literal(expr_span, expr.ty); + let is_min = self.temp(bool_ty, expr_span); - this.cfg.push_assign( + self.cfg.push_assign( block, source_info, is_min, Rvalue::BinaryOp(BinOp::Eq, Box::new((arg.to_copy(), minval))), ); - block = this.assert( + block = self.assert( block, Operand::Move(is_min), false, @@ -122,9 +121,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(Rvalue::UnaryOp(op, arg)) } ExprKind::Box { value } => { - let value_ty = this.thir[value].ty; - let tcx = this.tcx; - let source_info = this.source_info(expr_span); + let value_ty = self.thir[value].ty; + let tcx = self.tcx; + let source_info = self.source_info(expr_span); let size = tcx.require_lang_item(LangItem::SizeOf, expr_span); let size = Operand::unevaluated_constant(tcx, size, &[value_ty.into()], expr_span); @@ -140,9 +139,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { [], expr_span, ); - let storage = this.temp(Ty::new_mut_ptr(tcx, tcx.types.u8), expr_span); - let success = this.cfg.start_new_block(); - this.cfg.terminate( + let storage = self.temp(Ty::new_mut_ptr(tcx, tcx.types.u8), expr_span); + let success = self.cfg.start_new_block(); + self.cfg.terminate( block, source_info, TerminatorKind::Call { @@ -159,29 +158,29 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn_span: expr_span, }, ); - this.diverge_from(block); + self.diverge_from(block); block = success; - let result = this.local_decls.push(LocalDecl::new(expr.ty, expr_span)); - this.cfg + let result = self.local_decls.push(LocalDecl::new(expr.ty, expr_span)); + self.cfg .push(block, Statement::new(source_info, StatementKind::StorageLive(result))); if let Some(scope) = scope.temp_lifetime { // schedule a shallow free of that memory, lest we unwind: - this.schedule_drop_storage_and_value(expr_span, scope, result); + self.schedule_drop_storage_and_value(expr_span, scope, result); } // Transmute `*mut u8` to the box (thus far, uninitialized): let box_ = Rvalue::ShallowInitBox(Operand::Move(storage), value_ty); - this.cfg.push_assign(block, source_info, Place::from(result), box_); + self.cfg.push_assign(block, source_info, Place::from(result), box_); // initialize the box contents: - block = this - .expr_into_dest(this.tcx.mk_place_deref(Place::from(result)), block, value) + block = self + .expr_into_dest(self.tcx.mk_place_deref(Place::from(result)), block, value) .into_block(); block.and(Rvalue::Use(Operand::Move(Place::from(result)))) } ExprKind::Cast { source } => { - let source_expr = &this.thir[source]; + let source_expr = &self.thir[source]; // Casting an enum to an integer is equivalent to computing the discriminant and casting the // discriminant. Previously every backend had to repeat the logic for this operation. Now we @@ -189,10 +188,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let (source, ty) = if let ty::Adt(adt_def, ..) = source_expr.ty.kind() && adt_def.is_enum() { - let discr_ty = adt_def.repr().discr_type().to_ty(this.tcx); - let temp = unpack!(block = this.as_temp(block, scope, source, Mutability::Not)); - let discr = this.temp(discr_ty, source_expr.span); - this.cfg.push_assign( + let discr_ty = adt_def.repr().discr_type().to_ty(self.tcx); + let temp = unpack!(block = self.as_temp(block, scope, source, Mutability::Not)); + let discr = self.temp(discr_ty, source_expr.span); + self.cfg.push_assign( block, source_info, discr, @@ -202,7 +201,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } else { let ty = source_expr.ty; let source = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, source, @@ -220,7 +219,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ExprKind::PointerCoercion { cast, source, is_from_as_cast } => { let source = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, source, @@ -260,13 +259,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // to the same MIR as `let x = ();`. // first process the set of fields - let el_ty = expr.ty.sequence_element_type(this.tcx); + let el_ty = expr.ty.sequence_element_type(self.tcx); let fields: IndexVec = fields .into_iter() .copied() .map(|f| { unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, f, @@ -287,7 +286,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .copied() .map(|f| { unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, f, @@ -322,12 +321,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // ``` // for (thir_place, cause, hir_id) in fake_reads.into_iter() { - let place_builder = unpack!(block = this.as_place_builder(block, *thir_place)); + let place_builder = unpack!(block = self.as_place_builder(block, *thir_place)); - if let Some(mir_place) = place_builder.try_to_place(this) { - this.cfg.push_fake_read( + if let Some(mir_place) = place_builder.try_to_place(self) { + self.cfg.push_fake_read( block, - this.source_info(this.tcx.hir_span(*hir_id)), + self.source_info(self.tcx.hir_span(*hir_id)), *cause, mir_place, ); @@ -339,7 +338,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .into_iter() .copied() .map(|upvar| { - let upvar_expr = &this.thir[upvar]; + let upvar_expr = &self.thir[upvar]; match Category::of(&upvar_expr.kind) { // Use as_place to avoid creating a temporary when // moving a variable into a closure, so that @@ -350,8 +349,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // This occurs when capturing by copy/move, while // by reference captures use as_operand Some(Category::Place) => { - let place = unpack!(block = this.as_place(block, upvar)); - this.consume_by_copy_or_move(place) + let place = unpack!(block = self.as_place(block, upvar)); + self.consume_by_copy_or_move(place) } _ => { // Turn mutable borrow captures into unique @@ -364,7 +363,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { BorrowKind::Mut { kind: MutBorrowKind::Default }, arg, } => unpack!( - block = this.limit_capture_mutability( + block = self.limit_capture_mutability( upvar_expr.span, upvar_expr.ty, scope.temp_lifetime, @@ -374,7 +373,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ), _ => { unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, upvar, @@ -403,11 +402,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.and(Rvalue::Aggregate(result, operands)) } ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => { - block = this.stmt_expr(block, expr_id, None).into_block(); + block = self.stmt_expr(block, expr_id, None).into_block(); block.and(Rvalue::Use(Operand::Constant(Box::new(ConstOperand { span: expr_span, user_ty: None, - const_: Const::zero_sized(this.tcx.types.unit), + const_: Const::zero_sized(self.tcx.types.unit), })))) } @@ -422,13 +421,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::ConstParam { .. } | ExprKind::ConstBlock { .. } | ExprKind::StaticRef { .. } => { - let constant = this.as_constant(expr); + let constant = self.as_constant(expr); block.and(Rvalue::Use(Operand::Constant(Box::new(constant)))) } ExprKind::WrapUnsafeBinder { source } => { let source = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, source, @@ -475,7 +474,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Some(Category::Rvalue(RvalueFunc::AsRvalue) | Category::Constant) )); let operand = unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, expr_id, @@ -489,7 +488,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ExprKind::ByUse { expr, span: _ } => { let operand = unpack!( block = - this.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::No) + self.as_operand(block, scope, expr, LocalInfo::Boring, NeedsTemporary::No) ); block.and(Rvalue::Use(operand)) } @@ -676,19 +675,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { scope: TempLifetime, outer_source_info: SourceInfo, ) -> BlockAnd> { - let this = self; - let value_expr = &this.thir[value]; + let value_expr = &self.thir[value]; let elem_ty = value_expr.ty; - if this.check_constness(&value_expr.kind) { + if self.check_constness(&value_expr.kind) { // Repeating a const does nothing } else { // For a non-const, we may need to generate an appropriate `Drop` let value_operand = unpack!( - block = this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No) + block = self.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No) ); if let Operand::Move(to_drop) = value_operand { - let success = this.cfg.start_new_block(); - this.cfg.terminate( + let success = self.cfg.start_new_block(); + self.cfg.terminate( block, outer_source_info, TerminatorKind::Drop { @@ -700,10 +698,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { async_fut: None, }, ); - this.diverge_from(block); + self.diverge_from(block); block = success; } - this.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]); + self.record_operands_moved(&[Spanned { node: value_operand, span: DUMMY_SP }]); } block.and(Rvalue::Aggregate(Box::new(AggregateKind::Array(elem_ty)), IndexVec::new())) } @@ -716,25 +714,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { mut block: BasicBlock, arg: ExprId, ) -> BlockAnd> { - let this = self; - - let source_info = this.source_info(upvar_span); - let temp = this.local_decls.push(LocalDecl::new(upvar_ty, upvar_span)); + let source_info = self.source_info(upvar_span); + let temp = self.local_decls.push(LocalDecl::new(upvar_ty, upvar_span)); - this.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp))); + self.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp))); - let arg_place_builder = unpack!(block = this.as_place_builder(block, arg)); + let arg_place_builder = unpack!(block = self.as_place_builder(block, arg)); let mutability = match arg_place_builder.base() { // We are capturing a path that starts off a local variable in the parent. // The mutability of the current capture is same as the mutability // of the local declaration in the parent. - PlaceBase::Local(local) => this.local_decls[local].mutability, + PlaceBase::Local(local) => self.local_decls[local].mutability, // Parent is a closure and we are capturing a path that is captured // by the parent itself. The mutability of the current capture // is same as that of the capture in the parent closure. PlaceBase::Upvar { .. } => { - let enclosing_upvars_resolved = arg_place_builder.to_place(this); + let enclosing_upvars_resolved = arg_place_builder.to_place(self); match enclosing_upvars_resolved.as_ref() { PlaceRef { @@ -753,12 +749,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); // Not in a closure debug_assert!( - this.upvars.len() > upvar_index.index(), + self.upvars.len() > upvar_index.index(), "Unexpected capture place, upvars={:#?}, upvar_index={:?}", - this.upvars, + self.upvars, upvar_index ); - this.upvars[upvar_index.index()].mutability + self.upvars[upvar_index.index()].mutability } _ => bug!("Unexpected capture place"), } @@ -770,19 +766,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Mutability::Mut => BorrowKind::Mut { kind: MutBorrowKind::Default }, }; - let arg_place = arg_place_builder.to_place(this); + let arg_place = arg_place_builder.to_place(self); - this.cfg.push_assign( + self.cfg.push_assign( block, source_info, Place::from(temp), - Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place), + Rvalue::Ref(self.tcx.lifetimes.re_erased, borrow_kind, arg_place), ); // This can be `None` if the expression's temporary scope was extended so that it can be // borrowed by a `const` or `static`. In that case, it's never dropped. if let Some(temp_lifetime) = temp_lifetime { - this.schedule_drop_storage_and_value(upvar_span, temp_lifetime, temp); + self.schedule_drop_storage_and_value(upvar_span, temp_lifetime, temp); } block.and(Operand::Move(Place::from(temp))) diff --git a/compiler/rustc_mir_build/src/builder/expr/as_temp.rs b/compiler/rustc_mir_build/src/builder/expr/as_temp.rs index b0ce3527d8b3d..8f6fe4474d6b4 100644 --- a/compiler/rustc_mir_build/src/builder/expr/as_temp.rs +++ b/compiler/rustc_mir_build/src/builder/expr/as_temp.rs @@ -34,21 +34,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr_id: ExprId, mutability: Mutability, ) -> BlockAnd { - let this = self; - - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; let expr_span = expr.span; - let source_info = this.source_info(expr_span); + let source_info = self.source_info(expr_span); if let ExprKind::Scope { region_scope, lint_level, value } = expr.kind { - return this.in_scope((region_scope, source_info), lint_level, |this| { + return self.in_scope((region_scope, source_info), lint_level, |this| { this.as_temp(block, temp_lifetime, value, mutability) }); } let expr_ty = expr.ty; - let deduplicate_temps = this.fixed_temps_scope.is_some() - && this.fixed_temps_scope == temp_lifetime.temp_lifetime; - let temp = if deduplicate_temps && let Some(temp_index) = this.fixed_temps.get(&expr_id) { + let deduplicate_temps = self.fixed_temps_scope.is_some() + && self.fixed_temps_scope == temp_lifetime.temp_lifetime; + let temp = if deduplicate_temps && let Some(temp_index) = self.fixed_temps.get(&expr_id) { *temp_index } else { let mut local_decl = LocalDecl::new(expr_ty, expr_span); @@ -56,14 +54,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { local_decl = local_decl.immutable(); } - debug!("creating temp {:?} with block_context: {:?}", local_decl, this.block_context); + debug!("creating temp {:?} with block_context: {:?}", local_decl, self.block_context); let local_info = match expr.kind { ExprKind::StaticRef { def_id, .. } => { - assert!(!this.tcx.is_thread_local_static(def_id)); + assert!(!self.tcx.is_thread_local_static(def_id)); LocalInfo::StaticRef { def_id, is_thread_local: false } } ExprKind::ThreadLocalRef(def_id) => { - assert!(this.tcx.is_thread_local_static(def_id)); + assert!(self.tcx.is_thread_local_static(def_id)); LocalInfo::StaticRef { def_id, is_thread_local: true } } ExprKind::NamedConst { def_id, .. } | ExprKind::ConstParam { def_id, .. } => { @@ -71,7 +69,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } // Find out whether this temp is being created within the // tail expression of a block whose result is ignored. - _ if let Some(tail_info) = this.block_context.currently_in_block_tail() => { + _ if let Some(tail_info) = self.block_context.currently_in_block_tail() => { LocalInfo::BlockTailTemp(tail_info) } @@ -79,18 +77,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { temp_lifetime.temp_lifetime => { LocalInfo::IfThenRescopeTemp { - if_then: HirId { owner: this.hir_id.owner, local_id }, + if_then: HirId { owner: self.hir_id.owner, local_id }, } } _ => LocalInfo::Boring, }; **local_decl.local_info.as_mut().unwrap_crate_local() = local_info; - this.local_decls.push(local_decl) + self.local_decls.push(local_decl) }; debug!(?temp); if deduplicate_temps { - this.fixed_temps.insert(expr_id, temp); + self.fixed_temps.insert(expr_id, temp); } let temp_place = Place::from(temp); @@ -99,10 +97,10 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // they are never assigned. ExprKind::Break { .. } | ExprKind::Continue { .. } | ExprKind::Return { .. } => (), ExprKind::Block { block } - if let Block { expr: None, targeted_by_break: false, .. } = this.thir[block] + if let Block { expr: None, targeted_by_break: false, .. } = self.thir[block] && expr_ty.is_never() => {} _ => { - this.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp))); + self.cfg.push(block, Statement::new(source_info, StatementKind::StorageLive(temp))); // In constants, `temp_lifetime` is `None` for temporaries that // live for the `'static` lifetime. Thus we do not drop these @@ -118,19 +116,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // `bar(&foo())` or anything within a block will keep the // regular drops just like runtime code. if let Some(temp_lifetime) = temp_lifetime.temp_lifetime { - this.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Storage); + self.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Storage); } } } - block = this.expr_into_dest(temp_place, block, expr_id).into_block(); + block = self.expr_into_dest(temp_place, block, expr_id).into_block(); if let Some(temp_lifetime) = temp_lifetime.temp_lifetime { - this.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Value); + self.schedule_drop(expr_span, temp_lifetime, temp, DropKind::Value); } if let Some(backwards_incompatible) = temp_lifetime.backwards_incompatible { - this.schedule_backwards_incompatible_drop(expr_span, backwards_incompatible, temp); + self.schedule_backwards_incompatible_drop(expr_span, backwards_incompatible, temp); } block.and(temp) diff --git a/compiler/rustc_mir_build/src/builder/expr/into.rs b/compiler/rustc_mir_build/src/builder/expr/into.rs index bb65ef28bdc8c..f1ad40edc1009 100644 --- a/compiler/rustc_mir_build/src/builder/expr/into.rs +++ b/compiler/rustc_mir_build/src/builder/expr/into.rs @@ -32,44 +32,43 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // since we frequently have to reference `self` from within a // closure, where `self` would be shadowed, it's easier to // just use the name `this` uniformly - let this = self; - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; let expr_span = expr.span; - let source_info = this.source_info(expr_span); + let source_info = self.source_info(expr_span); let expr_is_block_or_scope = matches!(expr.kind, ExprKind::Block { .. } | ExprKind::Scope { .. }); if !expr_is_block_or_scope { - this.block_context.push(BlockFrame::SubExpr); + self.block_context.push(BlockFrame::SubExpr); } let block_and = match expr.kind { ExprKind::Scope { region_scope, lint_level, value } => { let region_scope = (region_scope, source_info); ensure_sufficient_stack(|| { - this.in_scope(region_scope, lint_level, |this| { + self.in_scope(region_scope, lint_level, |this| { this.expr_into_dest(destination, block, value) }) }) } ExprKind::Block { block: ast_block } => { - this.ast_block(destination, block, ast_block, source_info) + self.ast_block(destination, block, ast_block, source_info) } - ExprKind::Match { scrutinee, ref arms, .. } => this.match_expr( + ExprKind::Match { scrutinee, ref arms, .. } => self.match_expr( destination, block, scrutinee, arms, expr_span, - this.thir[scrutinee].span, + self.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_span = self.thir[then].span; + let then_source_info = self.source_info(then_span); + let condition_scope = self.local_scope(); - let then_and_else_blocks = this.in_scope( + let then_and_else_blocks = self.in_scope( (if_then_scope, then_source_info), LintLevel::Inherited, |this| { @@ -111,19 +110,19 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // If there is an `else` arm, lower it into `else_blk`. if let Some(else_expr) = else_opt { - else_blk = this.expr_into_dest(destination, else_blk, else_expr).into_block(); + else_blk = self.expr_into_dest(destination, else_blk, else_expr).into_block(); } else { // There is no `else` arm, so we know both arms have type `()`. // Generate the implicit `else {}` by assigning unit. - let correct_si = this.source_info(expr_span.shrink_to_hi()); - this.cfg.push_assign_unit(else_blk, correct_si, destination, this.tcx); + let correct_si = self.source_info(expr_span.shrink_to_hi()); + self.cfg.push_assign_unit(else_blk, correct_si, destination, self.tcx); } // The `then` and `else` arms have been lowered into their respective // blocks, so make both of them meet up in a new block. - 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); + let join_block = self.cfg.start_new_block(); + self.cfg.goto(then_blk, source_info, join_block); + self.cfg.goto(else_blk, source_info, join_block); join_block.unit() } ExprKind::Let { .. } => { @@ -134,7 +133,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { span_bug!(expr_span, "unexpected let expression outside of if or match-guard"); } ExprKind::NeverToAny { source } => { - let source_expr = &this.thir[source]; + let source_expr = &self.thir[source]; let is_call = matches!(source_expr.kind, ExprKind::Call { .. } | ExprKind::InlineAsm { .. }); @@ -142,7 +141,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // exist in the generated MIR. unpack!( block = - this.as_temp(block, this.local_temp_lifetime(), source, Mutability::Mut) + self.as_temp(block, self.local_temp_lifetime(), source, Mutability::Mut) ); // This is an optimization. If the expression was a call then we already have an @@ -150,18 +149,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { if is_call { block.unit() } else { - this.cfg.terminate(block, source_info, TerminatorKind::Unreachable); - let end_block = this.cfg.start_new_block(); + self.cfg.terminate(block, source_info, TerminatorKind::Unreachable); + let end_block = self.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 condition_scope = self.local_scope(); + let source_info = self.source_info(expr.span); // We first evaluate the left-hand side of the predicate ... let (then_block, else_block) = - this.in_if_then_scope(condition_scope, expr.span, |this| { + self.in_if_then_scope(condition_scope, expr.span, |this| { this.then_else_break( block, lhs, @@ -182,25 +181,25 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // failing it leads to the short-circuting path which assigns `false` to the place. // - If the operator is `||`, failing `lhs` leads to continuation of evaluation on `rhs`; // passing it leads to the short-circuting path which assigns `true` to the place. - this.cfg.push_assign_constant( + self.cfg.push_assign_constant( short_circuit, source_info, destination, ConstOperand { span: expr.span, user_ty: None, - const_: Const::from_bool(this.tcx, constant), + const_: Const::from_bool(self.tcx, constant), }, ); let mut rhs_block = - this.expr_into_dest(destination, continuation, rhs).into_block(); + self.expr_into_dest(destination, continuation, rhs).into_block(); // Instrument the lowered RHS's value for condition coverage. // (Does nothing if condition coverage is not enabled.) - this.visit_coverage_standalone_condition(rhs, destination, &mut rhs_block); + self.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); + let target = self.cfg.start_new_block(); + self.cfg.goto(rhs_block, source_info, target); + self.cfg.goto(short_circuit, source_info, target); target.unit() } ExprKind::Loop { body } => { @@ -214,12 +213,12 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // The false link is required to make sure borrowck considers unwinds through the // body, even when the exact code in the body cannot unwind - let loop_block = this.cfg.start_new_block(); + let loop_block = self.cfg.start_new_block(); // Start the loop. - this.cfg.goto(block, source_info, loop_block); + self.cfg.goto(block, source_info, loop_block); - this.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| { + self.in_breakable_scope(Some(loop_block), destination, expr_span, move |this| { // conduct the test, if necessary let body_block = this.cfg.start_new_block(); this.cfg.terminate( @@ -268,18 +267,18 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } - let state_ty = this.thir.exprs[state].ty; + let state_ty = self.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 span = self.thir.exprs[state].span; + self.tcx.dcx().emit_fatal(LoopMatchUnsupportedType { span, ty: state_ty }) } - let loop_block = this.cfg.start_new_block(); + let loop_block = self.cfg.start_new_block(); // Start the loop. - this.cfg.goto(block, source_info, loop_block); + self.cfg.goto(block, source_info, loop_block); - this.in_breakable_scope(Some(loop_block), destination, expr_span, |this| { + self.in_breakable_scope(Some(loop_block), destination, expr_span, |this| { // Logic for `loop`. let mut body_block = this.cfg.start_new_block(); this.cfg.terminate( @@ -366,23 +365,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) } ExprKind::Call { ty: _, fun, ref args, from_hir_call, fn_span } => { - let fun = unpack!(block = this.as_local_operand(block, fun)); + let fun = unpack!(block = self.as_local_operand(block, fun)); let args: Box<[_]> = args .into_iter() .copied() .map(|arg| Spanned { - node: unpack!(block = this.as_local_call_operand(block, arg)), - span: this.thir.exprs[arg].span, + node: unpack!(block = self.as_local_call_operand(block, arg)), + span: self.thir.exprs[arg].span, }) .collect(); - let success = this.cfg.start_new_block(); + let success = self.cfg.start_new_block(); - this.record_operands_moved(&args); + self.record_operands_moved(&args); debug!("expr_into_dest: fn_span={:?}", fn_span); - this.cfg.terminate( + self.cfg.terminate( block, source_info, TerminatorKind::Call { @@ -399,36 +398,36 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { fn_span, }, ); - this.diverge_from(block); + self.diverge_from(block); success.unit() } ExprKind::ByUse { expr, span } => { - let place = unpack!(block = this.as_place(block, expr)); - let ty = place.ty(&this.local_decls, this.tcx).ty; + let place = unpack!(block = self.as_place(block, expr)); + let ty = place.ty(&self.local_decls, self.tcx).ty; - if this.tcx.type_is_copy_modulo_regions(this.infcx.typing_env(this.param_env), ty) { - this.cfg.push_assign( + if self.tcx.type_is_copy_modulo_regions(self.infcx.typing_env(self.param_env), ty) { + self.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) { + } else if self.infcx.type_is_use_cloned_modulo_regions(self.param_env, ty) { // Convert `expr.use` to a call like `Clone::clone(&expr)` - 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( + let success = self.cfg.start_new_block(); + let clone_trait = self.tcx.require_lang_item(LangItem::Clone, span); + let clone_fn = self.tcx.associated_item_def_ids(clone_trait)[0]; + let func = Operand::function_handle(self.tcx, clone_fn, [ty.into()], expr_span); + let ref_ty = Ty::new_imm_ref(self.tcx, self.tcx.lifetimes.re_erased, ty); + let ref_place = self.temp(ref_ty, span); + self.cfg.push_assign( block, source_info, ref_place, - Rvalue::Ref(this.tcx.lifetimes.re_erased, BorrowKind::Shared, place), + Rvalue::Ref(self.tcx.lifetimes.re_erased, BorrowKind::Shared, place), ); - this.cfg.terminate( + self.cfg.terminate( block, source_info, TerminatorKind::Call { @@ -444,7 +443,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); success.unit() } else { - this.cfg.push_assign( + self.cfg.push_assign( block, source_info, destination, @@ -453,7 +452,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block.unit() } } - ExprKind::Use { source } => this.expr_into_dest(destination, block, source), + ExprKind::Use { source } => self.expr_into_dest(destination, block, source), ExprKind::Borrow { arg, borrow_kind } => { // We don't do this in `as_rvalue` because we use `as_place` // for borrow expressions, so we cannot create an `RValue` that @@ -462,21 +461,21 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // unnecessary temporaries. let arg_place = match borrow_kind { BorrowKind::Shared => { - unpack!(block = this.as_read_only_place(block, arg)) + unpack!(block = self.as_read_only_place(block, arg)) } - _ => unpack!(block = this.as_place(block, arg)), + _ => unpack!(block = self.as_place(block, arg)), }; - let borrow = Rvalue::Ref(this.tcx.lifetimes.re_erased, borrow_kind, arg_place); - this.cfg.push_assign(block, source_info, destination, borrow); + let borrow = Rvalue::Ref(self.tcx.lifetimes.re_erased, borrow_kind, arg_place); + self.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), + hir::Mutability::Not => self.as_read_only_place(block, arg), + hir::Mutability::Mut => self.as_place(block, arg), }; let address_of = Rvalue::RawPtr(mutability.into(), unpack!(block = place)); - this.cfg.push_assign(block, source_info, destination, address_of); + self.cfg.push_assign(block, source_info, destination, address_of); block.unit() } ExprKind::Adt(box AdtExpr { @@ -492,7 +491,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let is_union = adt_def.is_union(); let active_field_index = is_union.then(|| fields[0].name); - let scope = this.local_temp_lifetime(); + let scope = self.local_temp_lifetime(); // first process the set of fields that were provided // (evaluating them in order given by user) @@ -502,7 +501,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ( f.name, unpack!( - block = this.as_operand( + block = self.as_operand( block, scope, f.expr, @@ -522,7 +521,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { field_names.filter_map(|n| fields_map.get(&n).cloned()).collect() } AdtExprBase::Base(FruInfo { base, field_types }) => { - let place_builder = unpack!(block = this.as_place_builder(block, *base)); + let place_builder = unpack!(block = self.as_place_builder(block, *base)); // We desugar FRU as we lower to MIR, so for each // base-supplied field, generate an operand that @@ -533,7 +532,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { None => { let place = place_builder.clone_project(PlaceElem::Field(n, *ty)); - this.consume_by_copy_or_move(place.to_place(this)) + self.consume_by_copy_or_move(place.to_place(self)) } }) .collect() @@ -569,7 +568,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let inferred_ty = expr.ty; let user_ty = user_ty.as_ref().map(|user_ty| { - this.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { + self.canonical_user_type_annotations.push(CanonicalUserTypeAnnotation { span: source_info.span, user_ty: user_ty.clone(), inferred_ty, @@ -582,7 +581,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { user_ty, active_field_index, )); - this.cfg.push_assign( + self.cfg.push_assign( block, source_info, destination, @@ -599,7 +598,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }) => { use rustc_middle::{mir, thir}; - let destination_block = this.cfg.start_new_block(); + let destination_block = self.cfg.start_new_block(); let mut targets = if asm_macro.diverges(options) { vec![] } else { vec![destination_block] }; @@ -608,17 +607,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|op| match *op { thir::InlineAsmOperand::In { reg, expr } => mir::InlineAsmOperand::In { reg, - value: unpack!(block = this.as_local_operand(block, expr)), + value: unpack!(block = self.as_local_operand(block, expr)), }, thir::InlineAsmOperand::Out { reg, late, expr } => { mir::InlineAsmOperand::Out { reg, late, - place: expr.map(|expr| unpack!(block = this.as_place(block, expr))), + place: expr.map(|expr| unpack!(block = self.as_place(block, expr))), } } thir::InlineAsmOperand::InOut { reg, late, expr } => { - let place = unpack!(block = this.as_place(block, expr)); + let place = unpack!(block = self.as_place(block, expr)); mir::InlineAsmOperand::InOut { reg, late, @@ -631,9 +630,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { mir::InlineAsmOperand::InOut { reg, late, - in_value: unpack!(block = this.as_local_operand(block, in_expr)), + in_value: unpack!(block = self.as_local_operand(block, in_expr)), out_place: out_expr.map(|out_expr| { - unpack!(block = this.as_place(block, out_expr)) + unpack!(block = self.as_place(block, out_expr)) }), } } @@ -647,20 +646,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } } thir::InlineAsmOperand::SymFn { value } => mir::InlineAsmOperand::SymFn { - value: Box::new(this.as_constant(&this.thir[value])), + value: Box::new(self.as_constant(&self.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 = self.cfg.start_new_block(); let target_index = targets.len(); targets.push(target); - let tmp = this.get_unit_temp(); + let tmp = self.get_unit_temp(); let target = - this.ast_block(tmp, target, block, source_info).into_block(); - this.cfg.terminate( + self.ast_block(tmp, target, block, source_info).into_block(); + self.cfg.terminate( target, source_info, TerminatorKind::Goto { target: destination_block }, @@ -672,7 +671,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .collect(); if !expr.ty.is_never() { - this.cfg.push_assign_unit(block, source_info, destination, this.tcx); + self.cfg.push_assign_unit(block, source_info, destination, self.tcx); } let asm_macro = match asm_macro { @@ -680,7 +679,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { AsmMacro::NakedAsm => InlineAsmMacro::NakedAsm, }; - this.cfg.terminate( + self.cfg.terminate( block, source_info, TerminatorKind::InlineAsm { @@ -698,15 +697,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }, ); if options.contains(InlineAsmOptions::MAY_UNWIND) { - this.diverge_from(block); + self.diverge_from(block); } destination_block.unit() } // These cases don't actually need a destination 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 = self.stmt_expr(block, expr_id, None).into_block(); + self.cfg.push_assign_unit(block, source_info, destination, self.tcx); block.unit() } @@ -715,7 +714,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::Break { .. } | ExprKind::Return { .. } | ExprKind::Become { .. } => { - block = this.stmt_expr(block, expr_id, None).into_block(); + block = self.stmt_expr(block, expr_id, None).into_block(); // No assign, as these have type `!`. block.unit() } @@ -729,9 +728,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::ValueUnwrapUnsafeBinder { .. } => { debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); - let place = unpack!(block = this.as_place(block, expr_id)); - let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place)); - this.cfg.push_assign(block, source_info, destination, rvalue); + let place = unpack!(block = self.as_place(block, expr_id)); + let rvalue = Rvalue::Use(self.consume_by_copy_or_move(place)); + self.cfg.push_assign(block, source_info, destination, rvalue); block.unit() } ExprKind::Index { .. } | ExprKind::Deref { .. } | ExprKind::Field { .. } => { @@ -741,28 +740,28 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // value is Sized. Usually, this is caught in type checking, but // in the case of box expr there is no such check. if !destination.projection.is_empty() { - this.local_decls.push(LocalDecl::new(expr.ty, expr.span)); + self.local_decls.push(LocalDecl::new(expr.ty, expr.span)); } - let place = unpack!(block = this.as_place(block, expr_id)); - let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place)); - this.cfg.push_assign(block, source_info, destination, rvalue); + let place = unpack!(block = self.as_place(block, expr_id)); + let rvalue = Rvalue::Use(self.consume_by_copy_or_move(place)); + self.cfg.push_assign(block, source_info, destination, rvalue); block.unit() } ExprKind::Yield { value } => { - let scope = this.local_temp_lifetime(); + let scope = self.local_temp_lifetime(); let value = unpack!( block = - this.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No) + self.as_operand(block, scope, value, LocalInfo::Boring, NeedsTemporary::No) ); - let resume = this.cfg.start_new_block(); - this.cfg.terminate( + let resume = self.cfg.start_new_block(); + self.cfg.terminate( block, source_info, TerminatorKind::Yield { value, resume, resume_arg: destination, drop: None }, ); - this.coroutine_drop_cleanup(block); + self.coroutine_drop_cleanup(block); resume.unit() } @@ -798,14 +797,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { _ => true, }); - let rvalue = unpack!(block = this.as_local_rvalue(block, expr_id)); - this.cfg.push_assign(block, source_info, destination, rvalue); + let rvalue = unpack!(block = self.as_local_rvalue(block, expr_id)); + self.cfg.push_assign(block, source_info, destination, rvalue); block.unit() } }; if !expr_is_block_or_scope { - let popped = this.block_context.pop(); + let popped = self.block_context.pop(); assert!(popped.is_some()); } diff --git a/compiler/rustc_mir_build/src/builder/expr/stmt.rs b/compiler/rustc_mir_build/src/builder/expr/stmt.rs index 675beceea14a9..feb371de3dc33 100644 --- a/compiler/rustc_mir_build/src/builder/expr/stmt.rs +++ b/compiler/rustc_mir_build/src/builder/expr/stmt.rs @@ -18,42 +18,41 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr_id: ExprId, statement_scope: Option, ) -> BlockAnd<()> { - let this = self; - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; let expr_span = expr.span; - let source_info = this.source_info(expr.span); + let source_info = self.source_info(expr.span); // Handle a number of expressions that don't need a destination at all. This // avoids needing a mountain of temporary `()` variables. match expr.kind { ExprKind::Scope { region_scope, lint_level, value } => { - this.in_scope((region_scope, source_info), lint_level, |this| { + self.in_scope((region_scope, source_info), lint_level, |this| { this.stmt_expr(block, value, statement_scope) }) } ExprKind::Assign { lhs, rhs } => { - let lhs_expr = &this.thir[lhs]; + let lhs_expr = &self.thir[lhs]; // Note: we evaluate assignments right-to-left. This // is better for borrowck interaction with overloaded // operators like x[j] = x[i]. debug!("stmt_expr Assign block_context.push(SubExpr) : {:?}", expr); - this.block_context.push(BlockFrame::SubExpr); + self.block_context.push(BlockFrame::SubExpr); // Generate better code for things that don't need to be // dropped. - if lhs_expr.ty.needs_drop(this.tcx, this.typing_env()) { - let rhs = unpack!(block = this.as_local_rvalue(block, rhs)); - let lhs = unpack!(block = this.as_place(block, lhs)); + if lhs_expr.ty.needs_drop(self.tcx, self.typing_env()) { + let rhs = unpack!(block = self.as_local_rvalue(block, rhs)); + let lhs = unpack!(block = self.as_place(block, lhs)); block = - this.build_drop_and_replace(block, lhs_expr.span, lhs, rhs).into_block(); + self.build_drop_and_replace(block, lhs_expr.span, lhs, rhs).into_block(); } else { - let rhs = unpack!(block = this.as_local_rvalue(block, rhs)); - let lhs = unpack!(block = this.as_place(block, lhs)); - this.cfg.push_assign(block, source_info, lhs, rhs); + let rhs = unpack!(block = self.as_local_rvalue(block, rhs)); + let lhs = unpack!(block = self.as_place(block, lhs)); + self.cfg.push_assign(block, source_info, lhs, rhs); } - this.block_context.pop(); + self.block_context.pop(); block.unit() } ExprKind::AssignOp { op, lhs, rhs } => { @@ -65,20 +64,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // only affects weird things like `x += {x += 1; x}` // -- is that equal to `x + (x + 1)` or `2*(x+1)`? - let lhs_ty = this.thir[lhs].ty; + let lhs_ty = self.thir[lhs].ty; debug!("stmt_expr AssignOp block_context.push(SubExpr) : {:?}", expr); - this.block_context.push(BlockFrame::SubExpr); + self.block_context.push(BlockFrame::SubExpr); // As above, RTL. - let rhs = unpack!(block = this.as_local_operand(block, rhs)); - let lhs = unpack!(block = this.as_place(block, lhs)); + let rhs = unpack!(block = self.as_local_operand(block, rhs)); + let lhs = unpack!(block = self.as_place(block, lhs)); // we don't have to drop prior contents or anything // because AssignOp is only legal for Copy types // (overloaded ops should be desugared into a call). let result = unpack!( - block = this.build_binary_op( + block = self.build_binary_op( block, op.into(), expr_span, @@ -87,35 +86,35 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { rhs ) ); - this.cfg.push_assign(block, source_info, lhs, result); + self.cfg.push_assign(block, source_info, lhs, result); - this.block_context.pop(); + self.block_context.pop(); block.unit() } ExprKind::Continue { label } => { - this.break_scope(block, None, BreakableTarget::Continue(label), source_info) + self.break_scope(block, None, BreakableTarget::Continue(label), source_info) } ExprKind::Break { label, value } => { - this.break_scope(block, value, BreakableTarget::Break(label), source_info) + self.break_scope(block, value, BreakableTarget::Break(label), source_info) } ExprKind::ConstContinue { label, value } => { - this.break_const_continuable_scope(block, value, label, source_info) + self.break_const_continuable_scope(block, value, label, source_info) } ExprKind::Return { value } => { - this.break_scope(block, value, BreakableTarget::Return, source_info) + self.break_scope(block, value, BreakableTarget::Return, source_info) } ExprKind::Become { value } => { - let v = &this.thir[value]; + let v = &self.thir[value]; let ExprKind::Scope { value, lint_level, region_scope } = v.kind else { span_bug!(v.span, "`thir_check_tail_calls` should have disallowed this {v:?}") }; - let v = &this.thir[value]; + let v = &self.thir[value]; let ExprKind::Call { ref args, fun, fn_span, .. } = v.kind else { span_bug!(v.span, "`thir_check_tail_calls` should have disallowed this {v:?}") }; - this.in_scope((region_scope, source_info), lint_level, |this| { + self.in_scope((region_scope, source_info), lint_level, |this| { let fun = unpack!(block = this.as_local_operand(block, fun)); let args: Box<[_]> = args .into_iter() @@ -156,23 +155,23 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // it is usually better to focus on `the_value` rather // than the entirety of block(s) surrounding it. let adjusted_span = if let ExprKind::Block { block } = expr.kind - && let Some(tail_ex) = this.thir[block].expr + && let Some(tail_ex) = self.thir[block].expr { - let mut expr = &this.thir[tail_ex]; + let mut expr = &self.thir[tail_ex]; loop { match expr.kind { ExprKind::Block { block } - if let Some(nested_expr) = this.thir[block].expr => + if let Some(nested_expr) = self.thir[block].expr => { - expr = &this.thir[nested_expr]; + expr = &self.thir[nested_expr]; } ExprKind::Scope { value: nested_expr, .. } => { - expr = &this.thir[nested_expr]; + expr = &self.thir[nested_expr]; } _ => break, } } - this.block_context.push(BlockFrame::TailExpr { + self.block_context.push(BlockFrame::TailExpr { info: BlockTailInfo { tail_result_is_ignored: true, span: expr.span }, }); Some(expr.span) @@ -181,7 +180,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }; let temp = unpack!( - block = this.as_temp( + block = self.as_temp( block, TempLifetime { temp_lifetime: statement_scope, @@ -193,8 +192,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); if let Some(span) = adjusted_span { - this.local_decls[temp].source_info.span = span; - this.block_context.pop(); + self.local_decls[temp].source_info.span = span; + self.block_context.pop(); } block.unit() diff --git a/compiler/rustc_mir_build/src/builder/matches/mod.rs b/compiler/rustc_mir_build/src/builder/matches/mod.rs index 96c58dc14e8cb..713878f3f07a2 100644 --- a/compiler/rustc_mir_build/src/builder/matches/mod.rs +++ b/compiler/rustc_mir_build/src/builder/matches/mod.rs @@ -109,21 +109,20 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr_id: ExprId, // Condition expression to lower args: ThenElseArgs, ) -> BlockAnd<()> { - let this = self; - let expr = &this.thir[expr_id]; + let expr = &self.thir[expr_id]; let expr_span = expr.span; match expr.kind { ExprKind::LogicalOp { op: LogicalOp::And, lhs, rhs } => { - let lhs_then_block = this.then_else_break_inner(block, lhs, args).into_block(); + let lhs_then_block = self.then_else_break_inner(block, lhs, args).into_block(); let rhs_then_block = - this.then_else_break_inner(lhs_then_block, rhs, args).into_block(); + self.then_else_break_inner(lhs_then_block, rhs, args).into_block(); rhs_then_block.unit() } ExprKind::LogicalOp { op: LogicalOp::Or, lhs, rhs } => { - let local_scope = this.local_scope(); + let local_scope = self.local_scope(); let (lhs_success_block, failure_block) = - this.in_if_then_scope(local_scope, expr_span, |this| { + self.in_if_then_scope(local_scope, expr_span, |this| { this.then_else_break_inner( block, lhs, @@ -133,7 +132,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }, ) }); - let rhs_success_block = this + let rhs_success_block = self .then_else_break_inner( failure_block, rhs, @@ -147,22 +146,22 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // Make the LHS and RHS success arms converge to a common block. // (We can't just make LHS goto RHS, because `rhs_success_block` // might contain statements that we don't want on the LHS path.) - let success_block = this.cfg.start_new_block(); - this.cfg.goto(lhs_success_block, args.variable_source_info, success_block); - this.cfg.goto(rhs_success_block, args.variable_source_info, success_block); + let success_block = self.cfg.start_new_block(); + self.cfg.goto(lhs_success_block, args.variable_source_info, success_block); + self.cfg.goto(rhs_success_block, args.variable_source_info, success_block); success_block.unit() } ExprKind::Unary { op: UnOp::Not, arg } => { // Improve branch coverage instrumentation by noting conditions // nested within one or more `!` expressions. // (Skipped if branch coverage is not enabled.) - if let Some(coverage_info) = this.coverage_info.as_mut() { - coverage_info.visit_unary_not(this.thir, expr_id); + if let Some(coverage_info) = self.coverage_info.as_mut() { + coverage_info.visit_unary_not(self.thir, expr_id); } - let local_scope = this.local_scope(); + let local_scope = self.local_scope(); let (success_block, failure_block) = - this.in_if_then_scope(local_scope, expr_span, |this| { + self.in_if_then_scope(local_scope, expr_span, |this| { // Help out coverage instrumentation by injecting a dummy statement with // the original condition's span (including `!`). This fixes #115468. if this.tcx.sess.instrument_coverage() { @@ -177,17 +176,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { }, ) }); - this.break_for_else(success_block, args.variable_source_info); + self.break_for_else(success_block, args.variable_source_info); failure_block.unit() } ExprKind::Scope { region_scope, lint_level, value } => { - let region_scope = (region_scope, this.source_info(expr_span)); - this.in_scope(region_scope, lint_level, |this| { + let region_scope = (region_scope, self.source_info(expr_span)); + self.in_scope(region_scope, lint_level, |this| { this.then_else_break_inner(block, value, args) }) } - ExprKind::Use { source } => this.then_else_break_inner(block, source, args), - ExprKind::Let { expr, ref pat } => this.lower_let_expr( + ExprKind::Use { source } => self.then_else_break_inner(block, source, args), + ExprKind::Let { expr, ref pat } => self.lower_let_expr( block, expr, pat, @@ -197,11 +196,11 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ), _ => { let mut block = block; - let temp_scope = args.temp_scope_override.unwrap_or_else(|| this.local_scope()); + let temp_scope = args.temp_scope_override.unwrap_or_else(|| self.local_scope()); let mutability = Mutability::Mut; let place = unpack!( - block = this.as_temp( + block = self.as_temp( block, TempLifetime { temp_lifetime: Some(temp_scope), @@ -214,17 +213,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let operand = Operand::Move(Place::from(place)); - let then_block = this.cfg.start_new_block(); - let else_block = this.cfg.start_new_block(); + let then_block = self.cfg.start_new_block(); + let else_block = self.cfg.start_new_block(); let term = TerminatorKind::if_(operand, then_block, else_block); // Record branch coverage info for this condition. // (Does nothing if branch coverage is not enabled.) - this.visit_coverage_branch_condition(expr_id, then_block, else_block); + self.visit_coverage_branch_condition(expr_id, then_block, else_block); - let source_info = this.source_info(expr_span); - this.cfg.terminate(block, source_info, term); - this.break_for_else(else_block, source_info); + let source_info = self.source_info(expr_span); + self.cfg.terminate(block, source_info, term); + self.break_for_else(else_block, source_info); then_block.unit() }