diff --git a/src/librustc/mir/mod.rs b/src/librustc/mir/mod.rs index 6f9cede7e46..9b1808c585c 100644 --- a/src/librustc/mir/mod.rs +++ b/src/librustc/mir/mod.rs @@ -2096,6 +2096,18 @@ fn iterate2( } } +impl From for Place<'_> { + fn from(local: Local) -> Self { + Place::Base(local.into()) + } +} + +impl From for PlaceBase<'_> { + fn from(local: Local) -> Self { + PlaceBase::Local(local) + } +} + /// A linked list of projections running up the stack; begins with the /// innermost projection and extends to the outermost (e.g., `a.b.c` /// would have the place `b` with a "next" pointer to `b.c`). diff --git a/src/librustc_codegen_ssa/mir/place.rs b/src/librustc_codegen_ssa/mir/place.rs index d56f39c6de2..be5d7b09965 100644 --- a/src/librustc_codegen_ssa/mir/place.rs +++ b/src/librustc_codegen_ssa/mir/place.rs @@ -470,7 +470,7 @@ pub fn codegen_place( } mir::ProjectionElem::Index(index) => { let index = &mir::Operand::Copy( - mir::Place::Base(mir::PlaceBase::Local(index)) + mir::Place::from(index) ); let index = self.codegen_operand(bx, index); let llindex = index.immediate(); diff --git a/src/librustc_mir/borrow_check/error_reporting.rs b/src/librustc_mir/borrow_check/error_reporting.rs index ac64cf79537..10c9a439bf7 100644 --- a/src/librustc_mir/borrow_check/error_reporting.rs +++ b/src/librustc_mir/borrow_check/error_reporting.rs @@ -627,7 +627,7 @@ pub(super) fn borrow_spans(&self, use_span: Span, location: Location) -> UseSpan def_id, is_generator, places ); if let Some((args_span, var_span)) = self.closure_span( - *def_id, &Place::Base(PlaceBase::Local(target)), places + *def_id, &Place::from(target), places ) { return ClosureUse { is_generator, diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 919ed5ccaba..4872440f5bd 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -620,7 +620,7 @@ fn visit_statement_entry( StatementKind::StorageDead(local) => { self.access_place( location, - (&Place::Base(PlaceBase::Local(local)), span), + (&Place::from(local), span), (Shallow(None), Write(WriteKind::StorageDeadOrDrop)), LocalMutationIsAllowed::Yes, flow_state, diff --git a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs index 4bc2f7064be..ed88b162535 100644 --- a/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs +++ b/src/librustc_mir/borrow_check/nll/explain_borrow/mod.rs @@ -252,7 +252,7 @@ pub(in crate::borrow_check) fn explain_why_borrow_contains_point( Some(Cause::LiveVar(local, location)) => { let span = body.source_info(location).span; let spans = self - .move_spans(&Place::Base(PlaceBase::Local(local)), location) + .move_spans(&Place::from(local), location) .or_else(|| self.borrow_spans(span, location)); let borrow_location = location; diff --git a/src/librustc_mir/borrow_check/nll/invalidation.rs b/src/librustc_mir/borrow_check/nll/invalidation.rs index c45c28c6146..c7b4a403052 100644 --- a/src/librustc_mir/borrow_check/nll/invalidation.rs +++ b/src/librustc_mir/borrow_check/nll/invalidation.rs @@ -11,7 +11,7 @@ use crate::dataflow::indexes::BorrowIndex; use rustc::ty::TyCtxt; use rustc::mir::visit::Visitor; -use rustc::mir::{BasicBlock, Location, Body, Place, PlaceBase, Rvalue}; +use rustc::mir::{BasicBlock, Location, Body, Place, Rvalue}; use rustc::mir::{Statement, StatementKind}; use rustc::mir::TerminatorKind; use rustc::mir::{Operand, BorrowKind}; @@ -124,7 +124,7 @@ fn visit_statement( StatementKind::StorageDead(local) => { self.access_place( location, - &Place::Base(PlaceBase::Local(local)), + &Place::from(local), (Shallow(None), Write(WriteKind::StorageDeadOrDrop)), LocalMutationIsAllowed::Yes, ); diff --git a/src/librustc_mir/borrow_check/nll/type_check/mod.rs b/src/librustc_mir/borrow_check/nll/type_check/mod.rs index e1f5964ff93..9409fefb6bd 100644 --- a/src/librustc_mir/borrow_check/nll/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/nll/type_check/mod.rs @@ -632,7 +632,7 @@ fn sanitize_projection( ) } ProjectionElem::Index(i) => { - let index_ty = Place::Base(PlaceBase::Local(i)).ty(self.body, tcx).ty; + let index_ty = Place::from(i).ty(self.body, tcx).ty; if index_ty != tcx.types.usize { PlaceTy::from_ty( span_mirbug_and_err!(self, i, "index by non-usize {:?}", i), diff --git a/src/librustc_mir/build/expr/as_operand.rs b/src/librustc_mir/build/expr/as_operand.rs index dd78e7e869a..207399fbdcf 100644 --- a/src/librustc_mir/build/expr/as_operand.rs +++ b/src/librustc_mir/build/expr/as_operand.rs @@ -74,7 +74,7 @@ fn expr_as_operand( } Category::Place | Category::Rvalue(..) => { let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut)); - block.and(Operand::Move(Place::Base(PlaceBase::Local(operand)))) + block.and(Operand::Move(Place::from(operand))) } } } diff --git a/src/librustc_mir/build/expr/as_place.rs b/src/librustc_mir/build/expr/as_place.rs index 51808ef7ebd..0640c01d255 100644 --- a/src/librustc_mir/build/expr/as_place.rs +++ b/src/librustc_mir/build/expr/as_place.rs @@ -98,26 +98,26 @@ fn expr_as_place( <, Rvalue::BinaryOp( BinOp::Lt, - Operand::Copy(Place::Base(PlaceBase::Local(idx))), + Operand::Copy(Place::from(idx)), Operand::Copy(len.clone()), ), ); let msg = BoundsCheck { len: Operand::Move(len), - index: Operand::Copy(Place::Base(PlaceBase::Local(idx))), + index: Operand::Copy(Place::from(idx)), }; let success = this.assert(block, Operand::Move(lt), true, msg, expr_span); success.and(slice.index(idx)) } - ExprKind::SelfRef => block.and(Place::Base(PlaceBase::Local(Local::new(1)))), + ExprKind::SelfRef => block.and(Place::from(Local::new(1))), ExprKind::VarRef { id } => { let place = if this.is_bound_var_in_guard(id) { let index = this.var_local_id(id, RefWithinGuard); - Place::Base(PlaceBase::Local(index)).deref() + Place::from(index).deref() } else { let index = this.var_local_id(id, OutsideGuard); - Place::Base(PlaceBase::Local(index)) + Place::from(index) }; block.and(place) } @@ -168,14 +168,14 @@ fn expr_as_place( Statement { source_info, kind: StatementKind::AscribeUserType( - Place::Base(PlaceBase::Local(temp.clone())), + Place::from(temp.clone()), Variance::Invariant, box UserTypeProjection { base: annotation_index, projs: vec![], }, ), }, ); } - block.and(Place::Base(PlaceBase::Local(temp))) + block.and(Place::from(temp)) } ExprKind::Array { .. } @@ -211,7 +211,7 @@ fn expr_as_place( }); let temp = unpack!(block = this.as_temp(block, expr.temp_lifetime, expr, mutability)); - block.and(Place::Base(PlaceBase::Local(temp))) + block.and(Place::from(temp)) } } } diff --git a/src/librustc_mir/build/expr/as_rvalue.rs b/src/librustc_mir/build/expr/as_rvalue.rs index 243c13c2982..73ce2a5dc9b 100644 --- a/src/librustc_mir/build/expr/as_rvalue.rs +++ b/src/librustc_mir/build/expr/as_rvalue.rs @@ -127,7 +127,7 @@ fn expr_as_rvalue( this.schedule_drop_storage_and_value( expr_span, scope, - &Place::Base(PlaceBase::Local(result)), + &Place::from(result), value.ty, ); } @@ -135,16 +135,16 @@ fn expr_as_rvalue( // malloc some memory of suitable type (thus far, uninitialized): let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty); this.cfg - .push_assign(block, source_info, &Place::Base(PlaceBase::Local(result)), box_); + .push_assign(block, source_info, &Place::from(result), box_); // initialize the box contents: unpack!( block = this.into( - &Place::Base(PlaceBase::Local(result)).deref(), + &Place::from(result).deref(), block, value ) ); - block.and(Rvalue::Use(Operand::Move(Place::Base(PlaceBase::Local(result))))) + block.and(Rvalue::Use(Operand::Move(Place::from(result)))) } ExprKind::Cast { source } => { let source = unpack!(block = this.as_operand(block, scope, source)); @@ -548,7 +548,7 @@ fn limit_capture_mutability( this.cfg.push_assign( block, source_info, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place), ); @@ -559,12 +559,12 @@ fn limit_capture_mutability( this.schedule_drop_storage_and_value( upvar_span, temp_lifetime, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), upvar_ty, ); } - block.and(Operand::Move(Place::Base(PlaceBase::Local(temp)))) + block.and(Operand::Move(Place::from(temp))) } // Helper to get a `-1` value of the appropriate type diff --git a/src/librustc_mir/build/expr/as_temp.rs b/src/librustc_mir/build/expr/as_temp.rs index 9d907c6ec04..1b3ebac4a3d 100644 --- a/src/librustc_mir/build/expr/as_temp.rs +++ b/src/librustc_mir/build/expr/as_temp.rs @@ -64,7 +64,7 @@ fn expr_as_temp( } this.local_decls.push(local_decl) }; - let temp_place = &Place::Base(PlaceBase::Local(temp)); + let temp_place = &Place::from(temp); if !expr_ty.is_never() { this.cfg.push( diff --git a/src/librustc_mir/build/expr/into.rs b/src/librustc_mir/build/expr/into.rs index a3976238fbe..f70ecef0c25 100644 --- a/src/librustc_mir/build/expr/into.rs +++ b/src/librustc_mir/build/expr/into.rs @@ -258,7 +258,7 @@ pub fn into_expr( is_user_variable: None, is_block_tail: None, }); - let ptr_temp = Place::Base(PlaceBase::Local(ptr_temp)); + let ptr_temp = Place::from(ptr_temp); let block = unpack!(this.into(&ptr_temp, block, ptr)); this.into(&ptr_temp.deref(), block, val) } else { diff --git a/src/librustc_mir/build/expr/stmt.rs b/src/librustc_mir/build/expr/stmt.rs index 74338de6775..4463e7fd4d4 100644 --- a/src/librustc_mir/build/expr/stmt.rs +++ b/src/librustc_mir/build/expr/stmt.rs @@ -235,7 +235,7 @@ pub fn stmt_expr(&mut self, } } let temp = this.local_decls.push(local_decl); - let place = Place::Base(PlaceBase::Local(temp)); + let place = Place::from(temp); debug!("created temp {:?} for expr {:?} in block_context: {:?}", temp, expr, this.block_context); place diff --git a/src/librustc_mir/build/matches/mod.rs b/src/librustc_mir/build/matches/mod.rs index 55093f28a42..d2e56c4981f 100644 --- a/src/librustc_mir/build/matches/mod.rs +++ b/src/librustc_mir/build/matches/mod.rs @@ -531,7 +531,7 @@ pub fn storage_live_binding( kind: StatementKind::StorageLive(local_id), }, ); - let place = Place::Base(PlaceBase::Local(local_id)); + let place = Place::from(local_id); let var_ty = self.local_decls[local_id].ty; let region_scope = self.hir.region_scope_tree.var_scope(var.local_id); self.schedule_drop(span, region_scope, &place, var_ty, DropKind::Storage); @@ -545,7 +545,7 @@ pub fn schedule_drop_for_binding(&mut self, var: HirId, span: Span, for_guard: F self.schedule_drop( span, region_scope, - &Place::Base(PlaceBase::Local(local_id)), + &Place::from(local_id), var_ty, DropKind::Value, ); @@ -1478,7 +1478,7 @@ fn bind_and_guard_matched_candidate<'pat>( self.cfg.push_assign( block, scrutinee_source_info, - &Place::Base(PlaceBase::Local(temp)), + &Place::from(temp), borrow, ); } @@ -1502,7 +1502,7 @@ fn bind_and_guard_matched_candidate<'pat>( source_info: guard_end, kind: StatementKind::FakeRead( FakeReadCause::ForMatchGuard, - Place::Base(PlaceBase::Local(temp)), + Place::from(temp), ), }); } @@ -1575,7 +1575,7 @@ fn bind_and_guard_matched_candidate<'pat>( // place they refer to can't be modified by the guard. for binding in by_value_bindings.clone() { let local_id = self.var_local_id(binding.var_id, RefWithinGuard); - let place = Place::Base(PlaceBase::Local(local_id)); + let place = Place::from(local_id); self.cfg.push( block, Statement { diff --git a/src/librustc_mir/build/misc.rs b/src/librustc_mir/build/misc.rs index ad891b1c1ea..56025eeaaa9 100644 --- a/src/librustc_mir/build/misc.rs +++ b/src/librustc_mir/build/misc.rs @@ -16,7 +16,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// call `schedule_drop` once the temporary is initialized. pub fn temp(&mut self, ty: Ty<'tcx>, span: Span) -> Place<'tcx> { let temp = self.local_decls.push(LocalDecl::new_temp(ty, span)); - let place = Place::Base(PlaceBase::Local(temp)); + let place = Place::from(temp); debug!("temp: created temp {:?} with type {:?}", place, self.local_decls[temp].ty); place diff --git a/src/librustc_mir/build/mod.rs b/src/librustc_mir/build/mod.rs index 311b6aa0c14..0957dcbf3ea 100644 --- a/src/librustc_mir/build/mod.rs +++ b/src/librustc_mir/build/mod.rs @@ -808,7 +808,7 @@ fn args_and_body(&mut self, for (index, arg_info) in arguments.iter().enumerate() { // Function arguments always get the first Local indices after the return place let local = Local::new(index + 1); - let place = Place::Base(PlaceBase::Local(local)); + let place = Place::from(local); let &ArgInfo(ty, opt_ty_info, pattern, ref self_binding) = arg_info; // Make sure we drop (parts of) the argument even when not matched on. diff --git a/src/librustc_mir/dataflow/drop_flag_effects.rs b/src/librustc_mir/dataflow/drop_flag_effects.rs index 37f2a915782..a73ec2ed8e0 100644 --- a/src/librustc_mir/dataflow/drop_flag_effects.rs +++ b/src/librustc_mir/dataflow/drop_flag_effects.rs @@ -170,7 +170,7 @@ pub(crate) fn drop_flag_effects_for_function_entry<'tcx, F>( { let move_data = &ctxt.move_data; for arg in body.args_iter() { - let place = mir::Place::Base(mir::PlaceBase::Local(arg)); + let place = mir::Place::from(arg); let lookup_result = move_data.rev_lookup.find(&place); on_lookup_result_bits(tcx, body, move_data, lookup_result, diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 53d00d44e3f..dcc6ba5ca05 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -288,7 +288,7 @@ fn statement_effect(&self, mir::StatementKind::StorageDead(local) => { // Make sure there are no remaining borrows for locals that // are gone out of scope. - self.kill_borrows_on_place(trans, &Place::Base(PlaceBase::Local(local))); + self.kill_borrows_on_place(trans, &Place::from(local)); } mir::StatementKind::InlineAsm(ref asm) => { diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index e8386e8fef1..f282c276e09 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -33,13 +33,13 @@ fn new(body: &'a Body<'tcx>, tcx: TyCtxt<'tcx>) -> Self { moves: IndexVec::new(), loc_map: LocationMap::new(body), rev_lookup: MovePathLookup { - locals: body.local_decls.indices().map(PlaceBase::Local).map(|v| { + locals: body.local_decls.indices().map(|i| { Self::new_move_path( &mut move_paths, &mut path_map, &mut init_path_map, None, - Place::Base(v), + Place::from(i), ) }).collect(), projections: Default::default(), @@ -289,7 +289,7 @@ fn gather_statement(&mut self, stmt: &Statement<'tcx>) { } StatementKind::StorageLive(_) => {} StatementKind::StorageDead(local) => { - self.gather_move(&Place::Base(PlaceBase::Local(local))); + self.gather_move(&Place::from(local)); } StatementKind::SetDiscriminant{ .. } => { span_bug!(stmt.source_info.span, diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index a29611e4814..13baf245d10 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -355,7 +355,7 @@ fn eval_fn_call( let mut locals_iter = body.args_iter(); while let Some(local) = locals_iter.next() { let dest = self.eval_place( - &mir::Place::Base(mir::PlaceBase::Local(local)) + &mir::Place::from(local) )?; if Some(local) == body.spread_arg { // Must be a tuple diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index c04672f8331..7987095a334 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -213,7 +213,7 @@ fn build_drop_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, ty: Option>) if let Some(..) = ty { // The first argument (index 0), but add 1 for the return value. - let dropee_ptr = Place::Base(PlaceBase::Local(Local::new(1+0))); + let dropee_ptr = Place::from(Local::new(1+0)); if tcx.sess.opts.debugging_opts.mir_emit_retag { // Function arguments should be retagged, and we make this one raw. body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement { @@ -308,7 +308,7 @@ fn build_clone_shim<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, self_ty: Ty<'tcx>) - let is_copy = self_ty.is_copy_modulo_regions(tcx, tcx.param_env(def_id), builder.span); let dest = Place::RETURN_PLACE; - let src = Place::Base(PlaceBase::Local(Local::new(1+0))).deref(); + let src = Place::from(Local::new(1+0)).deref(); match self_ty.sty { _ if is_copy => builder.copy_shim(), @@ -412,7 +412,7 @@ fn make_statement(&self, kind: StatementKind<'tcx>) -> Statement<'tcx> { } fn copy_shim(&mut self) { - let rcvr = Place::Base(PlaceBase::Local(Local::new(1+0))).deref(); + let rcvr = Place::from(Local::new(1+0)).deref(); let ret_statement = self.make_statement( StatementKind::Assign( Place::RETURN_PLACE, @@ -424,9 +424,7 @@ fn copy_shim(&mut self) { fn make_place(&mut self, mutability: Mutability, ty: Ty<'tcx>) -> Place<'tcx> { let span = self.span; - Place::Base(PlaceBase::Local( - self.local_decls.push(temp_decl(mutability, ty, span)) - )) + Place::from(self.local_decls.push(temp_decl(mutability, ty, span))) } fn make_clone_call( @@ -525,7 +523,7 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: let inits = vec![ self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::Use(Operand::Constant(self.make_usize(0))) ) ), @@ -543,7 +541,7 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: // BB #3; // } // BB #4; - self.loop_header(Place::Base(PlaceBase::Local(beg)), + self.loop_header(Place::from(beg), end, BasicBlock::new(2), BasicBlock::new(4), @@ -563,10 +561,10 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: let statements = vec![ self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::BinaryOp( BinOp::Add, - Operand::Copy(Place::Base(PlaceBase::Local(beg))), + Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)) ) ) @@ -586,7 +584,7 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: let beg = self.local_decls.push(temp_decl(Mutability::Mut, tcx.types.usize, span)); let init = self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::Use(Operand::Constant(self.make_usize(0))) ) ); @@ -597,7 +595,7 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: // BB #8; // } // BB #9; - self.loop_header(Place::Base(PlaceBase::Local(beg)), Place::Base(PlaceBase::Local(end)), + self.loop_header(Place::from(beg), Place::from(end), BasicBlock::new(7), BasicBlock::new(9), true); // BB #7 (cleanup) @@ -613,10 +611,10 @@ fn array_shim(&mut self, dest: Place<'tcx>, src: Place<'tcx>, ty: Ty<'tcx>, len: // `goto #6;` let statement = self.make_statement( StatementKind::Assign( - Place::Base(PlaceBase::Local(beg)), + Place::from(beg), box Rvalue::BinaryOp( BinOp::Add, - Operand::Copy(Place::Base(PlaceBase::Local(beg))), + Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)) ) ) @@ -701,7 +699,7 @@ fn build_call_shim<'tcx>( let source_info = SourceInfo { span, scope: OUTERMOST_SOURCE_SCOPE }; let rcvr_arg = Local::new(1+0); - let rcvr_l = Place::Base(PlaceBase::Local(rcvr_arg)); + let rcvr_l = Place::from(rcvr_arg); let mut statements = vec![]; let rcvr = match rcvr_adjustment { @@ -731,11 +729,11 @@ fn build_call_shim<'tcx>( statements.push(Statement { source_info, kind: StatementKind::Assign( - Place::Base(PlaceBase::Local(ref_rcvr)), + Place::from(ref_rcvr), box Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_l) ) }); - Operand::Move(Place::Base(PlaceBase::Local(ref_rcvr))) + Operand::Move(Place::from(ref_rcvr)) } }; @@ -755,12 +753,12 @@ fn build_call_shim<'tcx>( if let Some(untuple_args) = untuple_args { args.extend(untuple_args.iter().enumerate().map(|(i, ity)| { - let arg_place = Place::Base(PlaceBase::Local(Local::new(1+1))); + let arg_place = Place::from(Local::new(1+1)); Operand::Move(arg_place.field(Field::new(i), *ity)) })); } else { args.extend((1..sig.inputs().len()).map(|i| { - Operand::Move(Place::Base(PlaceBase::Local(Local::new(1+i)))) + Operand::Move(Place::from(Local::new(1+i))) })); } @@ -791,7 +789,7 @@ fn build_call_shim<'tcx>( if let Adjustment::RefMut = rcvr_adjustment { // BB #1 - drop for Self block(&mut blocks, vec![], TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(rcvr_arg)), + location: Place::from(rcvr_arg), target: BasicBlock::new(2), unwind: None }, false); @@ -801,7 +799,7 @@ fn build_call_shim<'tcx>( if let Adjustment::RefMut = rcvr_adjustment { // BB #3 - drop if closure panics block(&mut blocks, vec![], TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(rcvr_arg)), + location: Place::from(rcvr_arg), target: BasicBlock::new(4), unwind: None }, true); @@ -881,7 +879,7 @@ pub fn build_adt_ctor<'tcx>(tcx: TyCtxt<'tcx>, ctor_id: DefId) -> &'tcx Body<'tc .iter() .enumerate() .map(|(idx, field_def)| ( - Operand::Move(Place::Base(PlaceBase::Local(Local::new(idx + 1)))), + Operand::Move(Place::from(Local::new(idx + 1))), field_def.ty(tcx, substs), )), AggregateKind::Adt(adt_def, variant_index, substs, None, None), diff --git a/src/librustc_mir/transform/add_moves_for_packed_drops.rs b/src/librustc_mir/transform/add_moves_for_packed_drops.rs index a111669f149..426e16698d7 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -112,10 +112,10 @@ fn add_move_for_packed_drop<'tcx>( patch.add_statement( loc, StatementKind::StorageLive(temp)); - patch.add_assign(loc, Place::Base(PlaceBase::Local(temp)), + patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(location.clone()))); patch.patch_terminator(loc.block, TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(temp)), + location: Place::from(temp), target: storage_dead_block, unwind }); diff --git a/src/librustc_mir/transform/add_retag.rs b/src/librustc_mir/transform/add_retag.rs index ee040bf6590..e01017d7c9b 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -96,7 +96,7 @@ fn run_pass<'tcx>(&self, tcx: TyCtxt<'tcx>, _src: MirSource<'tcx>, body: &mut Bo }; // Gather all arguments, skip return value. let places = local_decls.iter_enumerated().skip(1).take(arg_count) - .map(|(local, _)| Place::Base(PlaceBase::Local(local))) + .map(|(local, _)| Place::from(local)) .filter(needs_retag) .collect::>(); // Emit their retags. diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index b2b489b2e38..ad19b974d7d 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -326,7 +326,7 @@ fn create_drop_flag(&mut self, index: MovePathIndex, span: Span) { } fn drop_flag(&mut self, index: MovePathIndex) -> Option> { - self.drop_flags.get(&index).map(|t| Place::Base(PlaceBase::Local(*t))) + self.drop_flags.get(&index).map(|t| Place::from(*t)) } /// create a patch that elaborates all drops in the input @@ -537,7 +537,7 @@ fn set_drop_flag(&mut self, loc: Location, path: MovePathIndex, val: DropFlagSta if let Some(&flag) = self.drop_flags.get(&path) { let span = self.patch.source_info_for_location(self.body, loc).span; let val = self.constant_bool(span, val.value()); - self.patch.add_assign(loc, Place::Base(PlaceBase::Local(flag)), val); + self.patch.add_assign(loc, Place::from(flag), val); } } @@ -546,7 +546,7 @@ fn drop_flags_on_init(&mut self) { let span = self.patch.source_info_for_location(self.body, loc).span; let false_ = self.constant_bool(span, false); for flag in self.drop_flags.values() { - self.patch.add_assign(loc, Place::Base(PlaceBase::Local(*flag)), false_.clone()); + self.patch.add_assign(loc, Place::from(*flag), false_.clone()); } } diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index ba8c47c665e..7b961e97a10 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -200,7 +200,7 @@ fn make_state(&self, idx: VariantIdx, val: Operand<'tcx>) -> Rvalue<'tcx> { // Create a Place referencing a generator struct field fn make_field(&self, variant_index: VariantIdx, idx: usize, ty: Ty<'tcx>) -> Place<'tcx> { - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); let base = self_place.downcast_unnamed(variant_index); let field = Projection { base: base, @@ -211,7 +211,7 @@ fn make_field(&self, variant_index: VariantIdx, idx: usize, ty: Ty<'tcx>) -> Pla // Create a statement which changes the discriminant fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statement<'tcx> { - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); Statement { source_info, kind: StatementKind::SetDiscriminant { place: self_place, variant_index: state_disc }, @@ -222,9 +222,9 @@ fn set_discr(&self, state_disc: VariantIdx, source_info: SourceInfo) -> Statemen fn get_discr(&self, body: &mut Body<'tcx>) -> (Statement<'tcx>, Place<'tcx>) { let temp_decl = LocalDecl::new_internal(self.tcx.types.isize, body.span); let local_decls_len = body.local_decls.push(temp_decl); - let temp = Place::Base(PlaceBase::Local(local_decls_len)); + let temp = Place::from(local_decls_len); - let self_place = Place::Base(PlaceBase::Local(self_arg())); + let self_place = Place::from(self_arg()); let assign = Statement { source_info: source_info(body), kind: StatementKind::Assign(temp.clone(), box Rvalue::Discriminant(self_place)), @@ -271,7 +271,7 @@ fn visit_basic_block_data(&mut self, let ret_val = match data.terminator().kind { TerminatorKind::Return => Some((VariantIdx::new(1), None, - Operand::Move(Place::Base(PlaceBase::Local(self.new_ret_local))), + Operand::Move(Place::from(self.new_ret_local)), None)), TerminatorKind::Yield { ref value, resume, drop } => Some((VariantIdx::new(0), Some(resume), @@ -840,7 +840,7 @@ fn elaborate_generator_drops<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId, body: &mut elaborate_drop( &mut elaborator, source_info, - &Place::Base(PlaceBase::Local(gen)), + &Place::from(gen), (), target, unwind, @@ -913,7 +913,7 @@ fn create_generator_drop_shim<'tcx>( // Alias tracking must know we changed the type body.basic_blocks_mut()[START_BLOCK].statements.insert(0, Statement { source_info, - kind: StatementKind::Retag(RetagKind::Raw, Place::Base(PlaceBase::Local(self_arg()))), + kind: StatementKind::Retag(RetagKind::Raw, Place::from(self_arg())), }) } @@ -1031,7 +1031,7 @@ fn insert_clean_drop<'tcx>(body: &mut Body<'tcx>) -> BasicBlock { // Create a block to destroy an unresumed generators. This can only destroy upvars. let drop_clean = BasicBlock::new(body.basic_blocks().len()); let term = TerminatorKind::Drop { - location: Place::Base(PlaceBase::Local(self_arg())), + location: Place::from(self_arg()), target: return_block, unwind: None, }; diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index e2f98e46dba..dc73e58d15c 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -467,7 +467,7 @@ fn dest_needs_borrow(place: &Place<'_>) -> bool { let temp = LocalDecl::new_temp(ty, callsite.location.span); let tmp = caller_body.local_decls.push(temp); - let tmp = Place::Base(PlaceBase::Local(tmp)); + let tmp = Place::from(tmp); let stmt = Statement { source_info: callsite.location, @@ -561,7 +561,7 @@ fn make_call_args( let tuple = self.create_temp_if_necessary(args.next().unwrap(), callsite, caller_body); assert!(args.next().is_none()); - let tuple = Place::Base(PlaceBase::Local(tuple)); + let tuple = Place::from(tuple); let tuple_tys = if let ty::Tuple(s) = tuple.ty(caller_body, tcx).ty.sty { s } else { @@ -621,7 +621,7 @@ fn create_temp_if_necessary( let stmt = Statement { source_info: callsite.location, - kind: StatementKind::Assign(Place::Base(PlaceBase::Local(arg_tmp)), box arg), + kind: StatementKind::Assign(Place::from(arg_tmp), box arg), }; caller_body[callsite.bb].statements.push(stmt); arg_tmp diff --git a/src/librustc_mir/transform/lower_128bit.rs b/src/librustc_mir/transform/lower_128bit.rs index f0aa189804f..f09a77d486c 100644 --- a/src/librustc_mir/transform/lower_128bit.rs +++ b/src/librustc_mir/transform/lower_128bit.rs @@ -83,13 +83,13 @@ fn lower_128bit_ops<'tcx>(&self, tcx: TyCtxt<'tcx>, body: &mut Body<'tcx>) { block.statements.push(Statement { source_info: source_info, kind: StatementKind::Assign( - Place::Base(PlaceBase::Local(local)), + Place::from(local), box Rvalue::Cast( CastKind::Misc, rhs, rhs_override_ty.unwrap())), }); - rhs = Operand::Move(Place::Base(PlaceBase::Local(local))); + rhs = Operand::Move(Place::from(local)); } let call_did = check_lang_item_type( diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index d78adfe433c..b1804fb0ab3 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -182,7 +182,7 @@ fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) { span, scope: OUTERMOST_SOURCE_SCOPE }, - kind: StatementKind::Assign(Place::Base(PlaceBase::Local(dest)), box rvalue) + kind: StatementKind::Assign(Place::from(dest), box rvalue) }); } @@ -273,7 +273,7 @@ fn promote_temp(&mut self, temp: Local) -> Local { args, cleanup: None, destination: Some( - (Place::Base(PlaceBase::Local(new_temp)), new_target) + (Place::from(new_temp), new_target) ), from_hir_call, }, diff --git a/src/librustc_mir/transform/uniform_array_move_out.rs b/src/librustc_mir/transform/uniform_array_move_out.rs index 812a024e1d9..6878eceb2a5 100644 --- a/src/librustc_mir/transform/uniform_array_move_out.rs +++ b/src/librustc_mir/transform/uniform_array_move_out.rs @@ -97,7 +97,7 @@ fn uniform(&mut self, let temp = self.patch.new_temp(item_ty, self.body.source_info(location).span); self.patch.add_statement(location, StatementKind::StorageLive(temp)); self.patch.add_assign(location, - Place::Base(PlaceBase::Local(temp)), + Place::from(temp), Rvalue::Use( Operand::Move( Place::Projection(box Projection{ @@ -115,7 +115,7 @@ fn uniform(&mut self, Rvalue::Aggregate( box AggregateKind::Array(item_ty), temps.iter().map( - |x| Operand::Move(Place::Base(PlaceBase::Local(*x))) + |x| Operand::Move(Place::from(*x)) ).collect() ) ); diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index 91fc19b71d8..dac90d37275 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -486,7 +486,7 @@ fn adt_switch_block(&mut self, // discriminant after it is free-ed, because that // way lies only trouble. let discr_ty = adt.repr.discr_type().to_ty(self.tcx()); - let discr = Place::Base(PlaceBase::Local(self.new_temp(discr_ty))); + let discr = Place::from(self.new_temp(discr_ty)); let discr_rv = Rvalue::Discriminant(self.place.clone()); let switch_block = BasicBlockData { statements: vec![self.assign(&discr, discr_rv)], @@ -518,11 +518,11 @@ fn destructor_call_block(&mut self, (succ, unwind): (BasicBlock, Unwind)) -> Bas mutbl: hir::Mutability::MutMutable }); let ref_place = self.new_temp(ref_ty); - let unit_temp = Place::Base(PlaceBase::Local(self.new_temp(tcx.mk_unit()))); + let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); let result = BasicBlockData { statements: vec![self.assign( - &Place::Base(PlaceBase::Local(ref_place)), + &Place::from(ref_place), Rvalue::Ref(tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, self.place.clone()) @@ -531,7 +531,7 @@ fn destructor_call_block(&mut self, (succ, unwind): (BasicBlock, Unwind)) -> Bas kind: TerminatorKind::Call { func: Operand::function_handle(tcx, drop_fn.def_id, substs, self.source_info.span), - args: vec![Operand::Move(Place::Base(PlaceBase::Local(ref_place)))], + args: vec![Operand::Move(Place::from(ref_place))], destination: Some((unit_temp, succ)), cleanup: unwind.into_option(), from_hir_call: true, @@ -576,8 +576,8 @@ fn drop_loop( ty: ety, mutbl: hir::Mutability::MutMutable }); - let ptr = &Place::Base(PlaceBase::Local(self.new_temp(ref_ty))); - let can_go = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.bool))); + let ptr = &Place::from(self.new_temp(ref_ty)); + let can_go = &Place::from(self.new_temp(tcx.types.bool)); let one = self.constant_usize(1); let (ptr_next, cur_next) = if ptr_based { @@ -589,19 +589,19 @@ fn drop_loop( elem: ProjectionElem::Deref, })) ), - Rvalue::BinaryOp(BinOp::Offset, move_(&Place::Base(PlaceBase::Local(cur))), one)) + Rvalue::BinaryOp(BinOp::Offset, move_(&Place::from(cur)), one)) } else { (Rvalue::Ref( tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, self.place.clone().index(cur)), - Rvalue::BinaryOp(BinOp::Add, move_(&Place::Base(PlaceBase::Local(cur))), one)) + Rvalue::BinaryOp(BinOp::Add, move_(&Place::from(cur)), one)) }; let drop_block = BasicBlockData { statements: vec![ self.assign(ptr, ptr_next), - self.assign(&Place::Base(PlaceBase::Local(cur)), cur_next) + self.assign(&Place::from(cur), cur_next) ], is_cleanup: unwind.is_cleanup(), terminator: Some(Terminator { @@ -615,7 +615,7 @@ fn drop_loop( let loop_block = BasicBlockData { statements: vec![ self.assign(can_go, Rvalue::BinaryOp(BinOp::Eq, - copy(&Place::Base(PlaceBase::Local(cur))), + copy(&Place::from(cur)), copy(length_or_end))) ], is_cleanup: unwind.is_cleanup(), @@ -665,8 +665,8 @@ fn open_drop_for_array(&mut self, ety: Ty<'tcx>, opt_size: Option) -> Basic let move_ = |place: &Place<'tcx>| Operand::Move(place.clone()); let tcx = self.tcx(); - let elem_size = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.usize))); - let len = &Place::Base(PlaceBase::Local(self.new_temp(tcx.types.usize))); + let elem_size = &Place::from(self.new_temp(tcx.types.usize)); + let len = &Place::from(self.new_temp(tcx.types.usize)); static USIZE_SWITCH_ZERO: &[u128] = &[0]; @@ -713,8 +713,7 @@ fn drop_loop_pair( let length_or_end = if ptr_based { // FIXME check if we want to make it return a `Place` directly // if all use sites want a `Place::Base` anyway. - let temp = self.new_temp(iter_ty); - Place::Base(PlaceBase::Local(temp)) + Place::from(self.new_temp(iter_ty)) } else { length.clone() }; @@ -736,10 +735,10 @@ fn drop_loop_pair( unwind, ptr_based); - let cur = Place::Base(PlaceBase::Local(cur)); + let cur = Place::from(cur); let drop_block_stmts = if ptr_based { let tmp_ty = tcx.mk_mut_ptr(self.place_ty(self.place)); - let tmp = Place::Base(PlaceBase::Local(self.new_temp(tmp_ty))); + let tmp = Place::from(self.new_temp(tmp_ty)); // tmp = &mut P; // cur = tmp as *mut T; // end = Offset(cur, len); @@ -894,7 +893,7 @@ fn unelaborated_free_block( unwind: Unwind, ) -> BasicBlock { let tcx = self.tcx(); - let unit_temp = Place::Base(PlaceBase::Local(self.new_temp(tcx.mk_unit()))); + let unit_temp = Place::from(self.new_temp(tcx.mk_unit())); let free_func = tcx.require_lang_item(lang_items::BoxFreeFnLangItem); let args = adt.variants[VariantIdx::new(0)].fields.iter().enumerate().map(|(i, f)| { let field = Field::new(i); diff --git a/src/librustc_mir/util/graphviz.rs b/src/librustc_mir/util/graphviz.rs index 7b154a9d46f..1d876d7bddb 100644 --- a/src/librustc_mir/util/graphviz.rs +++ b/src/librustc_mir/util/graphviz.rs @@ -153,7 +153,7 @@ fn write_graph_label<'tcx, W: Write>( } write!(w, "{:?}: {}", - Place::Base(PlaceBase::Local(arg)), + Place::from(arg), escape(&body.local_decls[arg].ty) )?; } @@ -171,10 +171,10 @@ fn write_graph_label<'tcx, W: Write>( if let Some(name) = decl.name { write!(w, r#"{:?}: {}; // {}
"#, - Place::Base(PlaceBase::Local(local)), escape(&decl.ty), name)?; + Place::from(local), escape(&decl.ty), name)?; } else { write!(w, r#"{:?}: {};
"#, - Place::Base(PlaceBase::Local(local)), escape(&decl.ty))?; + Place::from(local), escape(&decl.ty))?; } } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index fc46adb702c..d66f35f82c6 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -601,7 +601,7 @@ fn write_mir_sig( if i != 0 { write!(w, ", ")?; } - write!(w, "{:?}: {}", Place::Base(PlaceBase::Local(arg)), body.local_decls[arg].ty)?; + write!(w, "{:?}: {}", Place::from(arg), body.local_decls[arg].ty)?; } write!(w, ") -> {}", body.return_ty())?;