diff --git a/src/librustc_codegen_ssa/mir/analyze.rs b/src/librustc_codegen_ssa/mir/analyze.rs index 221f36fed362d..ee87597e73594 100644 --- a/src/librustc_codegen_ssa/mir/analyze.rs +++ b/src/librustc_codegen_ssa/mir/analyze.rs @@ -215,7 +215,7 @@ impl<'mir, 'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> Visitor<'tcx> fn visit_assign( &mut self, place: &mir::Place<'tcx>, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, location: Location, ) { debug!("visit_assign(place={:?}, rvalue={:?})", place, rvalue); diff --git a/src/librustc_codegen_ssa/mir/rvalue.rs b/src/librustc_codegen_ssa/mir/rvalue.rs index 57fe7b0da6ff2..693290c3be283 100644 --- a/src/librustc_codegen_ssa/mir/rvalue.rs +++ b/src/librustc_codegen_ssa/mir/rvalue.rs @@ -22,12 +22,12 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, mut bx: Bx, dest: PlaceRef<'tcx, Bx::Value>, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, ) -> Bx { debug!("codegen_rvalue(dest.llval={:?}, rvalue={:?})", dest.llval, rvalue); match *rvalue { - mir::Rvalue::Use(ref operand) => { + mir::Op::Use(ref operand) => { let cg_operand = self.codegen_operand(&mut bx, operand); // FIXME: consider not copying constants through stack. (Fixable by codegen'ing // constants into `OperandValue::Ref`; why don’t we do that yet if we don’t?) @@ -35,7 +35,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx } - mir::Rvalue::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref source, _) => { + mir::Op::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref source, _) => { // The destination necessarily contains a fat pointer, so if // it's a scalar pair, it's a fat pointer or newtype thereof. if bx.cx().is_backend_scalar_pair(dest.layout) { @@ -77,7 +77,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx } - mir::Rvalue::Repeat(ref elem, count) => { + mir::Op::Repeat(ref elem, count) => { let cg_elem = self.codegen_operand(&mut bx, elem); // Do not generate the loop for zero-sized elements or empty arrays. @@ -111,7 +111,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { bx.write_operand_repeatedly(cg_elem, count, dest) } - mir::Rvalue::Aggregate(ref kind, ref operands) => { + mir::Op::Aggregate(ref kind, ref operands) => { let (dest, active_field_index) = match **kind { mir::AggregateKind::Adt(adt_def, variant_index, _, _, active_field_index) => { dest.codegen_set_discr(&mut bx, variant_index); @@ -148,7 +148,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { &mut self, mut bx: Bx, indirect_dest: PlaceRef<'tcx, Bx::Value>, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, ) -> Bx { debug!( "codegen_rvalue_unsized(indirect_dest.llval={:?}, rvalue={:?})", @@ -156,20 +156,20 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ); match *rvalue { - mir::Rvalue::Use(ref operand) => { + mir::Op::Use(ref operand) => { let cg_operand = self.codegen_operand(&mut bx, operand); cg_operand.val.store_unsized(&mut bx, indirect_dest); bx } - _ => bug!("unsized assignment other than `Rvalue::Use`"), + _ => bug!("unsized assignment other than `Op::Use`"), } } pub fn codegen_rvalue_operand( &mut self, mut bx: Bx, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, ) -> (Bx, OperandRef<'tcx, Bx::Value>) { assert!( self.rvalue_creates_operand(rvalue, DUMMY_SP), @@ -178,7 +178,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ); match *rvalue { - mir::Rvalue::Cast(ref kind, ref source, mir_cast_ty) => { + mir::Op::Cast(ref kind, ref source, mir_cast_ty) => { let operand = self.codegen_operand(&mut bx, source); debug!("cast operand is {:?}", operand); let cast = bx.cx().layout_of(self.monomorphize(&mir_cast_ty)); @@ -382,7 +382,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (bx, OperandRef { val, layout: cast }) } - mir::Rvalue::Ref(_, bk, place) => { + mir::Op::Ref(_, bk, place) => { let mk_ref = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { tcx.mk_ref( tcx.lifetimes.re_erased, @@ -392,14 +392,14 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { self.codegen_place_to_pointer(bx, place, mk_ref) } - mir::Rvalue::AddressOf(mutability, place) => { + mir::Op::AddressOf(mutability, place) => { let mk_ptr = move |tcx: TyCtxt<'tcx>, ty: Ty<'tcx>| { tcx.mk_ptr(ty::TypeAndMut { ty, mutbl: mutability }) }; self.codegen_place_to_pointer(bx, place, mk_ptr) } - mir::Rvalue::Len(place) => { + mir::Op::Len(place) => { let size = self.evaluate_array_len(&mut bx, place); let operand = OperandRef { val: OperandValue::Immediate(size), @@ -408,7 +408,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (bx, operand) } - mir::Rvalue::BinaryOp(op, ref lhs, ref rhs) => { + mir::Op::BinaryOp(op, ref lhs, ref rhs) => { let lhs = self.codegen_operand(&mut bx, lhs); let rhs = self.codegen_operand(&mut bx, rhs); let llresult = match (lhs.val, rhs.val) { @@ -437,7 +437,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { }; (bx, operand) } - mir::Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { + mir::Op::CheckedBinaryOp(op, ref lhs, ref rhs) => { let lhs = self.codegen_operand(&mut bx, lhs); let rhs = self.codegen_operand(&mut bx, rhs); let result = self.codegen_scalar_checked_binop( @@ -454,7 +454,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (bx, operand) } - mir::Rvalue::UnaryOp(op, ref operand) => { + mir::Op::UnaryOp(op, ref operand) => { let operand = self.codegen_operand(&mut bx, operand); let lloperand = operand.immediate(); let is_float = operand.layout.ty.is_floating_point(); @@ -471,7 +471,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { (bx, OperandRef { val: OperandValue::Immediate(llval), layout: operand.layout }) } - mir::Rvalue::Discriminant(ref place) => { + mir::Op::Discriminant(ref place) => { let discr_ty = rvalue.ty(*self.mir, bx.tcx()); let discr = self .codegen_place(&mut bx, place.as_ref()) @@ -485,7 +485,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) } - mir::Rvalue::NullaryOp(mir::NullOp::SizeOf, ty) => { + mir::Op::NullaryOp(mir::NullOp::SizeOf, ty) => { assert!(bx.cx().type_is_sized(ty)); let val = bx.cx().const_usize(bx.cx().layout_of(ty).size.bytes()); let tcx = self.cx.tcx(); @@ -498,7 +498,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { ) } - mir::Rvalue::NullaryOp(mir::NullOp::Box, content_ty) => { + mir::Op::NullaryOp(mir::NullOp::Box, content_ty) => { let content_ty = self.monomorphize(&content_ty); let content_layout = bx.cx().layout_of(content_ty); let llsize = bx.cx().const_usize(content_layout.size.bytes()); @@ -521,11 +521,11 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { let operand = OperandRef { val: OperandValue::Immediate(val), layout: box_layout }; (bx, operand) } - mir::Rvalue::Use(ref operand) => { + mir::Op::Use(ref operand) => { let operand = self.codegen_operand(&mut bx, operand); (bx, operand) } - mir::Rvalue::Repeat(..) | mir::Rvalue::Aggregate(..) => { + mir::Op::Repeat(..) | mir::Op::Aggregate(..) => { // According to `rvalue_creates_operand`, only ZST // aggregate rvalues are allowed to be operands. let ty = rvalue.ty(*self.mir, self.cx.tcx()); @@ -552,7 +552,7 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { cg_value.len(bx.cx()) } - /// Codegen an `Rvalue::AddressOf` or `Rvalue::Ref` + /// Codegen an `Op::AddressOf` or `Op::Ref` fn codegen_place_to_pointer( &mut self, mut bx: Bx, @@ -733,21 +733,21 @@ impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { } impl<'a, 'tcx, Bx: BuilderMethods<'a, 'tcx>> FunctionCx<'a, 'tcx, Bx> { - pub fn rvalue_creates_operand(&self, rvalue: &mir::Rvalue<'tcx>, span: Span) -> bool { + pub fn rvalue_creates_operand(&self, rvalue: &mir::Op<'tcx>, span: Span) -> bool { match *rvalue { - mir::Rvalue::Ref(..) | - mir::Rvalue::AddressOf(..) | - mir::Rvalue::Len(..) | - mir::Rvalue::Cast(..) | // (*) - mir::Rvalue::BinaryOp(..) | - mir::Rvalue::CheckedBinaryOp(..) | - mir::Rvalue::UnaryOp(..) | - mir::Rvalue::Discriminant(..) | - mir::Rvalue::NullaryOp(..) | - mir::Rvalue::Use(..) => // (*) + mir::Op::Ref(..) | + mir::Op::AddressOf(..) | + mir::Op::Len(..) | + mir::Op::Cast(..) | // (*) + mir::Op::BinaryOp(..) | + mir::Op::CheckedBinaryOp(..) | + mir::Op::UnaryOp(..) | + mir::Op::Discriminant(..) | + mir::Op::NullaryOp(..) | + mir::Op::Use(..) => // (*) true, - mir::Rvalue::Repeat(..) | - mir::Rvalue::Aggregate(..) => { + mir::Op::Repeat(..) | + mir::Op::Aggregate(..) => { let ty = rvalue.ty(*self.mir, self.cx.tcx()); let ty = self.monomorphize(&ty); self.cx.spanned_layout_of(ty, span).is_zst() diff --git a/src/librustc_codegen_ssa/traits/builder.rs b/src/librustc_codegen_ssa/traits/builder.rs index caba7ebef593b..5f111a95d5290 100644 --- a/src/librustc_codegen_ssa/traits/builder.rs +++ b/src/librustc_codegen_ssa/traits/builder.rs @@ -123,7 +123,7 @@ pub trait BuilderMethods<'a, 'tcx>: fn load_operand(&mut self, place: PlaceRef<'tcx, Self::Value>) -> OperandRef<'tcx, Self::Value>; - /// Called for Rvalue::Repeat when the elem is neither a ZST nor optimizable using memset. + /// Called for Op::Repeat when the elem is neither a ZST nor optimizable using memset. fn write_operand_repeatedly( self, elem: OperandRef<'tcx, Self::Value>, diff --git a/src/librustc_middle/mir/mod.rs b/src/librustc_middle/mir/mod.rs index b82008f429fa4..49122d6334467 100644 --- a/src/librustc_middle/mir/mod.rs +++ b/src/librustc_middle/mir/mod.rs @@ -1561,8 +1561,8 @@ impl Statement<'_> { #[derive(Clone, Debug, PartialEq, RustcEncodable, RustcDecodable, HashStable, TypeFoldable)] pub enum StatementKind<'tcx> { - /// Write the RHS Rvalue to the LHS Place. - Assign(Box<(Place<'tcx>, Rvalue<'tcx>)>), + /// Write the RHS Op to the LHS Place. + Assign(Box<(Place<'tcx>, Op<'tcx>)>), /// This represents all the reading that a pattern match may do /// (e.g., inspecting constants and discriminant values), and the @@ -2042,7 +2042,7 @@ impl<'tcx> Operand<'tcx> { /// Rvalues #[derive(Clone, RustcEncodable, RustcDecodable, HashStable, PartialEq)] -pub enum Rvalue<'tcx> { +pub enum Op<'tcx> { /// x (either a move or copy, depending on type of x) Use(Operand<'tcx>), @@ -2169,9 +2169,9 @@ pub enum UnOp { Neg, } -impl<'tcx> Debug for Rvalue<'tcx> { +impl<'tcx> Debug for Op<'tcx> { fn fmt(&self, fmt: &mut Formatter<'_>) -> fmt::Result { - use self::Rvalue::*; + use self::Op::*; match *self { Use(ref place) => write!(fmt, "{:?}", place), diff --git a/src/librustc_middle/mir/tcx.rs b/src/librustc_middle/mir/tcx.rs index 06b27c5e8b329..aac8d7f58add6 100644 --- a/src/librustc_middle/mir/tcx.rs +++ b/src/librustc_middle/mir/tcx.rs @@ -142,41 +142,41 @@ pub enum RvalueInitializationState { Deep, } -impl<'tcx> Rvalue<'tcx> { +impl<'tcx> Op<'tcx> { pub fn ty(&self, local_decls: &D, tcx: TyCtxt<'tcx>) -> Ty<'tcx> where D: HasLocalDecls<'tcx>, { match *self { - Rvalue::Use(ref operand) => operand.ty(local_decls, tcx), - Rvalue::Repeat(ref operand, count) => { + Op::Use(ref operand) => operand.ty(local_decls, tcx), + Op::Repeat(ref operand, count) => { tcx.mk_ty(ty::Array(operand.ty(local_decls, tcx), count)) } - Rvalue::Ref(reg, bk, ref place) => { + Op::Ref(reg, bk, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; tcx.mk_ref(reg, ty::TypeAndMut { ty: place_ty, mutbl: bk.to_mutbl_lossy() }) } - Rvalue::AddressOf(mutability, ref place) => { + Op::AddressOf(mutability, ref place) => { let place_ty = place.ty(local_decls, tcx).ty; tcx.mk_ptr(ty::TypeAndMut { ty: place_ty, mutbl: mutability }) } - Rvalue::Len(..) => tcx.types.usize, - Rvalue::Cast(.., ty) => ty, - Rvalue::BinaryOp(op, ref lhs, ref rhs) => { + Op::Len(..) => tcx.types.usize, + Op::Cast(.., ty) => ty, + Op::BinaryOp(op, ref lhs, ref rhs) => { let lhs_ty = lhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx); op.ty(tcx, lhs_ty, rhs_ty) } - Rvalue::CheckedBinaryOp(op, ref lhs, ref rhs) => { + Op::CheckedBinaryOp(op, ref lhs, ref rhs) => { let lhs_ty = lhs.ty(local_decls, tcx); let rhs_ty = rhs.ty(local_decls, tcx); let ty = op.ty(tcx, lhs_ty, rhs_ty); tcx.intern_tup(&[ty, tcx.types.bool]) } - Rvalue::UnaryOp(UnOp::Not, ref operand) | Rvalue::UnaryOp(UnOp::Neg, ref operand) => { + Op::UnaryOp(UnOp::Not, ref operand) | Op::UnaryOp(UnOp::Neg, ref operand) => { operand.ty(local_decls, tcx) } - Rvalue::Discriminant(ref place) => { + Op::Discriminant(ref place) => { let ty = place.ty(local_decls, tcx).ty; match ty.kind { ty::Adt(adt_def, _) => adt_def.repr.discr_type().to_ty(tcx), @@ -187,9 +187,9 @@ impl<'tcx> Rvalue<'tcx> { } } } - Rvalue::NullaryOp(NullOp::Box, t) => tcx.mk_box(t), - Rvalue::NullaryOp(NullOp::SizeOf, _) => tcx.types.usize, - Rvalue::Aggregate(ref ak, ref ops) => match **ak { + Op::NullaryOp(NullOp::Box, t) => tcx.mk_box(t), + Op::NullaryOp(NullOp::SizeOf, _) => tcx.types.usize, + Op::Aggregate(ref ak, ref ops) => match **ak { AggregateKind::Array(ty) => tcx.mk_array(ty, ops.len() as u64), AggregateKind::Tuple => tcx.mk_tup(ops.iter().map(|op| op.ty(local_decls, tcx))), AggregateKind::Adt(def, _, substs, _, _) => tcx.type_of(def.did).subst(tcx, substs), @@ -203,10 +203,10 @@ impl<'tcx> Rvalue<'tcx> { #[inline] /// Returns `true` if this rvalue is deeply initialized (most rvalues) or - /// whether its only shallowly initialized (`Rvalue::Box`). + /// whether its only shallowly initialized (`Op::Box`). pub fn initialization_state(&self) -> RvalueInitializationState { match *self { - Rvalue::NullaryOp(NullOp::Box, _) => RvalueInitializationState::Shallow, + Op::NullaryOp(NullOp::Box, _) => RvalueInitializationState::Shallow, _ => RvalueInitializationState::Deep, } } diff --git a/src/librustc_middle/mir/type_foldable.rs b/src/librustc_middle/mir/type_foldable.rs index 9520f081b6bfb..a8b4014e8b8bd 100644 --- a/src/librustc_middle/mir/type_foldable.rs +++ b/src/librustc_middle/mir/type_foldable.rs @@ -163,9 +163,9 @@ impl<'tcx> TypeFoldable<'tcx> for &'tcx ty::List> { } } -impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { +impl<'tcx> TypeFoldable<'tcx> for Op<'tcx> { fn super_fold_with>(&self, folder: &mut F) -> Self { - use crate::mir::Rvalue::*; + use crate::mir::Op::*; match *self { Use(ref op) => Use(op.fold_with(folder)), Repeat(ref op, len) => Repeat(op.fold_with(folder), len), @@ -208,7 +208,7 @@ impl<'tcx> TypeFoldable<'tcx> for Rvalue<'tcx> { } fn super_visit_with>(&self, visitor: &mut V) -> bool { - use crate::mir::Rvalue::*; + use crate::mir::Op::*; match *self { Use(ref op) => op.visit_with(visitor), Repeat(ref op, _) => op.visit_with(visitor), diff --git a/src/librustc_middle/mir/visit.rs b/src/librustc_middle/mir/visit.rs index 400d15cdc144b..e0adb784a9030 100644 --- a/src/librustc_middle/mir/visit.rs +++ b/src/librustc_middle/mir/visit.rs @@ -106,7 +106,7 @@ macro_rules! make_mir_visitor { fn visit_assign(&mut self, place: & $($mutability)? Place<'tcx>, - rvalue: & $($mutability)? Rvalue<'tcx>, + rvalue: & $($mutability)? Op<'tcx>, location: Location) { self.super_assign(place, rvalue, location); } @@ -130,7 +130,7 @@ macro_rules! make_mir_visitor { } fn visit_rvalue(&mut self, - rvalue: & $($mutability)? Rvalue<'tcx>, + rvalue: & $($mutability)? Op<'tcx>, location: Location) { self.super_rvalue(rvalue, location); } @@ -413,7 +413,7 @@ macro_rules! make_mir_visitor { fn super_assign(&mut self, place: &$($mutability)? Place<'tcx>, - rvalue: &$($mutability)? Rvalue<'tcx>, + rvalue: &$($mutability)? Op<'tcx>, location: Location) { self.visit_place( place, @@ -547,18 +547,18 @@ macro_rules! make_mir_visitor { } fn super_rvalue(&mut self, - rvalue: & $($mutability)? Rvalue<'tcx>, + rvalue: & $($mutability)? Op<'tcx>, location: Location) { match rvalue { - Rvalue::Use(operand) => { + Op::Use(operand) => { self.visit_operand(operand, location); } - Rvalue::Repeat(value, _) => { + Op::Repeat(value, _) => { self.visit_operand(value, location); } - Rvalue::Ref(r, bk, path) => { + Op::Ref(r, bk, path) => { self.visit_region(r, location); let ctx = match bk { BorrowKind::Shared => PlaceContext::NonMutatingUse( @@ -576,7 +576,7 @@ macro_rules! make_mir_visitor { self.visit_place(path, ctx, location); } - Rvalue::AddressOf(m, path) => { + Op::AddressOf(m, path) => { let ctx = match m { Mutability::Mut => PlaceContext::MutatingUse( MutatingUseContext::AddressOf @@ -588,7 +588,7 @@ macro_rules! make_mir_visitor { self.visit_place(path, ctx, location); } - Rvalue::Len(path) => { + Op::Len(path) => { self.visit_place( path, PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect), @@ -596,22 +596,22 @@ macro_rules! make_mir_visitor { ); } - Rvalue::Cast(_cast_kind, operand, ty) => { + Op::Cast(_cast_kind, operand, ty) => { self.visit_operand(operand, location); self.visit_ty(ty, TyContext::Location(location)); } - Rvalue::BinaryOp(_bin_op, lhs, rhs) - | Rvalue::CheckedBinaryOp(_bin_op, lhs, rhs) => { + Op::BinaryOp(_bin_op, lhs, rhs) + | Op::CheckedBinaryOp(_bin_op, lhs, rhs) => { self.visit_operand(lhs, location); self.visit_operand(rhs, location); } - Rvalue::UnaryOp(_un_op, op) => { + Op::UnaryOp(_un_op, op) => { self.visit_operand(op, location); } - Rvalue::Discriminant(place) => { + Op::Discriminant(place) => { self.visit_place( place, PlaceContext::NonMutatingUse(NonMutatingUseContext::Inspect), @@ -619,11 +619,11 @@ macro_rules! make_mir_visitor { ); } - Rvalue::NullaryOp(_op, ty) => { + Op::NullaryOp(_op, ty) => { self.visit_ty(ty, TyContext::Location(location)); } - Rvalue::Aggregate(kind, operands) => { + Op::Aggregate(kind, operands) => { let kind = &$($mutability)? **kind; match kind { AggregateKind::Array(ty) => { @@ -838,7 +838,7 @@ macro_rules! make_mir_visitor { } macro_rules! visit_place_fns { - (mut) => ( + (mut) => { fn tcx<'a>(&'a self) -> TyCtxt<'tcx>; fn super_place( @@ -877,15 +877,12 @@ macro_rules! visit_place_fns { } } - fn process_projection_elem( - &mut self, - _elem: &PlaceElem<'tcx>, - ) -> Option> { + fn process_projection_elem(&mut self, _elem: &PlaceElem<'tcx>) -> Option> { None } - ); + }; - () => ( + () => { fn visit_projection( &mut self, local: Local, @@ -907,12 +904,7 @@ macro_rules! visit_place_fns { self.super_projection_elem(local, proj_base, elem, context, location); } - fn super_place( - &mut self, - place: &Place<'tcx>, - context: PlaceContext, - location: Location, - ) { + fn super_place(&mut self, place: &Place<'tcx>, context: PlaceContext, location: Location) { let mut context = context; if !place.projection.is_empty() { @@ -925,10 +917,7 @@ macro_rules! visit_place_fns { self.visit_place_base(&place.local, context, location); - self.visit_projection(place.local, - &place.projection, - context, - location); + self.visit_projection(place.local, &place.projection, context, location); } fn super_projection( @@ -961,19 +950,16 @@ macro_rules! visit_place_fns { self.visit_local( local, PlaceContext::NonMutatingUse(NonMutatingUseContext::Copy), - location + location, ); } - ProjectionElem::Deref | - ProjectionElem::Subslice { from: _, to: _, from_end: _ } | - ProjectionElem::ConstantIndex { offset: _, - min_length: _, - from_end: _ } | - ProjectionElem::Downcast(_, _) => { - } + ProjectionElem::Deref + | ProjectionElem::Subslice { from: _, to: _, from_end: _ } + | ProjectionElem::ConstantIndex { offset: _, min_length: _, from_end: _ } + | ProjectionElem::Downcast(_, _) => {} } } - ); + }; } make_mir_visitor!(Visitor,); diff --git a/src/librustc_mir/borrow_check/borrow_set.rs b/src/librustc_mir/borrow_check/borrow_set.rs index 7242bbcd2eb8f..e45593780833f 100644 --- a/src/librustc_mir/borrow_check/borrow_set.rs +++ b/src/librustc_mir/borrow_check/borrow_set.rs @@ -184,10 +184,10 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> { fn visit_assign( &mut self, assigned_place: &mir::Place<'tcx>, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, location: mir::Location, ) { - if let mir::Rvalue::Ref(region, kind, ref borrowed_place) = *rvalue { + if let mir::Op::Ref(region, kind, ref borrowed_place) = *rvalue { if borrowed_place.ignore_borrow(self.tcx, self.body, &self.locals_state_at_exit) { debug!("ignoring_borrow of {:?}", borrowed_place); return; @@ -261,8 +261,8 @@ impl<'a, 'tcx> Visitor<'tcx> for GatherBorrows<'a, 'tcx> { } } - fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: mir::Location) { - if let mir::Rvalue::Ref(region, kind, ref place) = *rvalue { + fn visit_rvalue(&mut self, rvalue: &mir::Op<'tcx>, location: mir::Location) { + if let mir::Op::Ref(region, kind, ref place) = *rvalue { // double-check that we already registered a BorrowData for this let borrow_index = self.location_map[&location]; diff --git a/src/librustc_mir/borrow_check/constraint_generation.rs b/src/librustc_mir/borrow_check/constraint_generation.rs index e0420d974fbdf..35dc0c0da78c9 100644 --- a/src/librustc_mir/borrow_check/constraint_generation.rs +++ b/src/librustc_mir/borrow_check/constraint_generation.rs @@ -2,7 +2,7 @@ use rustc_infer::infer::InferCtxt; use rustc_middle::mir::visit::TyContext; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::{ - BasicBlock, BasicBlockData, Body, Local, Location, Place, PlaceRef, ProjectionElem, Rvalue, + BasicBlock, BasicBlockData, Body, Local, Location, Op, Place, PlaceRef, ProjectionElem, SourceInfo, Statement, StatementKind, Terminator, TerminatorKind, UserTypeProjection, }; use rustc_middle::ty::fold::TypeFoldable; @@ -111,7 +111,7 @@ impl<'cg, 'cx, 'tcx> Visitor<'tcx> for ConstraintGeneration<'cg, 'cx, 'tcx> { self.super_statement(statement, location); } - fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_assign(&mut self, place: &Place<'tcx>, rvalue: &Op<'tcx>, location: Location) { // When we see `X = ...`, then kill borrows of // `(*X).foo` and so forth. self.record_killed_borrows_for_place(*place, location); diff --git a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs index 9df5760563129..a5f8ce6105ced 100644 --- a/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/conflict_errors.rs @@ -6,8 +6,8 @@ use rustc_hir::{AsyncGeneratorKind, GeneratorKind}; use rustc_index::vec::Idx; use rustc_middle::mir::{ self, AggregateKind, BindingForm, BorrowKind, ClearCrossCrate, ConstraintCategory, - FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Operand, Place, PlaceRef, - ProjectionElem, Rvalue, Statement, StatementKind, TerminatorKind, VarBindingForm, + FakeReadCause, Local, LocalDecl, LocalInfo, LocalKind, Location, Op, Operand, Place, PlaceRef, + ProjectionElem, Statement, StatementKind, TerminatorKind, VarBindingForm, }; use rustc_middle::ty::{self, Ty}; use rustc_span::source_map::DesugaringKind; @@ -1616,10 +1616,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { assigned_to, rvalue ); // Check if our `target` was captured by a closure. - if let Rvalue::Aggregate( - box AggregateKind::Closure(def_id, substs), - operands, - ) = rvalue + if let Op::Aggregate(box AggregateKind::Closure(def_id, substs), operands) = + rvalue { for operand in operands { let assigned_from = match operand { @@ -1673,8 +1671,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // Otherwise, look at other types of assignment. let assigned_from = match rvalue { - Rvalue::Ref(_, _, assigned_from) => assigned_from, - Rvalue::Use(operand) => match operand { + Op::Ref(_, _, assigned_from) => assigned_from, + Op::Use(operand) => match operand { Operand::Copy(assigned_from) | Operand::Move(assigned_from) => { assigned_from } diff --git a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs index 7645182ad1fb3..dd449b2511195 100644 --- a/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs +++ b/src/librustc_mir/borrow_check/diagnostics/explain_borrow.rs @@ -7,7 +7,7 @@ use rustc_errors::{Applicability, DiagnosticBuilder}; use rustc_index::vec::IndexVec; use rustc_infer::infer::NLLRegionVariableOrigin; use rustc_middle::mir::{ - Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Rvalue, + Body, CastKind, ConstraintCategory, FakeReadCause, Local, Location, Operand, Place, Op, Statement, StatementKind, TerminatorKind, }; use rustc_middle::ty::adjustment::PointerCast; @@ -596,7 +596,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { match rvalue { // If we see a use, we should check whether it is our data, and if so // update the place that we're looking for to that new place. - Rvalue::Use(operand) => match operand { + Op::Use(operand) => match operand { Operand::Copy(place) | Operand::Move(place) => { if let Some(from) = place.as_local() { if from == target { @@ -608,7 +608,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }, // If we see a unsized cast, then if it is our data we should check // whether it is being cast to a trait object. - Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), operand, ty) => { + Op::Cast(CastKind::Pointer(PointerCast::Unsize), operand, ty) => { match operand { Operand::Copy(place) | Operand::Move(place) => { if let Some(from) = place.as_local() { diff --git a/src/librustc_mir/borrow_check/diagnostics/mod.rs b/src/librustc_mir/borrow_check/diagnostics/mod.rs index 619ae0ff8faa1..45911bd0d7bb6 100644 --- a/src/librustc_mir/borrow_check/diagnostics/mod.rs +++ b/src/librustc_mir/borrow_check/diagnostics/mod.rs @@ -7,7 +7,7 @@ use rustc_hir::def_id::DefId; use rustc_hir::GeneratorKind; use rustc_middle::mir::{ AggregateKind, Constant, Field, Local, LocalInfo, LocalKind, Location, Operand, Place, - PlaceRef, ProjectionElem, Rvalue, Statement, StatementKind, Terminator, TerminatorKind, + PlaceRef, ProjectionElem, Op, Statement, StatementKind, Terminator, TerminatorKind, }; use rustc_middle::ty::print::Print; use rustc_middle::ty::{self, DefIdTree, Ty, TyCtxt}; @@ -58,7 +58,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let mut target = place.local_or_deref_local(); for stmt in &self.body[location.block].statements[location.statement_index..] { debug!("add_moved_or_invoked_closure_note: stmt={:?} target={:?}", stmt, target); - if let StatementKind::Assign(box (into, Rvalue::Use(from))) = &stmt.kind { + if let StatementKind::Assign(box (into, Op::Use(from))) = &stmt.kind { debug!("add_fnonce_closure_note: into={:?} from={:?}", into, from); match from { Operand::Copy(ref place) | Operand::Move(ref place) @@ -720,7 +720,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { }; debug!("move_spans: moved_place={:?} location={:?} stmt={:?}", moved_place, location, stmt); - if let StatementKind::Assign(box (_, Rvalue::Aggregate(ref kind, ref places))) = stmt.kind { + if let StatementKind::Assign(box (_, Op::Aggregate(ref kind, ref places))) = stmt.kind { let def_id = match kind { box AggregateKind::Closure(def_id, _) | box AggregateKind::Generator(def_id, _, _) => def_id, @@ -763,7 +763,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { } for stmt in &self.body[location.block].statements[location.statement_index + 1..] { - if let StatementKind::Assign(box (_, Rvalue::Aggregate(ref kind, ref places))) = + if let StatementKind::Assign(box (_, Op::Aggregate(ref kind, ref places))) = stmt.kind { let (def_id, is_generator) = match kind { diff --git a/src/librustc_mir/borrow_check/diagnostics/move_errors.rs b/src/librustc_mir/borrow_check/diagnostics/move_errors.rs index d32533b6ce9a1..1e1470b53cda6 100644 --- a/src/librustc_mir/borrow_check/diagnostics/move_errors.rs +++ b/src/librustc_mir/borrow_check/diagnostics/move_errors.rs @@ -86,13 +86,11 @@ impl<'a, 'tcx> MirBorrowckCtxt<'a, 'tcx> { // to a user variable is when initializing it. // If that ever stops being the case, then the ever initialized // flow could be used. - if let Some(StatementKind::Assign(box ( - place, - Rvalue::Use(Operand::Move(move_from)), - ))) = self.body.basic_blocks()[location.block] - .statements - .get(location.statement_index) - .map(|stmt| &stmt.kind) + if let Some(StatementKind::Assign(box (place, Op::Use(Operand::Move(move_from))))) = + self.body.basic_blocks()[location.block] + .statements + .get(location.statement_index) + .map(|stmt| &stmt.kind) { if let Some(local) = place.as_local() { let local_decl = &self.body.local_decls[local]; diff --git a/src/librustc_mir/borrow_check/invalidation.rs b/src/librustc_mir/borrow_check/invalidation.rs index 318751113b283..dc57135dda70e 100644 --- a/src/librustc_mir/borrow_check/invalidation.rs +++ b/src/librustc_mir/borrow_check/invalidation.rs @@ -1,7 +1,7 @@ use rustc_data_structures::graph::dominators::Dominators; use rustc_middle::mir::visit::Visitor; use rustc_middle::mir::TerminatorKind; -use rustc_middle::mir::{BasicBlock, Body, Location, Place, ReadOnlyBodyAndCache, Rvalue}; +use rustc_middle::mir::{BasicBlock, Body, Location, Op, Place, ReadOnlyBodyAndCache}; use rustc_middle::mir::{BorrowKind, Mutability, Operand}; use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; @@ -237,9 +237,9 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> { } // Simulates consumption of an rvalue - fn consume_rvalue(&mut self, location: Location, rvalue: &Rvalue<'tcx>) { + fn consume_rvalue(&mut self, location: Location, rvalue: &Op<'tcx>) { match *rvalue { - Rvalue::Ref(_ /*rgn*/, bk, place) => { + Op::Ref(_ /*rgn*/, bk, place) => { let access_kind = match bk { BorrowKind::Shallow => { (Shallow(Some(ArtificialField::ShallowBorrow)), Read(ReadKind::Borrow(bk))) @@ -258,7 +258,7 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> { self.access_place(location, place, access_kind, LocalMutationIsAllowed::No); } - Rvalue::AddressOf(mutability, place) => { + Op::AddressOf(mutability, place) => { let access_kind = match mutability { Mutability::Mut => ( Deep, @@ -272,17 +272,17 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> { self.access_place(location, place, access_kind, LocalMutationIsAllowed::No); } - Rvalue::Use(ref operand) - | Rvalue::Repeat(ref operand, _) - | Rvalue::UnaryOp(_ /*un_op*/, ref operand) - | Rvalue::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => { + Op::Use(ref operand) + | Op::Repeat(ref operand, _) + | Op::UnaryOp(_ /*un_op*/, ref operand) + | Op::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => { self.consume_operand(location, operand) } - Rvalue::Len(place) | Rvalue::Discriminant(place) => { + Op::Len(place) | Op::Discriminant(place) => { let af = match *rvalue { - Rvalue::Len(..) => Some(ArtificialField::ArrayLength), - Rvalue::Discriminant(..) => None, + Op::Len(..) => Some(ArtificialField::ArrayLength), + Op::Discriminant(..) => None, _ => unreachable!(), }; self.access_place( @@ -293,15 +293,15 @@ impl<'cx, 'tcx> InvalidationGenerator<'cx, 'tcx> { ); } - Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) - | Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { + Op::BinaryOp(_bin_op, ref operand1, ref operand2) + | Op::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { self.consume_operand(location, operand1); self.consume_operand(location, operand2); } - Rvalue::NullaryOp(_op, _ty) => {} + Op::NullaryOp(_op, _ty) => {} - Rvalue::Aggregate(_, ref operands) => { + Op::Aggregate(_, ref operands) => { for operand in operands { self.consume_operand(location, operand); } diff --git a/src/librustc_mir/borrow_check/mod.rs b/src/librustc_mir/borrow_check/mod.rs index 52847af214f6c..bde3650c3897d 100644 --- a/src/librustc_mir/borrow_check/mod.rs +++ b/src/librustc_mir/borrow_check/mod.rs @@ -14,7 +14,7 @@ use rustc_middle::mir::{ Operand, Place, PlaceElem, PlaceRef, ReadOnlyBodyAndCache, }; use rustc_middle::mir::{AggregateKind, BasicBlock, BorrowCheckResult, BorrowKind}; -use rustc_middle::mir::{Field, ProjectionElem, Promoted, Rvalue, Statement, StatementKind}; +use rustc_middle::mir::{Field, ProjectionElem, Promoted, Op, Statement, StatementKind}; use rustc_middle::mir::{Terminator, TerminatorKind}; use rustc_middle::ty::query::Providers; use rustc_middle::ty::{self, RegionVid, TyCtxt}; @@ -1145,11 +1145,11 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { fn consume_rvalue( &mut self, location: Location, - (rvalue, span): (&'cx Rvalue<'tcx>, Span), + (rvalue, span): (&'cx Op<'tcx>, Span), flow_state: &Flows<'cx, 'tcx>, ) { match *rvalue { - Rvalue::Ref(_ /*rgn*/, bk, place) => { + Op::Ref(_ /*rgn*/, bk, place) => { let access_kind = match bk { BorrowKind::Shallow => { (Shallow(Some(ArtificialField::ShallowBorrow)), Read(ReadKind::Borrow(bk))) @@ -1187,7 +1187,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } - Rvalue::AddressOf(mutability, place) => { + Op::AddressOf(mutability, place) => { let access_kind = match mutability { Mutability::Mut => ( Deep, @@ -1214,17 +1214,17 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } - Rvalue::Use(ref operand) - | Rvalue::Repeat(ref operand, _) - | Rvalue::UnaryOp(_ /*un_op*/, ref operand) - | Rvalue::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => { + Op::Use(ref operand) + | Op::Repeat(ref operand, _) + | Op::UnaryOp(_ /*un_op*/, ref operand) + | Op::Cast(_ /*cast_kind*/, ref operand, _ /*ty*/) => { self.consume_operand(location, (operand, span), flow_state) } - Rvalue::Len(place) | Rvalue::Discriminant(place) => { + Op::Len(place) | Op::Discriminant(place) => { let af = match *rvalue { - Rvalue::Len(..) => Some(ArtificialField::ArrayLength), - Rvalue::Discriminant(..) => None, + Op::Len(..) => Some(ArtificialField::ArrayLength), + Op::Discriminant(..) => None, _ => unreachable!(), }; self.access_place( @@ -1242,13 +1242,13 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { ); } - Rvalue::BinaryOp(_bin_op, ref operand1, ref operand2) - | Rvalue::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { + Op::BinaryOp(_bin_op, ref operand1, ref operand2) + | Op::CheckedBinaryOp(_bin_op, ref operand1, ref operand2) => { self.consume_operand(location, (operand1, span), flow_state); self.consume_operand(location, (operand2, span), flow_state); } - Rvalue::NullaryOp(_op, _ty) => { + Op::NullaryOp(_op, _ty) => { // nullary ops take no dynamic input; no borrowck effect. // // FIXME: is above actually true? Do we want to track @@ -1256,7 +1256,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { // `NullOp::Box`? } - Rvalue::Aggregate(ref aggregate_kind, ref operands) => { + Op::Aggregate(ref aggregate_kind, ref operands) => { // We need to report back the list of mutable upvars that were // moved into the closure and subsequently used by the closure, // in order to populate our used_mut set. @@ -1335,7 +1335,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> { let stmt = &bbd.statements[loc.statement_index]; debug!("temporary assigned in: stmt={:?}", stmt); - if let StatementKind::Assign(box (_, Rvalue::Ref(_, _, source))) = stmt.kind + if let StatementKind::Assign(box (_, Op::Ref(_, _, source))) = stmt.kind { propagate_closure_used_mut_place(self, source); } else { diff --git a/src/librustc_mir/borrow_check/type_check/mod.rs b/src/librustc_mir/borrow_check/type_check/mod.rs index a118fe2db7124..90875cd659969 100644 --- a/src/librustc_mir/borrow_check/type_check/mod.rs +++ b/src/librustc_mir/borrow_check/type_check/mod.rs @@ -392,7 +392,7 @@ impl<'a, 'b, 'tcx> Visitor<'tcx> for TypeVerifier<'a, 'b, 'tcx> { } } - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { self.super_rvalue(rvalue, location); let rval_ty = rvalue.ty(self.body, self.tcx()); self.sanitize_type(rvalue, rval_ty); @@ -1975,17 +1975,15 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn check_rvalue( &mut self, body: ReadOnlyBodyAndCache<'_, 'tcx>, - rvalue: &Rvalue<'tcx>, + rvalue: &Op<'tcx>, location: Location, ) { let tcx = self.tcx(); match rvalue { - Rvalue::Aggregate(ak, ops) => { - self.check_aggregate_rvalue(&body, rvalue, ak, ops, location) - } + Op::Aggregate(ak, ops) => self.check_aggregate_rvalue(&body, rvalue, ak, ops, location), - Rvalue::Repeat(operand, len) => { + Op::Repeat(operand, len) => { // If the length cannot be evaluated we must assume that the length can be larger // than 1. // If the length is larger than 1, the repeat expression will need to copy the @@ -2037,7 +2035,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } - Rvalue::NullaryOp(_, ty) => { + Op::NullaryOp(_, ty) => { // Even with unsized locals cannot box an unsized value. if self.tcx().features().unsized_locals { let span = body.source_info(location).span; @@ -2056,7 +2054,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { ); } - Rvalue::Cast(cast_kind, op, ty) => { + Op::Cast(cast_kind, op, ty) => { match cast_kind { CastKind::Pointer(PointerCast::ReifyFnPointer) => { let fn_sig = op.ty(*body, tcx).fn_sig(tcx); @@ -2289,16 +2287,16 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } - Rvalue::Ref(region, _borrow_kind, borrowed_place) => { + Op::Ref(region, _borrow_kind, borrowed_place) => { self.add_reborrow_constraint(&body, location, region, borrowed_place); } - Rvalue::BinaryOp(BinOp::Eq, left, right) - | Rvalue::BinaryOp(BinOp::Ne, left, right) - | Rvalue::BinaryOp(BinOp::Lt, left, right) - | Rvalue::BinaryOp(BinOp::Le, left, right) - | Rvalue::BinaryOp(BinOp::Gt, left, right) - | Rvalue::BinaryOp(BinOp::Ge, left, right) => { + Op::BinaryOp(BinOp::Eq, left, right) + | Op::BinaryOp(BinOp::Ne, left, right) + | Op::BinaryOp(BinOp::Lt, left, right) + | Op::BinaryOp(BinOp::Le, left, right) + | Op::BinaryOp(BinOp::Gt, left, right) + | Op::BinaryOp(BinOp::Ge, left, right) => { let ty_left = left.ty(*body, tcx); if let ty::RawPtr(_) | ty::FnPtr(_) = ty_left.kind { let ty_right = right.ty(*body, tcx); @@ -2333,34 +2331,34 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { } } - Rvalue::AddressOf(..) - | Rvalue::Use(..) - | Rvalue::Len(..) - | Rvalue::BinaryOp(..) - | Rvalue::CheckedBinaryOp(..) - | Rvalue::UnaryOp(..) - | Rvalue::Discriminant(..) => {} + Op::AddressOf(..) + | Op::Use(..) + | Op::Len(..) + | Op::BinaryOp(..) + | Op::CheckedBinaryOp(..) + | Op::UnaryOp(..) + | Op::Discriminant(..) => {} } } /// If this rvalue supports a user-given type annotation, then /// extract and return it. This represents the final type of the /// rvalue and will be unified with the inferred type. - fn rvalue_user_ty(&self, rvalue: &Rvalue<'tcx>) -> Option { + fn rvalue_user_ty(&self, rvalue: &Op<'tcx>) -> Option { match rvalue { - Rvalue::Use(_) - | Rvalue::Repeat(..) - | Rvalue::Ref(..) - | Rvalue::AddressOf(..) - | Rvalue::Len(..) - | Rvalue::Cast(..) - | Rvalue::BinaryOp(..) - | Rvalue::CheckedBinaryOp(..) - | Rvalue::NullaryOp(..) - | Rvalue::UnaryOp(..) - | Rvalue::Discriminant(..) => None, - - Rvalue::Aggregate(aggregate, _) => match **aggregate { + Op::Use(_) + | Op::Repeat(..) + | Op::Ref(..) + | Op::AddressOf(..) + | Op::Len(..) + | Op::Cast(..) + | Op::BinaryOp(..) + | Op::CheckedBinaryOp(..) + | Op::NullaryOp(..) + | Op::UnaryOp(..) + | Op::Discriminant(..) => None, + + Op::Aggregate(aggregate, _) => match **aggregate { AggregateKind::Adt(_, _, _, user_ty, _) => user_ty, AggregateKind::Array(_) => None, AggregateKind::Tuple => None, @@ -2373,7 +2371,7 @@ impl<'a, 'tcx> TypeChecker<'a, 'tcx> { fn check_aggregate_rvalue( &mut self, body: &Body<'tcx>, - rvalue: &Rvalue<'tcx>, + rvalue: &Op<'tcx>, aggregate_kind: &AggregateKind<'tcx>, operands: &[Operand<'tcx>], location: Location, diff --git a/src/librustc_mir/dataflow/framework/engine.rs b/src/librustc_mir/dataflow/framework/engine.rs index 2a9d2d99c8a72..ee137742df340 100644 --- a/src/librustc_mir/dataflow/framework/engine.rs +++ b/src/librustc_mir/dataflow/framework/engine.rs @@ -365,13 +365,13 @@ fn switch_on_enum_discriminant( switch_on: mir::Place<'tcx>, ) -> Option<(mir::Place<'tcx>, &'tcx ty::AdtDef)> { match block.statements.last().map(|stmt| &stmt.kind) { - Some(mir::StatementKind::Assign(box (lhs, mir::Rvalue::Discriminant(discriminated)))) + Some(mir::StatementKind::Assign(box (lhs, mir::Op::Discriminant(discriminated)))) if *lhs == switch_on => { match &discriminated.ty(body, tcx).ty.kind { ty::Adt(def, _) => Some((*discriminated, def)), - // `Rvalue::Discriminant` is also used to get the active yield point for a + // `Op::Discriminant` is also used to get the active yield point for a // generator, but we do not need edge-specific effects in that case. This may // change in the future. ty::Generator(..) => None, diff --git a/src/librustc_mir/dataflow/impls/borrowed_locals.rs b/src/librustc_mir/dataflow/impls/borrowed_locals.rs index 6972a81cf1b0e..00273e648e157 100644 --- a/src/librustc_mir/dataflow/impls/borrowed_locals.rs +++ b/src/librustc_mir/dataflow/impls/borrowed_locals.rs @@ -155,32 +155,32 @@ where } } - fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &mir::Op<'tcx>, location: Location) { self.super_rvalue(rvalue, location); match rvalue { - mir::Rvalue::AddressOf(mt, borrowed_place) => { + mir::Op::AddressOf(mt, borrowed_place) => { if !borrowed_place.is_indirect() && self.kind.in_address_of(*mt, *borrowed_place) { self.trans.gen(borrowed_place.local); } } - mir::Rvalue::Ref(_, kind, borrowed_place) => { + mir::Op::Ref(_, kind, borrowed_place) => { if !borrowed_place.is_indirect() && self.kind.in_ref(*kind, *borrowed_place) { self.trans.gen(borrowed_place.local); } } - mir::Rvalue::Cast(..) - | mir::Rvalue::Use(..) - | mir::Rvalue::Repeat(..) - | mir::Rvalue::Len(..) - | mir::Rvalue::BinaryOp(..) - | mir::Rvalue::CheckedBinaryOp(..) - | mir::Rvalue::NullaryOp(..) - | mir::Rvalue::UnaryOp(..) - | mir::Rvalue::Discriminant(..) - | mir::Rvalue::Aggregate(..) => {} + mir::Op::Cast(..) + | mir::Op::Use(..) + | mir::Op::Repeat(..) + | mir::Op::Len(..) + | mir::Op::BinaryOp(..) + | mir::Op::CheckedBinaryOp(..) + | mir::Op::NullaryOp(..) + | mir::Op::UnaryOp(..) + | mir::Op::Discriminant(..) + | mir::Op::Aggregate(..) => {} } } diff --git a/src/librustc_mir/dataflow/impls/borrows.rs b/src/librustc_mir/dataflow/impls/borrows.rs index 0de8f45720e6f..be7db6bf3cbd3 100644 --- a/src/librustc_mir/dataflow/impls/borrows.rs +++ b/src/librustc_mir/dataflow/impls/borrows.rs @@ -22,7 +22,7 @@ rustc_index::newtype_index! { /// `Borrows` stores the data used in the analyses that track the flow /// of borrows. /// -/// It uniquely identifies every borrow (`Rvalue::Ref`) by a +/// It uniquely identifies every borrow (`Op::Ref`) by a /// `BorrowIndex`, and maps each such index to a `BorrowData` /// describing the borrow. These indexes are used for representing the /// borrows in compact bitvectors. @@ -263,7 +263,7 @@ impl<'tcx> dataflow::GenKillAnalysis<'tcx> for Borrows<'_, 'tcx> { ) { match stmt.kind { mir::StatementKind::Assign(box (lhs, ref rhs)) => { - if let mir::Rvalue::Ref(_, _, place) = *rhs { + if let mir::Op::Ref(_, _, place) = *rhs { if place.ignore_borrow( self.tcx, self.body, diff --git a/src/librustc_mir/dataflow/move_paths/builder.rs b/src/librustc_mir/dataflow/move_paths/builder.rs index fabe575c28904..befc8c17a307c 100644 --- a/src/librustc_mir/dataflow/move_paths/builder.rs +++ b/src/librustc_mir/dataflow/move_paths/builder.rs @@ -322,28 +322,28 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> { } } - fn gather_rvalue(&mut self, rvalue: &Rvalue<'tcx>) { + fn gather_rvalue(&mut self, rvalue: &Op<'tcx>) { match *rvalue { - Rvalue::Use(ref operand) - | Rvalue::Repeat(ref operand, _) - | Rvalue::Cast(_, ref operand, _) - | Rvalue::UnaryOp(_, ref operand) => self.gather_operand(operand), - Rvalue::BinaryOp(ref _binop, ref lhs, ref rhs) - | Rvalue::CheckedBinaryOp(ref _binop, ref lhs, ref rhs) => { + Op::Use(ref operand) + | Op::Repeat(ref operand, _) + | Op::Cast(_, ref operand, _) + | Op::UnaryOp(_, ref operand) => self.gather_operand(operand), + Op::BinaryOp(ref _binop, ref lhs, ref rhs) + | Op::CheckedBinaryOp(ref _binop, ref lhs, ref rhs) => { self.gather_operand(lhs); self.gather_operand(rhs); } - Rvalue::Aggregate(ref _kind, ref operands) => { + Op::Aggregate(ref _kind, ref operands) => { for operand in operands { self.gather_operand(operand); } } - Rvalue::Ref(..) - | Rvalue::AddressOf(..) - | Rvalue::Discriminant(..) - | Rvalue::Len(..) - | Rvalue::NullaryOp(NullOp::SizeOf, _) - | Rvalue::NullaryOp(NullOp::Box, _) => { + Op::Ref(..) + | Op::AddressOf(..) + | Op::Discriminant(..) + | Op::Len(..) + | Op::NullaryOp(NullOp::SizeOf, _) + | Op::NullaryOp(NullOp::Box, _) => { // This returns an rvalue with uninitialized contents. We can't // move out of it here because it is an rvalue - assignments always // completely initialize their place. diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index 37740878f7043..31e69209ac8ab 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -136,12 +136,12 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> { /// type writes its results directly into the memory specified by the place. pub fn eval_rvalue_into_place( &mut self, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, place: mir::Place<'tcx>, ) -> InterpResult<'tcx> { let dest = self.eval_place(place)?; - use rustc_middle::mir::Rvalue::*; + use rustc_middle::mir::Op::*; match *rvalue { Use(ref operand) => { // Avoid recomputing the layout diff --git a/src/librustc_mir/monomorphize/collector.rs b/src/librustc_mir/monomorphize/collector.rs index d8ceda96a25e1..5310426608f42 100644 --- a/src/librustc_mir/monomorphize/collector.rs +++ b/src/librustc_mir/monomorphize/collector.rs @@ -130,7 +130,7 @@ //! #### Boxes //! Since `Box` expression have special compiler support, no explicit calls to //! `exchange_malloc()` and `box_free()` may show up in MIR, even if the -//! compiler will generate them. We have to observe `Rvalue::Box` expressions +//! compiler will generate them. We have to observe `Op::Box` expressions //! and Box-typed drop-statements for that purpose. //! //! @@ -514,18 +514,14 @@ impl<'a, 'tcx> MirNeighborCollector<'a, 'tcx> { } impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { - fn visit_rvalue(&mut self, rvalue: &mir::Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &mir::Op<'tcx>, location: Location) { debug!("visiting rvalue {:?}", *rvalue); match *rvalue { // When doing an cast from a regular pointer to a fat pointer, we // have to instantiate all methods of the trait being cast to, so we // can build the appropriate vtable. - mir::Rvalue::Cast( - mir::CastKind::Pointer(PointerCast::Unsize), - ref operand, - target_ty, - ) => { + mir::Op::Cast(mir::CastKind::Pointer(PointerCast::Unsize), ref operand, target_ty) => { let target_ty = self.monomorphize(target_ty); let source_ty = operand.ty(self.body, self.tcx); let source_ty = self.monomorphize(source_ty); @@ -543,16 +539,12 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { ); } } - mir::Rvalue::Cast( - mir::CastKind::Pointer(PointerCast::ReifyFnPointer), - ref operand, - _, - ) => { + mir::Op::Cast(mir::CastKind::Pointer(PointerCast::ReifyFnPointer), ref operand, _) => { let fn_ty = operand.ty(self.body, self.tcx); let fn_ty = self.monomorphize(fn_ty); visit_fn_use(self.tcx, fn_ty, false, &mut self.output); } - mir::Rvalue::Cast( + mir::Op::Cast( mir::CastKind::Pointer(PointerCast::ClosureFnPointer(_)), ref operand, _, @@ -574,7 +566,7 @@ impl<'a, 'tcx> MirVisitor<'tcx> for MirNeighborCollector<'a, 'tcx> { _ => bug!(), } } - mir::Rvalue::NullaryOp(mir::NullOp::Box, _) => { + mir::Op::NullaryOp(mir::NullOp::Box, _) => { let tcx = self.tcx; let exchange_malloc_fn_def_id = tcx .lang_items() diff --git a/src/librustc_mir/shim.rs b/src/librustc_mir/shim.rs index 67de81ed77baa..68204e263f27c 100644 --- a/src/librustc_mir/shim.rs +++ b/src/librustc_mir/shim.rs @@ -418,7 +418,7 @@ impl CloneShimBuilder<'tcx> { let rcvr = self.tcx.mk_place_deref(Place::from(Local::new(1 + 0))); let ret_statement = self.make_statement(StatementKind::Assign(box ( Place::return_place(), - Rvalue::Use(Operand::Copy(rcvr)), + Op::Use(Operand::Copy(rcvr)), ))); self.block(vec![ret_statement], TerminatorKind::Return, false); } @@ -456,7 +456,7 @@ impl CloneShimBuilder<'tcx> { // `let ref_loc: &ty = &src;` let statement = self.make_statement(StatementKind::Assign(box ( ref_loc, - Rvalue::Ref(tcx.lifetimes.re_erased, BorrowKind::Shared, src), + Op::Ref(tcx.lifetimes.re_erased, BorrowKind::Shared, src), ))); // `let loc = Clone::clone(ref_loc);` @@ -486,7 +486,7 @@ impl CloneShimBuilder<'tcx> { let cond = self.make_place(Mutability::Mut, tcx.types.bool); let compute_cond = self.make_statement(StatementKind::Assign(box ( cond, - Rvalue::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg)), + Op::BinaryOp(BinOp::Ne, Operand::Copy(end), Operand::Copy(beg)), ))); // `if end != beg { goto loop_body; } else { goto loop_end; }` @@ -519,11 +519,11 @@ impl CloneShimBuilder<'tcx> { let inits = vec![ self.make_statement(StatementKind::Assign(box ( Place::from(beg), - Rvalue::Use(Operand::Constant(self.make_usize(0))), + Op::Use(Operand::Constant(self.make_usize(0))), ))), self.make_statement(StatementKind::Assign(box ( end, - Rvalue::Use(Operand::Constant(self.make_usize(len))), + Op::Use(Operand::Constant(self.make_usize(len))), ))), ]; self.block(inits, TerminatorKind::Goto { target: BasicBlock::new(1) }, false); @@ -547,7 +547,7 @@ impl CloneShimBuilder<'tcx> { // `goto #1`; let statements = vec![self.make_statement(StatementKind::Assign(box ( Place::from(beg), - Rvalue::BinaryOp( + Op::BinaryOp( BinOp::Add, Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)), @@ -567,7 +567,7 @@ impl CloneShimBuilder<'tcx> { let beg = self.local_decls.push(temp_decl(Mutability::Mut, tcx.types.usize, span)); let init = self.make_statement(StatementKind::Assign(box ( Place::from(beg), - Rvalue::Use(Operand::Constant(self.make_usize(0))), + Op::Use(Operand::Constant(self.make_usize(0))), ))); self.block(vec![init], TerminatorKind::Goto { target: BasicBlock::new(6) }, true); @@ -601,7 +601,7 @@ impl CloneShimBuilder<'tcx> { // `goto #6;` let statement = self.make_statement(StatementKind::Assign(box ( Place::from(beg), - Rvalue::BinaryOp( + Op::BinaryOp( BinOp::Add, Operand::Copy(Place::from(beg)), Operand::Constant(self.make_usize(1)), @@ -725,7 +725,7 @@ fn build_call_shim<'tcx>( source_info, kind: StatementKind::Assign(box ( Place::from(ref_rcvr), - Rvalue::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()), + Op::Ref(tcx.lifetimes.re_erased, borrow_kind, rcvr_place()), )), }); Operand::Move(Place::from(ref_rcvr)) 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 7c46855dfd63c..1532808c98f30 100644 --- a/src/librustc_mir/transform/add_moves_for_packed_drops.rs +++ b/src/librustc_mir/transform/add_moves_for_packed_drops.rs @@ -108,7 +108,7 @@ fn add_move_for_packed_drop<'tcx>( }); patch.add_statement(loc, StatementKind::StorageLive(temp)); - patch.add_assign(loc, Place::from(temp), Rvalue::Use(Operand::Move(*location))); + patch.add_assign(loc, Place::from(temp), Op::Use(Operand::Move(*location))); patch.patch_terminator( loc.block, TerminatorKind::Drop { 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 5c016b0c515af..22f1f7712890a 100644 --- a/src/librustc_mir/transform/add_retag.rs +++ b/src/librustc_mir/transform/add_retag.rs @@ -141,7 +141,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag { for i in (0..block_data.statements.len()).rev() { let (retag_kind, place) = match block_data.statements[i].kind { // Retag-as-raw after escaping to a raw pointer. - StatementKind::Assign(box (place, Rvalue::AddressOf(..))) => { + StatementKind::Assign(box (place, Op::AddressOf(..))) => { (RetagKind::Raw, place) } // Assignments of reference or ptr type are the ones where we may have @@ -149,9 +149,7 @@ impl<'tcx> MirPass<'tcx> for AddRetag { // we also retag after taking a reference! StatementKind::Assign(box (ref place, ref rvalue)) if needs_retag(place) => { let kind = match rvalue { - Rvalue::Ref(_, borrow_kind, _) - if borrow_kind.allows_two_phase_borrow() => - { + Op::Ref(_, borrow_kind, _) if borrow_kind.allows_two_phase_borrow() => { RetagKind::TwoPhase } _ => RetagKind::Default, diff --git a/src/librustc_mir/transform/check_consts/qualifs.rs b/src/librustc_mir/transform/check_consts/qualifs.rs index f38b9d8ef8586..badf94e14838f 100644 --- a/src/librustc_mir/transform/check_consts/qualifs.rs +++ b/src/librustc_mir/transform/check_consts/qualifs.rs @@ -106,29 +106,27 @@ impl Qualif for NeedsDrop { // FIXME: Use `mir::visit::Visitor` for the `in_*` functions if/when it supports early return. -/// Returns `true` if this `Rvalue` contains qualif `Q`. -pub fn in_rvalue(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, rvalue: &Rvalue<'tcx>) -> bool +/// Returns `true` if this `Op` contains qualif `Q`. +pub fn in_rvalue(cx: &ConstCx<'_, 'tcx>, in_local: &mut F, rvalue: &Op<'tcx>) -> bool where Q: Qualif, F: FnMut(Local) -> bool, { match rvalue { - Rvalue::NullaryOp(..) => Q::in_any_value_of_ty(cx, rvalue.ty(*cx.body, cx.tcx)), + Op::NullaryOp(..) => Q::in_any_value_of_ty(cx, rvalue.ty(*cx.body, cx.tcx)), - Rvalue::Discriminant(place) | Rvalue::Len(place) => { - in_place::(cx, in_local, place.as_ref()) - } + Op::Discriminant(place) | Op::Len(place) => in_place::(cx, in_local, place.as_ref()), - Rvalue::Use(operand) - | Rvalue::Repeat(operand, _) - | Rvalue::UnaryOp(_, operand) - | Rvalue::Cast(_, operand, _) => in_operand::(cx, in_local, operand), + Op::Use(operand) + | Op::Repeat(operand, _) + | Op::UnaryOp(_, operand) + | Op::Cast(_, operand, _) => in_operand::(cx, in_local, operand), - Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { + Op::BinaryOp(_, lhs, rhs) | Op::CheckedBinaryOp(_, lhs, rhs) => { in_operand::(cx, in_local, lhs) || in_operand::(cx, in_local, rhs) } - Rvalue::Ref(_, _, place) | Rvalue::AddressOf(_, place) => { + Op::Ref(_, _, place) | Op::AddressOf(_, place) => { // Special-case reborrows to be more like a copy of the reference. if let &[ref proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() { let base_ty = Place::ty_from(place.local, proj_base, *cx.body, cx.tcx).ty; @@ -144,7 +142,7 @@ where in_place::(cx, in_local, place.as_ref()) } - Rvalue::Aggregate(kind, operands) => { + Op::Aggregate(kind, operands) => { // Return early if we know that the struct or enum being constructed is always // qualified. if let AggregateKind::Adt(def, ..) = **kind { diff --git a/src/librustc_mir/transform/check_consts/resolver.rs b/src/librustc_mir/transform/check_consts/resolver.rs index b95a3939389ba..50db0a32c8b86 100644 --- a/src/librustc_mir/transform/check_consts/resolver.rs +++ b/src/librustc_mir/transform/check_consts/resolver.rs @@ -104,7 +104,7 @@ where fn visit_assign( &mut self, place: &mir::Place<'tcx>, - rvalue: &mir::Rvalue<'tcx>, + rvalue: &mir::Op<'tcx>, location: Location, ) { let qualif = qualifs::in_rvalue::( diff --git a/src/librustc_mir/transform/check_consts/validation.rs b/src/librustc_mir/transform/check_consts/validation.rs index e4a0b9cdb48b1..213602f3c9962 100644 --- a/src/librustc_mir/transform/check_consts/validation.rs +++ b/src/librustc_mir/transform/check_consts/validation.rs @@ -255,12 +255,12 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { self.super_basic_block_data(bb, block); } - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { trace!("visit_rvalue: rvalue={:?} location={:?}", rvalue, location); // Special-case reborrows to be more like a copy of a reference. match *rvalue { - Rvalue::Ref(_, kind, place) => { + Op::Ref(_, kind, place) => { if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, *self.body, place) { let ctx = match kind { BorrowKind::Shared => { @@ -281,7 +281,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { return; } } - Rvalue::AddressOf(mutbl, place) => { + Op::AddressOf(mutbl, place) => { if let Some(reborrowed_proj) = place_as_reborrow(self.tcx, *self.body, place) { let ctx = match mutbl { Mutability::Not => { @@ -300,19 +300,19 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { self.super_rvalue(rvalue, location); match *rvalue { - Rvalue::Use(_) - | Rvalue::Repeat(..) - | Rvalue::UnaryOp(UnOp::Neg, _) - | Rvalue::UnaryOp(UnOp::Not, _) - | Rvalue::NullaryOp(NullOp::SizeOf, _) - | Rvalue::CheckedBinaryOp(..) - | Rvalue::Cast(CastKind::Pointer(_), ..) - | Rvalue::Discriminant(..) - | Rvalue::Len(_) - | Rvalue::Aggregate(..) => {} - - Rvalue::Ref(_, kind @ BorrowKind::Mut { .. }, ref place) - | Rvalue::Ref(_, kind @ BorrowKind::Unique, ref place) => { + Op::Use(_) + | Op::Repeat(..) + | Op::UnaryOp(UnOp::Neg, _) + | Op::UnaryOp(UnOp::Not, _) + | Op::NullaryOp(NullOp::SizeOf, _) + | Op::CheckedBinaryOp(..) + | Op::Cast(CastKind::Pointer(_), ..) + | Op::Discriminant(..) + | Op::Len(_) + | Op::Aggregate(..) => {} + + Op::Ref(_, kind @ BorrowKind::Mut { .. }, ref place) + | Op::Ref(_, kind @ BorrowKind::Unique, ref place) => { let ty = place.ty(*self.body, self.tcx).ty; let is_allowed = match ty.kind { // Inside a `static mut`, `&mut [...]` is allowed. @@ -339,11 +339,11 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { } } - Rvalue::AddressOf(Mutability::Mut, _) => self.check_op(ops::MutAddressOf), + Op::AddressOf(Mutability::Mut, _) => self.check_op(ops::MutAddressOf), - Rvalue::Ref(_, BorrowKind::Shared, ref place) - | Rvalue::Ref(_, BorrowKind::Shallow, ref place) - | Rvalue::AddressOf(Mutability::Not, ref place) => { + Op::Ref(_, BorrowKind::Shared, ref place) + | Op::Ref(_, BorrowKind::Shallow, ref place) + | Op::AddressOf(Mutability::Not, ref place) => { let borrowed_place_has_mut_interior = qualifs::in_place::( &self.item, &mut |local| self.qualifs.has_mut_interior(local, location), @@ -355,7 +355,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { } } - Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) => { + Op::Cast(CastKind::Misc, ref operand, cast_ty) => { let operand_ty = operand.ty(*self.body, self.tcx); let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); @@ -367,7 +367,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { } } - Rvalue::BinaryOp(op, ref lhs, _) => { + Op::BinaryOp(op, ref lhs, _) => { if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(*self.body, self.tcx).kind { assert!( op == BinOp::Eq @@ -383,7 +383,7 @@ impl Visitor<'tcx> for Validator<'_, 'mir, 'tcx> { } } - Rvalue::NullaryOp(NullOp::Box, _) => { + Op::NullaryOp(NullOp::Box, _) => { self.check_op(ops::HeapAllocation); } } diff --git a/src/librustc_mir/transform/check_unsafety.rs b/src/librustc_mir/transform/check_unsafety.rs index 3ce9b875e16cc..f480b03e1409b 100644 --- a/src/librustc_mir/transform/check_unsafety.rs +++ b/src/librustc_mir/transform/check_unsafety.rs @@ -115,9 +115,9 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { self.super_statement(statement, location); } - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { match rvalue { - Rvalue::Aggregate(box ref aggregate, _) => match aggregate { + Op::Aggregate(box ref aggregate, _) => match aggregate { &AggregateKind::Array(..) | &AggregateKind::Tuple => {} &AggregateKind::Adt(ref def, ..) => { match self.tcx.layout_scalar_valid_range(def.did) { @@ -139,7 +139,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // casting pointers to ints is unsafe in const fn because the const evaluator cannot // possibly know what the result of various operations like `address / 2` would be // pointers during const evaluation have no integral address, only an abstract one - Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) + Op::Cast(CastKind::Misc, ref operand, cast_ty) if self.const_context && self.tcx.features().const_raw_ptr_to_usize_cast => { let operand_ty = operand.ty(self.body, self.tcx); @@ -160,7 +160,7 @@ impl<'a, 'tcx> Visitor<'tcx> for UnsafetyChecker<'a, 'tcx> { // pointer would be "less" or "equal" to another, because we cannot know where llvm // or the linker will place various statics in memory. Without this information the // result of a comparison of addresses would differ between runtime and compile-time. - Rvalue::BinaryOp(_, ref lhs, _) + Op::BinaryOp(_, ref lhs, _) if self.const_context && self.tcx.features().const_compare_raw_pointers => { if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(self.body, self.tcx).kind { diff --git a/src/librustc_mir/transform/cleanup_post_borrowck.rs b/src/librustc_mir/transform/cleanup_post_borrowck.rs index 446aadd56dc30..af68308a4e3e5 100644 --- a/src/librustc_mir/transform/cleanup_post_borrowck.rs +++ b/src/librustc_mir/transform/cleanup_post_borrowck.rs @@ -18,7 +18,7 @@ use crate::transform::{MirPass, MirSource}; use rustc_middle::mir::visit::MutVisitor; -use rustc_middle::mir::{BodyAndCache, BorrowKind, Location, Rvalue}; +use rustc_middle::mir::{BodyAndCache, BorrowKind, Location, Op}; use rustc_middle::mir::{Statement, StatementKind}; use rustc_middle::ty::TyCtxt; @@ -44,7 +44,7 @@ impl<'tcx> MutVisitor<'tcx> for DeleteNonCodegenStatements<'tcx> { fn visit_statement(&mut self, statement: &mut Statement<'tcx>, location: Location) { match statement.kind { StatementKind::AscribeUserType(..) - | StatementKind::Assign(box (_, Rvalue::Ref(_, BorrowKind::Shallow, _))) + | StatementKind::Assign(box (_, Op::Ref(_, BorrowKind::Shallow, _))) | StatementKind::FakeRead(..) => statement.make_nop(), _ => (), } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 25719d037f9fc..ab460bc0299bd 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -15,7 +15,7 @@ use rustc_middle::mir::visit::{ }; use rustc_middle::mir::{ read_only, AggregateKind, AssertKind, BasicBlock, BinOp, Body, BodyAndCache, ClearCrossCrate, - Constant, Local, LocalDecl, LocalKind, Location, Operand, Place, ReadOnlyBodyAndCache, Rvalue, + Constant, Local, LocalDecl, LocalKind, Location, Op, Operand, Place, ReadOnlyBodyAndCache, SourceInfo, SourceScope, SourceScopeData, Statement, StatementKind, Terminator, TerminatorKind, UnOp, RETURN_PLACE, }; @@ -565,7 +565,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn const_prop( &mut self, - rvalue: &Rvalue<'tcx>, + rvalue: &Op<'tcx>, place_layout: TyAndLayout<'tcx>, source_info: SourceInfo, place: Place<'tcx>, @@ -580,7 +580,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { return None; } - // Perform any special handling for specific Rvalue types. + // Perform any special handling for specific Op types. // Generally, checks here fall into one of two categories: // 1. Additional checking to provide useful lints to the user // - In this case, we will do some validation and then fall through to the @@ -592,15 +592,15 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { // We do this here and not in the `Assert` terminator as that terminator is // only sometimes emitted (overflow checks can be disabled), but we want to always // lint. - Rvalue::UnaryOp(op, arg) => { + Op::UnaryOp(op, arg) => { trace!("checking UnaryOp(op = {:?}, arg = {:?})", op, arg); self.check_unary_op(*op, arg, source_info)?; } - Rvalue::BinaryOp(op, left, right) => { + Op::BinaryOp(op, left, right) => { trace!("checking BinaryOp(op = {:?}, left = {:?}, right = {:?})", op, left, right); self.check_binary_op(*op, left, right, source_info)?; } - Rvalue::CheckedBinaryOp(op, left, right) => { + Op::CheckedBinaryOp(op, left, right) => { trace!( "checking CheckedBinaryOp(op = {:?}, left = {:?}, right = {:?})", op, @@ -611,7 +611,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { } // Do not try creating references (#67862) - Rvalue::Ref(_, _, place_ref) => { + Op::Ref(_, _, place_ref) => { trace!("skipping Ref({:?})", place_ref); return None; @@ -637,7 +637,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { fn replace_with_const( &mut self, - rval: &mut Rvalue<'tcx>, + rval: &mut Op<'tcx>, value: OpTy<'tcx>, source_info: SourceInfo, ) { @@ -659,7 +659,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { if let Some(Ok(imm)) = imm { match *imm { interpret::Immediate::Scalar(ScalarMaybeUndef::Scalar(scalar)) => { - *rval = Rvalue::Use(self.operand_from_scalar( + *rval = Op::Use(self.operand_from_scalar( scalar, value.layout.ty, source_info.span, @@ -670,7 +670,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { ScalarMaybeUndef::Scalar(two), ) => { // Found a value represented as a pair. For now only do cont-prop if type of - // Rvalue is also a pair with two scalars. The more general case is more + // Op is also a pair with two scalars. The more general case is more // complicated to implement so we'll do it later. let ty = &value.layout.ty.kind; // Only do it for tuples @@ -692,7 +692,7 @@ impl<'mir, 'tcx> ConstPropagator<'mir, 'tcx> { }); if let Some(Some((ty1, ty2))) = opt_ty1_ty2 { - *rval = Rvalue::Aggregate( + *rval = Op::Aggregate( Box::new(AggregateKind::Tuple), vec![ self.operand_from_scalar(one, ty1, source_info.span), diff --git a/src/librustc_mir/transform/copy_prop.rs b/src/librustc_mir/transform/copy_prop.rs index a25b554b345eb..2a123af37af5c 100644 --- a/src/librustc_mir/transform/copy_prop.rs +++ b/src/librustc_mir/transform/copy_prop.rs @@ -23,7 +23,7 @@ use crate::transform::{MirPass, MirSource}; use crate::util::def_use::DefUseAnalysis; use rustc_middle::mir::visit::MutVisitor; use rustc_middle::mir::{ - read_only, Body, BodyAndCache, Constant, Local, LocalKind, Location, Operand, Place, Rvalue, + read_only, Body, BodyAndCache, Constant, Local, LocalKind, Location, Op, Operand, Place, StatementKind, }; use rustc_middle::ty::TyCtxt; @@ -93,7 +93,7 @@ impl<'tcx> MirPass<'tcx> for CopyPropagation { // That use of the source must be an assignment. match &statement.kind { - StatementKind::Assign(box (place, Rvalue::Use(operand))) => { + StatementKind::Assign(box (place, Op::Use(operand))) => { if let Some(local) = place.as_local() { if local == dest_local { let maybe_action = match operand { @@ -156,8 +156,8 @@ fn eliminate_self_assignments(body: &mut Body<'_>, def_use_analysis: &DefUseAnal let location = def.location; if let Some(stmt) = body[location.block].statements.get(location.statement_index) { match &stmt.kind { - StatementKind::Assign(box (place, Rvalue::Use(Operand::Copy(src_place)))) - | StatementKind::Assign(box (place, Rvalue::Use(Operand::Move(src_place)))) => { + StatementKind::Assign(box (place, Op::Use(Operand::Copy(src_place)))) + | StatementKind::Assign(box (place, Op::Use(Operand::Move(src_place)))) => { if let (Some(local), Some(src_local)) = (place.as_local(), src_place.as_local()) { diff --git a/src/librustc_mir/transform/deaggregator.rs b/src/librustc_mir/transform/deaggregator.rs index 3e2be7fd7d554..67cd25219da03 100644 --- a/src/librustc_mir/transform/deaggregator.rs +++ b/src/librustc_mir/transform/deaggregator.rs @@ -13,7 +13,7 @@ impl<'tcx> MirPass<'tcx> for Deaggregator { bb.expand_statements(|stmt| { // FIXME(eddyb) don't match twice on `stmt.kind` (post-NLL). if let StatementKind::Assign(box (_, ref rhs)) = stmt.kind { - if let Rvalue::Aggregate(ref kind, _) = *rhs { + if let Op::Aggregate(ref kind, _) = *rhs { // FIXME(#48193) Deaggregate arrays when it's cheaper to do so. if let AggregateKind::Array(_) = **kind { return None; @@ -29,7 +29,7 @@ impl<'tcx> MirPass<'tcx> for Deaggregator { let source_info = stmt.source_info; let (lhs, kind, operands) = match stmt.kind { StatementKind::Assign(box (lhs, rvalue)) => match rvalue { - Rvalue::Aggregate(kind, operands) => (lhs, kind, operands), + Op::Aggregate(kind, operands) => (lhs, kind, operands), _ => bug!(), }, _ => bug!(), diff --git a/src/librustc_mir/transform/elaborate_drops.rs b/src/librustc_mir/transform/elaborate_drops.rs index a7c6b5a98bbc1..82e45129d61da 100644 --- a/src/librustc_mir/transform/elaborate_drops.rs +++ b/src/librustc_mir/transform/elaborate_drops.rs @@ -407,7 +407,7 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { assert!(!data.is_cleanup, "DropAndReplace in unwind path not supported"); let assign = Statement { - kind: StatementKind::Assign(box (location, Rvalue::Use(value.clone()))), + kind: StatementKind::Assign(box (location, Op::Use(value.clone()))), source_info: terminator.source_info, }; @@ -465,8 +465,8 @@ impl<'b, 'tcx> ElaborateDropsCtxt<'b, 'tcx> { } } - fn constant_bool(&self, span: Span, val: bool) -> Rvalue<'tcx> { - Rvalue::Use(Operand::Constant(Box::new(Constant { + fn constant_bool(&self, span: Span, val: bool) -> Op<'tcx> { + Op::Use(Operand::Constant(Box::new(Constant { span, user_ty: None, literal: ty::Const::from_bool(self.tcx, val), diff --git a/src/librustc_mir/transform/generator.rs b/src/librustc_mir/transform/generator.rs index 53eec1f6dc3de..c61ebaf1d303a 100644 --- a/src/librustc_mir/transform/generator.rs +++ b/src/librustc_mir/transform/generator.rs @@ -228,9 +228,9 @@ struct TransformVisitor<'tcx> { impl TransformVisitor<'tcx> { // Make a GeneratorState rvalue - fn make_state(&self, idx: VariantIdx, val: Operand<'tcx>) -> Rvalue<'tcx> { + fn make_state(&self, idx: VariantIdx, val: Operand<'tcx>) -> Op<'tcx> { let adt = AggregateKind::Adt(self.state_adt_ref, idx, self.state_substs, None, None); - Rvalue::Aggregate(box adt, vec![val]) + Op::Aggregate(box adt, vec![val]) } // Create a Place referencing a generator struct field @@ -264,7 +264,7 @@ impl TransformVisitor<'tcx> { let self_place = Place::from(SELF_ARG); let assign = Statement { source_info: source_info(body), - kind: StatementKind::Assign(box (temp, Rvalue::Discriminant(self_place))), + kind: StatementKind::Assign(box (temp, Op::Discriminant(self_place))), }; (assign, temp) } @@ -1193,7 +1193,7 @@ fn create_cases<'tcx>( source_info, kind: StatementKind::Assign(box ( point.resume_arg, - Rvalue::Use(Operand::Move(resume_arg.into())), + Op::Use(Operand::Move(resume_arg.into())), )), }); } @@ -1271,7 +1271,7 @@ impl<'tcx> MirPass<'tcx> for StateTransform { source_info, kind: StatementKind::Assign(box ( new_resume_local.into(), - Rvalue::Use(Operand::Move(resume_local.into())), + Op::Use(Operand::Move(resume_local.into())), )), }, ); diff --git a/src/librustc_mir/transform/inline.rs b/src/librustc_mir/transform/inline.rs index 157dada831a2e..006228ccdf8c7 100644 --- a/src/librustc_mir/transform/inline.rs +++ b/src/librustc_mir/transform/inline.rs @@ -463,7 +463,7 @@ impl Inliner<'tcx> { let dest = if dest_needs_borrow(destination.0) { debug!("creating temp for return destination"); - let dest = Rvalue::Ref( + let dest = Op::Ref( self.tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, destination.0, @@ -618,7 +618,7 @@ impl Inliner<'tcx> { debug!("creating temp for argument {:?}", arg); // Otherwise, create a temporary for the arg - let arg = Rvalue::Use(arg); + let arg = Op::Use(arg); let ty = arg.ty(&**caller_body, self.tcx); diff --git a/src/librustc_mir/transform/instcombine.rs b/src/librustc_mir/transform/instcombine.rs index 3a60048b0ef4e..b63bcf558b134 100644 --- a/src/librustc_mir/transform/instcombine.rs +++ b/src/librustc_mir/transform/instcombine.rs @@ -5,8 +5,8 @@ use rustc_data_structures::fx::{FxHashMap, FxHashSet}; use rustc_index::vec::Idx; use rustc_middle::mir::visit::{MutVisitor, Visitor}; use rustc_middle::mir::{ - read_only, Body, BodyAndCache, Constant, Local, Location, Operand, Place, PlaceRef, - ProjectionElem, Rvalue, + read_only, Body, BodyAndCache, Constant, Local, Location, Op, Operand, Place, PlaceRef, + ProjectionElem, }; use rustc_middle::ty::{self, TyCtxt}; use std::mem; @@ -45,11 +45,11 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { self.tcx } - fn visit_rvalue(&mut self, rvalue: &mut Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &mut Op<'tcx>, location: Location) { if self.optimizations.and_stars.remove(&location) { debug!("replacing `&*`: {:?}", rvalue); let new_place = match rvalue { - Rvalue::Ref(_, _, place) => { + Op::Ref(_, _, place) => { if let &[ref proj_l @ .., proj_r] = place.projection.as_ref() { place.projection = self.tcx().intern_place_elems(&[proj_r]); @@ -64,12 +64,12 @@ impl<'tcx> MutVisitor<'tcx> for InstCombineVisitor<'tcx> { } _ => bug!("Detected `&*` but didn't find `&*`!"), }; - *rvalue = Rvalue::Use(Operand::Copy(new_place)) + *rvalue = Op::Use(Operand::Copy(new_place)) } if let Some(constant) = self.optimizations.arrays_lengths.remove(&location) { debug!("replacing `Len([_; N])`: {:?}", rvalue); - *rvalue = Rvalue::Use(Operand::Constant(box constant)); + *rvalue = Op::Use(Operand::Constant(box constant)); } self.super_rvalue(rvalue, location) @@ -90,8 +90,8 @@ impl OptimizationFinder<'b, 'tcx> { } impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> { - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { - if let Rvalue::Ref(_, _, place) = rvalue { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { + if let Op::Ref(_, _, place) = rvalue { if let PlaceRef { local, projection: &[ref proj_base @ .., ProjectionElem::Deref] } = place.as_ref() { @@ -101,7 +101,7 @@ impl Visitor<'tcx> for OptimizationFinder<'b, 'tcx> { } } - if let Rvalue::Len(ref place) = *rvalue { + if let Op::Len(ref place) = *rvalue { let place_ty = place.ty(&self.body.local_decls, self.tcx).ty; if let ty::Array(_, len) = place_ty.kind { let span = self.body.source_info(location).span; diff --git a/src/librustc_mir/transform/promote_consts.rs b/src/librustc_mir/transform/promote_consts.rs index ec0b89ebb4d0a..2c8e07e71bb17 100644 --- a/src/librustc_mir/transform/promote_consts.rs +++ b/src/librustc_mir/transform/promote_consts.rs @@ -197,14 +197,14 @@ impl<'tcx> Visitor<'tcx> for Collector<'_, 'tcx> { *temp = TempState::Unpromotable; } - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { self.super_rvalue(rvalue, location); match *rvalue { - Rvalue::Ref(..) => { + Op::Ref(..) => { self.candidates.push(Candidate::Ref(location)); } - Rvalue::Repeat(..) if self.tcx.features().const_in_array_repeat_expressions => { + Op::Repeat(..) if self.tcx.features().const_in_array_repeat_expressions => { // FIXME(#49147) only promote the element when it isn't `Copy` // (so that code that can copy it at runtime is unaffected). self.candidates.push(Candidate::Repeat(location)); @@ -295,7 +295,7 @@ impl<'tcx> Validator<'_, 'tcx> { let statement = &self.body[loc.block].statements[loc.statement_index]; match &statement.kind { - StatementKind::Assign(box (_, Rvalue::Ref(_, kind, place))) => { + StatementKind::Assign(box (_, Op::Ref(_, kind, place))) => { match kind { BorrowKind::Shared | BorrowKind::Mut { .. } => {} @@ -383,7 +383,7 @@ impl<'tcx> Validator<'_, 'tcx> { let statement = &self.body[loc.block].statements[loc.statement_index]; match &statement.kind { - StatementKind::Assign(box (_, Rvalue::Repeat(ref operand, _))) => { + StatementKind::Assign(box (_, Op::Repeat(ref operand, _))) => { if !self.tcx.features().const_in_array_repeat_expressions { return Err(Unpromotable); } @@ -536,9 +536,9 @@ impl<'tcx> Validator<'_, 'tcx> { } } - fn validate_rvalue(&self, rvalue: &Rvalue<'tcx>) -> Result<(), Unpromotable> { + fn validate_rvalue(&self, rvalue: &Op<'tcx>) -> Result<(), Unpromotable> { match *rvalue { - Rvalue::Cast(CastKind::Misc, ref operand, cast_ty) if self.const_kind.is_none() => { + Op::Cast(CastKind::Misc, ref operand, cast_ty) if self.const_kind.is_none() => { let operand_ty = operand.ty(*self.body, self.tcx); let cast_in = CastTy::from_ty(operand_ty).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); @@ -551,7 +551,7 @@ impl<'tcx> Validator<'_, 'tcx> { } } - Rvalue::BinaryOp(op, ref lhs, _) if self.const_kind.is_none() => { + Op::BinaryOp(op, ref lhs, _) if self.const_kind.is_none() => { if let ty::RawPtr(_) | ty::FnPtr(..) = lhs.ty(*self.body, self.tcx).kind { assert!( op == BinOp::Eq @@ -568,27 +568,27 @@ impl<'tcx> Validator<'_, 'tcx> { } } - Rvalue::NullaryOp(NullOp::Box, _) => return Err(Unpromotable), + Op::NullaryOp(NullOp::Box, _) => return Err(Unpromotable), _ => {} } match rvalue { - Rvalue::NullaryOp(..) => Ok(()), + Op::NullaryOp(..) => Ok(()), - Rvalue::Discriminant(place) | Rvalue::Len(place) => self.validate_place(place.as_ref()), + Op::Discriminant(place) | Op::Len(place) => self.validate_place(place.as_ref()), - Rvalue::Use(operand) - | Rvalue::Repeat(operand, _) - | Rvalue::UnaryOp(_, operand) - | Rvalue::Cast(_, operand, _) => self.validate_operand(operand), + Op::Use(operand) + | Op::Repeat(operand, _) + | Op::UnaryOp(_, operand) + | Op::Cast(_, operand, _) => self.validate_operand(operand), - Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { + Op::BinaryOp(_, lhs, rhs) | Op::CheckedBinaryOp(_, lhs, rhs) => { self.validate_operand(lhs)?; self.validate_operand(rhs) } - Rvalue::AddressOf(_, place) => { + Op::AddressOf(_, place) => { // Raw reborrows can come from reference to pointer coercions, // so are allowed. if let [proj_base @ .., ProjectionElem::Deref] = place.projection.as_ref() { @@ -603,7 +603,7 @@ impl<'tcx> Validator<'_, 'tcx> { Err(Unpromotable) } - Rvalue::Ref(_, kind, place) => { + Op::Ref(_, kind, place) => { if let BorrowKind::Mut { .. } = kind { let ty = place.ty(*self.body, self.tcx).ty; @@ -668,7 +668,7 @@ impl<'tcx> Validator<'_, 'tcx> { Ok(()) } - Rvalue::Aggregate(_, ref operands) => { + Op::Aggregate(_, ref operands) => { for o in operands { self.validate_operand(o)?; } @@ -775,7 +775,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { }) } - fn assign(&mut self, dest: Local, rvalue: Rvalue<'tcx>, span: Span) { + fn assign(&mut self, dest: Local, rvalue: Op<'tcx>, span: Span) { let last = self.promoted.basic_blocks().last().unwrap(); let data = &mut self.promoted[last]; data.statements.push(Statement { @@ -815,7 +815,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { debug!("promote({:?} @ {:?}/{:?}, {:?})", temp, loc, num_stmts, self.keep_original); - // First, take the Rvalue or Call out of the source MIR, + // First, take the Op or Call out of the source MIR, // or duplicate it, depending on keep_original. if loc.statement_index < num_stmts { let (mut rvalue, source_info) = { @@ -835,7 +835,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { if self.keep_original { rhs.clone() } else { - let unit = Rvalue::Aggregate(box AggregateKind::Tuple, vec![]); + let unit = Op::Aggregate(box AggregateKind::Tuple, vec![]); mem::replace(rhs, unit) }, statement.source_info, @@ -932,7 +932,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { match statement.kind { StatementKind::Assign(box ( _, - Rvalue::Ref(ref mut region, borrow_kind, ref mut place), + Op::Ref(ref mut region, borrow_kind, ref mut place), )) => { // Use the underlying local for this (necessarily interior) borrow. let ty = local_decls.local_decls()[place.local].ty; @@ -961,12 +961,12 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { source_info: statement.source_info, kind: StatementKind::Assign(Box::new(( Place::from(promoted_ref), - Rvalue::Use(promoted_operand(ref_ty, span)), + Op::Use(promoted_operand(ref_ty, span)), ))), }; self.extra_statements.push((loc, promoted_ref_statement)); - Rvalue::Ref( + Op::Ref( tcx.lifetimes.re_erased, borrow_kind, Place { @@ -981,11 +981,11 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { Candidate::Repeat(loc) => { let statement = &mut blocks[loc.block].statements[loc.statement_index]; match statement.kind { - StatementKind::Assign(box (_, Rvalue::Repeat(ref mut operand, _))) => { + StatementKind::Assign(box (_, Op::Repeat(ref mut operand, _))) => { let ty = operand.ty(local_decls, self.tcx); let span = statement.source_info.span; - Rvalue::Use(mem::replace(operand, promoted_operand(ty, span))) + Op::Use(mem::replace(operand, promoted_operand(ty, span))) } _ => bug!(), } @@ -997,7 +997,7 @@ impl<'a, 'tcx> Promoter<'a, 'tcx> { let ty = args[index].ty(local_decls, self.tcx); let span = terminator.source_info.span; - Rvalue::Use(mem::replace(&mut args[index], promoted_operand(ty, span))) + Op::Use(mem::replace(&mut args[index], promoted_operand(ty, span))) } // We expected a `TerminatorKind::Call` for which we'd like to promote an // argument. `qualify_consts` saw a `TerminatorKind::Call` here, but diff --git a/src/librustc_mir/transform/qualify_min_const_fn.rs b/src/librustc_mir/transform/qualify_min_const_fn.rs index 8f7a1b948e3fd..243f3e1778564 100644 --- a/src/librustc_mir/transform/qualify_min_const_fn.rs +++ b/src/librustc_mir/transform/qualify_min_const_fn.rs @@ -149,18 +149,18 @@ fn check_rvalue( tcx: TyCtxt<'tcx>, body: &Body<'tcx>, def_id: DefId, - rvalue: &Rvalue<'tcx>, + rvalue: &Op<'tcx>, span: Span, ) -> McfResult { match rvalue { - Rvalue::Repeat(operand, _) | Rvalue::Use(operand) => { + Op::Repeat(operand, _) | Op::Use(operand) => { check_operand(tcx, operand, span, def_id, body) } - Rvalue::Len(place) - | Rvalue::Discriminant(place) - | Rvalue::Ref(_, _, place) - | Rvalue::AddressOf(_, place) => check_place(tcx, *place, span, def_id, body), - Rvalue::Cast(CastKind::Misc, operand, cast_ty) => { + Op::Len(place) + | Op::Discriminant(place) + | Op::Ref(_, _, place) + | Op::AddressOf(_, place) => check_place(tcx, *place, span, def_id, body), + Op::Cast(CastKind::Misc, operand, cast_ty) => { use rustc_middle::ty::cast::CastTy; let cast_in = CastTy::from_ty(operand.ty(body, tcx)).expect("bad input type for cast"); let cast_out = CastTy::from_ty(cast_ty).expect("bad output type for cast"); @@ -171,20 +171,20 @@ fn check_rvalue( _ => check_operand(tcx, operand, span, def_id, body), } } - Rvalue::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, _) - | Rvalue::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, _) => { + Op::Cast(CastKind::Pointer(PointerCast::MutToConstPointer), operand, _) + | Op::Cast(CastKind::Pointer(PointerCast::ArrayToPointer), operand, _) => { check_operand(tcx, operand, span, def_id, body) } - Rvalue::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), _, _) - | Rvalue::Cast(CastKind::Pointer(PointerCast::ClosureFnPointer(_)), _, _) - | Rvalue::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), _, _) => { + Op::Cast(CastKind::Pointer(PointerCast::UnsafeFnPointer), _, _) + | Op::Cast(CastKind::Pointer(PointerCast::ClosureFnPointer(_)), _, _) + | Op::Cast(CastKind::Pointer(PointerCast::ReifyFnPointer), _, _) => { Err((span, "function pointer casts are not allowed in const fn".into())) } - Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), _, _) => { + Op::Cast(CastKind::Pointer(PointerCast::Unsize), _, _) => { Err((span, "unsizing casts are not allowed in const fn".into())) } // binops are fine on integers - Rvalue::BinaryOp(_, lhs, rhs) | Rvalue::CheckedBinaryOp(_, lhs, rhs) => { + Op::BinaryOp(_, lhs, rhs) | Op::CheckedBinaryOp(_, lhs, rhs) => { check_operand(tcx, lhs, span, def_id, body)?; check_operand(tcx, rhs, span, def_id, body)?; let ty = lhs.ty(body, tcx); @@ -194,11 +194,11 @@ fn check_rvalue( Err((span, "only int, `bool` and `char` operations are stable in const fn".into())) } } - Rvalue::NullaryOp(NullOp::SizeOf, _) => Ok(()), - Rvalue::NullaryOp(NullOp::Box, _) => { + Op::NullaryOp(NullOp::SizeOf, _) => Ok(()), + Op::NullaryOp(NullOp::Box, _) => { Err((span, "heap allocations are not allowed in const fn".into())) } - Rvalue::UnaryOp(_, operand) => { + Op::UnaryOp(_, operand) => { let ty = operand.ty(body, tcx); if ty.is_integral() || ty.is_bool() { check_operand(tcx, operand, span, def_id, body) @@ -206,7 +206,7 @@ fn check_rvalue( Err((span, "only int and `bool` operations are stable in const fn".into())) } } - Rvalue::Aggregate(_, operands) => { + Op::Aggregate(_, operands) => { for operand in operands { check_operand(tcx, operand, span, def_id, body)?; } diff --git a/src/librustc_mir/transform/remove_noop_landing_pads.rs b/src/librustc_mir/transform/remove_noop_landing_pads.rs index 5e4fd061c7666..d45b8c6eafa4e 100644 --- a/src/librustc_mir/transform/remove_noop_landing_pads.rs +++ b/src/librustc_mir/transform/remove_noop_landing_pads.rs @@ -41,7 +41,7 @@ impl RemoveNoopLandingPads { // These are all nops in a landing pad } - StatementKind::Assign(box (place, Rvalue::Use(_))) => { + StatementKind::Assign(box (place, Op::Use(_))) => { if place.as_local().is_some() { // Writing to a local (e.g., a drop flag) does not // turn a landing pad to a non-nop diff --git a/src/librustc_mir/transform/rustc_peek.rs b/src/librustc_mir/transform/rustc_peek.rs index cccf9ff30168c..1cef405a35f5a 100644 --- a/src/librustc_mir/transform/rustc_peek.rs +++ b/src/librustc_mir/transform/rustc_peek.rs @@ -121,9 +121,9 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>( ); match (call.kind, peek_rval) { - (PeekCallKind::ByRef, mir::Rvalue::Ref(_, _, place)) - | (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Move(place))) - | (PeekCallKind::ByVal, mir::Rvalue::Use(mir::Operand::Copy(place))) => { + (PeekCallKind::ByRef, mir::Op::Ref(_, _, place)) + | (PeekCallKind::ByVal, mir::Op::Use(mir::Operand::Move(place))) + | (PeekCallKind::ByVal, mir::Op::Use(mir::Operand::Copy(place))) => { let loc = Location { block: bb, statement_index }; cursor.seek_before(loc); let state = cursor.get(); @@ -144,7 +144,7 @@ pub fn sanity_check_via_rustc_peek<'tcx, A>( fn value_assigned_to_local<'a, 'tcx>( stmt: &'a mir::Statement<'tcx>, local: Local, -) -> Option<&'a mir::Rvalue<'tcx>> { +) -> Option<&'a mir::Op<'tcx>> { if let mir::StatementKind::Assign(box (place, rvalue)) = &stmt.kind { if let Some(l) = place.as_local() { if local == l { diff --git a/src/librustc_mir/transform/simplify.rs b/src/librustc_mir/transform/simplify.rs index c2029a223b941..e911bb14e5df4 100644 --- a/src/librustc_mir/transform/simplify.rs +++ b/src/librustc_mir/transform/simplify.rs @@ -370,7 +370,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> { if let StatementKind::Assign(box (dest, rvalue)) = &stmt.kind { if !dest.is_indirect() && dest.local == *local { - if let Rvalue::Use(Operand::Constant(c)) = rvalue { + if let Op::Use(Operand::Constant(c)) = rvalue { match c.literal.val { // Keep assignments from unevaluated constants around, since the // evaluation may report errors, even if the use of the constant @@ -381,7 +381,7 @@ impl<'a, 'tcx> Visitor<'tcx> for DeclMarker<'a, 'tcx> { return; } } - } else if let Rvalue::Discriminant(d) = rvalue { + } else if let Op::Discriminant(d) = rvalue { trace!("skipping store of discriminant value {:?} to {:?}", d, dest); return; } diff --git a/src/librustc_mir/transform/simplify_try.rs b/src/librustc_mir/transform/simplify_try.rs index 7cdd929c7a033..96173e2ee0763 100644 --- a/src/librustc_mir/transform/simplify_try.rs +++ b/src/librustc_mir/transform/simplify_try.rs @@ -70,7 +70,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { match &mut s0.kind { StatementKind::Assign(box (place, rvalue)) => { *place = local_0.into(); - *rvalue = Rvalue::Use(Operand::Move(local_1.into())); + *rvalue = Op::Use(Operand::Move(local_1.into())); } _ => unreachable!(), } @@ -87,7 +87,7 @@ impl<'tcx> MirPass<'tcx> for SimplifyArmIdentity { fn match_get_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { match &stmt.kind { StatementKind::Assign(box (place_into, rvalue_from)) => match rvalue_from { - Rvalue::Use(Operand::Copy(pf)) | Rvalue::Use(Operand::Move(pf)) => { + Op::Use(Operand::Copy(pf)) | Op::Use(Operand::Move(pf)) => { let local_into = place_into.as_local()?; let (local_from, vf) = match_variant_field_place(*pf)?; Some((local_into, local_from, vf)) @@ -105,7 +105,7 @@ fn match_get_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local fn match_set_variant_field<'tcx>(stmt: &Statement<'tcx>) -> Option<(Local, Local, VarField<'tcx>)> { match &stmt.kind { StatementKind::Assign(box (place_from, rvalue_into)) => match rvalue_into { - Rvalue::Use(Operand::Move(place_into)) => { + Op::Use(Operand::Move(place_into)) => { let local_into = place_into.as_local()?; let (local_from, vf) = match_variant_field_place(*place_from)?; Some((local_into, local_from, vf)) diff --git a/src/librustc_mir/transform/uninhabited_enum_branching.rs b/src/librustc_mir/transform/uninhabited_enum_branching.rs index 0a08c13b479aa..d565d2540670b 100644 --- a/src/librustc_mir/transform/uninhabited_enum_branching.rs +++ b/src/librustc_mir/transform/uninhabited_enum_branching.rs @@ -2,7 +2,7 @@ use crate::transform::{MirPass, MirSource}; use rustc_middle::mir::{ - BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Operand, Rvalue, StatementKind, + BasicBlock, BasicBlockData, Body, BodyAndCache, Local, Op, Operand, StatementKind, TerminatorKind, }; use rustc_middle::ty::layout::TyAndLayout; @@ -32,8 +32,7 @@ fn get_switched_on_type<'tcx>( let stmt_before_term = (!block_data.statements.is_empty()) .then(|| &block_data.statements[block_data.statements.len() - 1].kind); - if let Some(StatementKind::Assign(box (l, Rvalue::Discriminant(place)))) = stmt_before_term - { + if let Some(StatementKind::Assign(box (l, Op::Discriminant(place)))) = stmt_before_term { if l.as_local() == Some(local) { if let Some(r_local) = place.as_local() { let ty = body.local_decls[r_local].ty; diff --git a/src/librustc_mir/util/aggregate.rs b/src/librustc_mir/util/aggregate.rs index e77d264b7ce5c..ccd0608e16542 100644 --- a/src/librustc_mir/util/aggregate.rs +++ b/src/librustc_mir/util/aggregate.rs @@ -5,7 +5,7 @@ use rustc_target::abi::VariantIdx; use std::iter::TrustedLen; -/// Expand `lhs = Rvalue::Aggregate(kind, operands)` into assignments to the fields. +/// Expand `lhs = Op::Aggregate(kind, operands)` into assignments to the fields. /// /// Produces something like /// @@ -68,7 +68,7 @@ pub fn expand_aggregate<'tcx>( let field = Field::new(active_field_index.unwrap_or(i)); tcx.mk_place_field(lhs.clone(), field, ty) }; - Statement { source_info, kind: StatementKind::Assign(box (lhs_field, Rvalue::Use(op))) } + Statement { source_info, kind: StatementKind::Assign(box (lhs_field, Op::Use(op))) } }) .chain(set_discriminant) } diff --git a/src/librustc_mir/util/elaborate_drops.rs b/src/librustc_mir/util/elaborate_drops.rs index e3a96ca78967e..6405152696fcf 100644 --- a/src/librustc_mir/util/elaborate_drops.rs +++ b/src/librustc_mir/util/elaborate_drops.rs @@ -524,7 +524,7 @@ where // way lies only trouble. let discr_ty = adt.repr.discr_type().to_ty(self.tcx()); let discr = Place::from(self.new_temp(discr_ty)); - let discr_rv = Rvalue::Discriminant(self.place); + let discr_rv = Op::Discriminant(self.place); let switch_block = BasicBlockData { statements: vec![self.assign(discr, discr_rv)], terminator: Some(Terminator { @@ -558,7 +558,7 @@ where let result = BasicBlockData { statements: vec![self.assign( Place::from(ref_place), - Rvalue::Ref( + Op::Ref( tcx.lifetimes.re_erased, BorrowKind::Mut { allow_two_phase_borrow: false }, self.place, @@ -619,11 +619,11 @@ where let one = self.constant_usize(1); let (ptr_next, cur_next) = if ptr_based { - (Rvalue::Use(copy(cur.into())), Rvalue::BinaryOp(BinOp::Offset, move_(cur.into()), one)) + (Op::Use(copy(cur.into())), Op::BinaryOp(BinOp::Offset, move_(cur.into()), one)) } else { ( - Rvalue::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place.clone(), cur)), - Rvalue::BinaryOp(BinOp::Add, move_(cur.into()), one), + Op::AddressOf(Mutability::Mut, tcx.mk_place_index(self.place.clone(), cur)), + Op::BinaryOp(BinOp::Add, move_(cur.into()), one), ) }; @@ -641,7 +641,7 @@ where let loop_block = BasicBlockData { statements: vec![self.assign( can_go, - Rvalue::BinaryOp(BinOp::Eq, copy(Place::from(cur)), copy(length_or_end)), + Op::BinaryOp(BinOp::Eq, copy(Place::from(cur)), copy(length_or_end)), )], is_cleanup: unwind.is_cleanup(), terminator: Some(Terminator { @@ -708,8 +708,8 @@ where let base_block = BasicBlockData { statements: vec![ - self.assign(elem_size, Rvalue::NullaryOp(NullOp::SizeOf, ety)), - self.assign(len, Rvalue::Len(self.place)), + self.assign(elem_size, Op::NullaryOp(NullOp::SizeOf, ety)), + self.assign(len, Op::Len(self.place)), ], is_cleanup: self.unwind.is_cleanup(), terminator: Some(Terminator { @@ -758,17 +758,17 @@ where // cur = tmp as *mut T; // end = Offset(cur, len); vec![ - self.assign(tmp, Rvalue::AddressOf(Mutability::Mut, self.place)), - self.assign(cur, Rvalue::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)), + self.assign(tmp, Op::AddressOf(Mutability::Mut, self.place)), + self.assign(cur, Op::Cast(CastKind::Misc, Operand::Move(tmp), iter_ty)), self.assign( length_or_end, - Rvalue::BinaryOp(BinOp::Offset, Operand::Copy(cur), Operand::Move(length)), + Op::BinaryOp(BinOp::Offset, Operand::Copy(cur), Operand::Move(length)), ), ] } else { // cur = 0 (length already pushed) let zero = self.constant_usize(0); - vec![self.assign(cur, Rvalue::Use(zero))] + vec![self.assign(cur, Op::Use(zero))] }; let drop_block = self.elaborator.patch().new_block(BasicBlockData { statements: drop_block_stmts, @@ -989,7 +989,7 @@ where }) } - fn assign(&self, lhs: Place<'tcx>, rhs: Rvalue<'tcx>) -> Statement<'tcx> { + fn assign(&self, lhs: Place<'tcx>, rhs: Op<'tcx>) -> Statement<'tcx> { Statement { source_info: self.source_info, kind: StatementKind::Assign(box (lhs, rhs)) } } } diff --git a/src/librustc_mir/util/patch.rs b/src/librustc_mir/util/patch.rs index 46f42f4db05fd..89d39b2bacf04 100644 --- a/src/librustc_mir/util/patch.rs +++ b/src/librustc_mir/util/patch.rs @@ -113,7 +113,7 @@ impl<'tcx> MirPatch<'tcx> { self.new_statements.push((loc, stmt)); } - pub fn add_assign(&mut self, loc: Location, place: Place<'tcx>, rv: Rvalue<'tcx>) { + pub fn add_assign(&mut self, loc: Location, place: Place<'tcx>, rv: Op<'tcx>) { self.add_statement(loc, StatementKind::Assign(box (place, rv))); } diff --git a/src/librustc_mir/util/pretty.rs b/src/librustc_mir/util/pretty.rs index 64221c41bffe4..6fd078fdda843 100644 --- a/src/librustc_mir/util/pretty.rs +++ b/src/librustc_mir/util/pretty.rs @@ -390,9 +390,9 @@ impl Visitor<'tcx> for ExtraComments<'tcx> { self.push(&format!("+ val: {:?}", val)); } - fn visit_rvalue(&mut self, rvalue: &Rvalue<'tcx>, location: Location) { + fn visit_rvalue(&mut self, rvalue: &Op<'tcx>, location: Location) { self.super_rvalue(rvalue, location); - if let Rvalue::Aggregate(kind, _) = rvalue { + if let Op::Aggregate(kind, _) = rvalue { match **kind { AggregateKind::Closure(def_id, substs) => { self.push("closure"); diff --git a/src/librustc_mir_build/build/cfg.rs b/src/librustc_mir_build/build/cfg.rs index f5828c4ac1fa1..1603ce03f120a 100644 --- a/src/librustc_mir_build/build/cfg.rs +++ b/src/librustc_mir_build/build/cfg.rs @@ -35,7 +35,7 @@ impl<'tcx> CFG<'tcx> { block: BasicBlock, source_info: SourceInfo, place: Place<'tcx>, - rvalue: Rvalue<'tcx>, + rvalue: Op<'tcx>, ) { self.push( block, @@ -50,7 +50,7 @@ impl<'tcx> CFG<'tcx> { temp: Place<'tcx>, constant: Constant<'tcx>, ) { - self.push_assign(block, source_info, temp, Rvalue::Use(Operand::Constant(box constant))); + self.push_assign(block, source_info, temp, Op::Use(Operand::Constant(box constant))); } crate fn push_assign_unit( @@ -63,7 +63,7 @@ impl<'tcx> CFG<'tcx> { block, source_info, place, - Rvalue::Aggregate(box AggregateKind::Tuple, vec![]), + Op::Aggregate(box AggregateKind::Tuple, vec![]), ); } diff --git a/src/librustc_mir_build/build/expr/as_operand.rs b/src/librustc_mir_build/build/expr/as_operand.rs index 783637fa45831..473f3d82f1d4e 100644 --- a/src/librustc_mir_build/build/expr/as_operand.rs +++ b/src/librustc_mir_build/build/expr/as_operand.rs @@ -63,7 +63,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let constant = this.as_constant(expr); block.and(Operand::Constant(box constant)) } - Category::Place | Category::Rvalue(..) => { + Category::Place | Category::Op(..) => { let operand = unpack!(block = this.as_temp(block, scope, expr, Mutability::Mut)); block.and(Operand::Move(Place::from(operand))) } diff --git a/src/librustc_mir_build/build/expr/as_place.rs b/src/librustc_mir_build/build/expr/as_place.rs index 9f74385b3368b..78dede3000793 100644 --- a/src/librustc_mir_build/build/expr/as_place.rs +++ b/src/librustc_mir_build/build/expr/as_place.rs @@ -341,13 +341,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let lt = self.temp(bool_ty, expr_span); // len = len(slice) - self.cfg.push_assign(block, source_info, len, Rvalue::Len(slice)); + self.cfg.push_assign(block, source_info, len, Op::Len(slice)); // lt = idx < len self.cfg.push_assign( block, source_info, lt, - Rvalue::BinaryOp(BinOp::Lt, Operand::Copy(Place::from(index)), Operand::Copy(len)), + Op::BinaryOp(BinOp::Lt, Operand::Copy(Place::from(index)), Operand::Copy(len)), ); let msg = BoundsCheck { len: Operand::Move(len), index: Operand::Copy(Place::from(index)) }; // assert!(lt, "...") @@ -389,7 +389,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, fake_borrow_temp.into(), - Rvalue::Ref( + Op::Ref( tcx.lifetimes.re_erased, BorrowKind::Shallow, Place { local: base_place.local, projection }, diff --git a/src/librustc_mir_build/build/expr/as_rvalue.rs b/src/librustc_mir_build/build/expr/as_rvalue.rs index 20ef763e90cb4..b6bed9c0ec39a 100644 --- a/src/librustc_mir_build/build/expr/as_rvalue.rs +++ b/src/librustc_mir_build/build/expr/as_rvalue.rs @@ -18,7 +18,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { /// The operand returned from this function will *not be valid* after /// an ExprKind::Scope is passed, so please do *not* return it from /// functions to avoid bad miscompiles. - crate fn as_local_rvalue(&mut self, block: BasicBlock, expr: M) -> BlockAnd> + crate fn as_local_rvalue(&mut self, block: BasicBlock, expr: M) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>>, { @@ -32,7 +32,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block: BasicBlock, scope: Option, expr: M, - ) -> BlockAnd> + ) -> BlockAnd> where M: Mirror<'tcx, Output = Expr<'tcx>>, { @@ -45,7 +45,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { mut block: BasicBlock, scope: Option, expr: Expr<'tcx>, - ) -> BlockAnd> { + ) -> BlockAnd> { debug!("expr_as_rvalue(block={:?}, scope={:?}, expr={:?})", block, scope, expr); let this = self; @@ -59,7 +59,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } ExprKind::Repeat { value, count } => { let value_operand = unpack!(block = this.as_operand(block, scope, value)); - block.and(Rvalue::Repeat(value_operand, count)) + block.and(Op::Repeat(value_operand, count)) } ExprKind::Binary { op, lhs, rhs } => { let lhs = unpack!(block = this.as_operand(block, scope, lhs)); @@ -79,7 +79,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, is_min, - Rvalue::BinaryOp(BinOp::Eq, arg.to_copy(), minval), + Op::BinaryOp(BinOp::Eq, arg.to_copy(), minval), ); block = this.assert( @@ -90,7 +90,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { expr_span, ); } - block.and(Rvalue::UnaryOp(op, arg)) + block.and(Op::UnaryOp(op, arg)) } ExprKind::Box { value } => { let value = this.hir.mirror(value); @@ -108,7 +108,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } // malloc some memory of suitable type (thus far, uninitialized): - let box_ = Rvalue::NullaryOp(NullOp::Box, value.ty); + let box_ = Op::NullaryOp(NullOp::Box, value.ty); this.cfg.push_assign(block, source_info, Place::from(result), box_); // initialize the box contents: @@ -116,15 +116,15 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block = this.into(this.hir.tcx().mk_place_deref(Place::from(result)), block, value) ); - block.and(Rvalue::Use(Operand::Move(Place::from(result)))) + block.and(Op::Use(Operand::Move(Place::from(result)))) } ExprKind::Cast { source } => { let source = unpack!(block = this.as_operand(block, scope, source)); - block.and(Rvalue::Cast(CastKind::Misc, source, expr.ty)) + block.and(Op::Cast(CastKind::Misc, source, expr.ty)) } ExprKind::Pointer { cast, source } => { let source = unpack!(block = this.as_operand(block, scope, source)); - block.and(Rvalue::Cast(CastKind::Pointer(cast), source, expr.ty)) + block.and(Op::Cast(CastKind::Pointer(cast), source, expr.ty)) } ExprKind::Array { fields } => { // (*) We would (maybe) be closer to codegen if we @@ -134,7 +134,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { // // let tmp1 = ...1; // let tmp2 = ...2; - // dest = Rvalue::Aggregate(Foo, [tmp1, tmp2]) + // dest = Op::Aggregate(Foo, [tmp1, tmp2]) // // we could just generate // @@ -160,7 +160,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|f| unpack!(block = this.as_operand(block, scope, f))) .collect(); - block.and(Rvalue::Aggregate(box AggregateKind::Array(el_ty), fields)) + block.and(Op::Aggregate(box AggregateKind::Array(el_ty), fields)) } ExprKind::Tuple { fields } => { // see (*) above @@ -170,7 +170,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { .map(|f| unpack!(block = this.as_operand(block, scope, f))) .collect(); - block.and(Rvalue::Aggregate(box AggregateKind::Tuple, fields)) + block.and(Op::Aggregate(box AggregateKind::Tuple, fields)) } ExprKind::Closure { closure_id, substs, upvars, movability } => { // see (*) above @@ -221,7 +221,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } UpvarSubsts::Closure(substs) => box AggregateKind::Closure(closure_id, substs), }; - block.and(Rvalue::Aggregate(result, operands)) + block.and(Op::Aggregate(result, operands)) } ExprKind::Assign { .. } | ExprKind::AssignOp { .. } => { block = unpack!(this.stmt_expr(block, expr, None)); @@ -251,14 +251,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::LlvmInlineAsm { .. } | ExprKind::PlaceTypeAscription { .. } | ExprKind::ValueTypeAscription { .. } => { - // these do not have corresponding `Rvalue` variants, + // these do not have corresponding `Op` variants, // so make an operand and then return that debug_assert!(match Category::of(&expr.kind) { - Some(Category::Rvalue(RvalueFunc::AsRvalue)) => false, + Some(Category::Op(RvalueFunc::AsRvalue)) => false, _ => true, }); let operand = unpack!(block = this.as_operand(block, scope, expr)); - block.and(Rvalue::Use(operand)) + block.and(Op::Use(operand)) } } } @@ -271,7 +271,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ty: Ty<'tcx>, lhs: Operand<'tcx>, rhs: Operand<'tcx>, - ) -> BlockAnd> { + ) -> BlockAnd> { let source_info = self.source_info(span); let bool_ty = self.hir.bool_ty(); if self.hir.check_overflow() && op.is_checkable() && ty.is_integral() { @@ -282,7 +282,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, result_value, - Rvalue::CheckedBinaryOp(op, lhs, rhs), + Op::CheckedBinaryOp(op, lhs, rhs), ); let val_fld = Field::new(0); let of_fld = Field::new(1); @@ -295,7 +295,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block = self.assert(block, Operand::Move(of), false, err, span); - block.and(Rvalue::Use(Operand::Move(val))) + block.and(Op::Use(Operand::Move(val))) } else { if ty.is_integral() && (op == BinOp::Div || op == BinOp::Rem) { // Checking division and remainder is more complex, since we 1. always check @@ -315,7 +315,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, is_zero, - Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), zero), + Op::BinaryOp(BinOp::Eq, rhs.to_copy(), zero), ); block = self.assert(block, Operand::Move(is_zero), false, zero_err, span); @@ -336,13 +336,13 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, is_neg_1, - Rvalue::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1), + Op::BinaryOp(BinOp::Eq, rhs.to_copy(), neg_1), ); self.cfg.push_assign( block, source_info, is_min, - Rvalue::BinaryOp(BinOp::Eq, lhs.to_copy(), min), + Op::BinaryOp(BinOp::Eq, lhs.to_copy(), min), ); let is_neg_1 = Operand::Move(is_neg_1); @@ -351,14 +351,14 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, of, - Rvalue::BinaryOp(BinOp::BitAnd, is_neg_1, is_min), + Op::BinaryOp(BinOp::BitAnd, is_neg_1, is_min), ); block = self.assert(block, Operand::Move(of), false, overflow_err, span); } } - block.and(Rvalue::BinaryOp(op, lhs, rhs)) + block.and(Op::BinaryOp(op, lhs, rhs)) } } @@ -426,7 +426,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, Place::from(temp), - Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place), + Op::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place), ); // In constants, temp_lifetime is None. We should not need to drop diff --git a/src/librustc_mir_build/build/expr/category.rs b/src/librustc_mir_build/build/expr/category.rs index f8cae205453c3..f5b819d200425 100644 --- a/src/librustc_mir_build/build/expr/category.rs +++ b/src/librustc_mir_build/build/expr/category.rs @@ -13,7 +13,7 @@ crate enum Category { // Something that generates a new value at runtime, like `x + y` // or `foo()`. - Rvalue(RvalueFunc), + Op(RvalueFunc), } // Rvalues fall into different "styles" that will determine which fn @@ -51,7 +51,7 @@ impl Category { | ExprKind::Borrow { .. } | ExprKind::AddressOf { .. } | ExprKind::Yield { .. } - | ExprKind::Call { .. } => Some(Category::Rvalue(RvalueFunc::Into)), + | ExprKind::Call { .. } => Some(Category::Op(RvalueFunc::Into)), ExprKind::Array { .. } | ExprKind::Tuple { .. } @@ -64,7 +64,7 @@ impl Category { | ExprKind::Repeat { .. } | ExprKind::Assign { .. } | ExprKind::AssignOp { .. } - | ExprKind::LlvmInlineAsm { .. } => Some(Category::Rvalue(RvalueFunc::AsRvalue)), + | ExprKind::LlvmInlineAsm { .. } => Some(Category::Op(RvalueFunc::AsRvalue)), ExprKind::Literal { .. } | ExprKind::StaticRef { .. } => Some(Category::Constant), @@ -76,7 +76,7 @@ impl Category { // FIXME(#27840) these probably want their own // category, like "nonterminating" { - Some(Category::Rvalue(RvalueFunc::Into)) + Some(Category::Op(RvalueFunc::Into)) } } } diff --git a/src/librustc_mir_build/build/expr/into.rs b/src/librustc_mir_build/build/expr/into.rs index 6b93755e9da7c..b79e8cdc366b6 100644 --- a/src/librustc_mir_build/build/expr/into.rs +++ b/src/librustc_mir_build/build/expr/into.rs @@ -3,10 +3,10 @@ use crate::build::expr::category::{Category, RvalueFunc}; use crate::build::{BlockAnd, BlockAndExtension, BlockFrame, Builder}; use crate::hair::*; -use rustc_middle::mir::*; -use rustc_middle::ty::{self, CanonicalUserTypeAnnotation}; use rustc_data_structures::fx::FxHashMap; use rustc_hir as hir; +use rustc_middle::mir::*; +use rustc_middle::ty::{self, CanonicalUserTypeAnnotation}; use rustc_span::symbol::sym; use rustc_target::spec::abi::Abi; @@ -247,8 +247,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { BorrowKind::Shared => unpack!(block = this.as_read_only_place(block, arg)), _ => unpack!(block = this.as_place(block, arg)), }; - let borrow = - Rvalue::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place); + let borrow = Op::Ref(this.hir.tcx().lifetimes.re_erased, borrow_kind, arg_place); this.cfg.push_assign(block, source_info, destination, borrow); block.unit() } @@ -257,7 +256,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { hir::Mutability::Not => this.as_read_only_place(block, arg), hir::Mutability::Mut => this.as_place(block, arg), }; - let address_of = Rvalue::AddressOf(mutability, unpack!(block = place)); + let address_of = Op::AddressOf(mutability, unpack!(block = place)); this.cfg.push_assign(block, source_info, destination, address_of); block.unit() } @@ -314,12 +313,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { user_ty, active_field_index, ); - this.cfg.push_assign( - block, - source_info, - destination, - Rvalue::Aggregate(adt, fields), - ); + this.cfg.push_assign(block, source_info, destination, Op::Aggregate(adt, fields)); block.unit() } @@ -343,7 +337,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); let place = unpack!(block = this.as_place(block, expr)); - let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place)); + let rvalue = Op::Use(this.consume_by_copy_or_move(place)); this.cfg.push_assign(block, source_info, destination, rvalue); block.unit() } @@ -360,7 +354,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { debug_assert!(Category::of(&expr.kind) == Some(Category::Place)); let place = unpack!(block = this.as_place(block, expr)); - let rvalue = Rvalue::Use(this.consume_by_copy_or_move(place)); + let rvalue = Op::Use(this.consume_by_copy_or_move(place)); this.cfg.push_assign(block, source_info, destination, rvalue); block.unit() } @@ -392,7 +386,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { | ExprKind::StaticRef { .. } => { debug_assert!(match Category::of(&expr.kind).unwrap() { // should be handled above - Category::Rvalue(RvalueFunc::Into) => false, + Category::Op(RvalueFunc::Into) => false, // must be handled above or else we get an // infinite loop in the builder; see diff --git a/src/librustc_mir_build/build/expr/mod.rs b/src/librustc_mir_build/build/expr/mod.rs index ac8c7e725e1b4..5f7b4d0f13075 100644 --- a/src/librustc_mir_build/build/expr/mod.rs +++ b/src/librustc_mir_build/build/expr/mod.rs @@ -12,10 +12,10 @@ //! - `into` -- writes the value into a specific location, which //! should be uninitialized //! - `as_operand` -- evaluates the value and yields an `Operand`, -//! suitable for use as an argument to an `Rvalue` +//! suitable for use as an argument to an `Op` //! - `as_temp` -- evaluates into a temporary; this is similar to `as_operand` //! except it always returns a fresh place, even for constants -//! - `as_rvalue` -- yields an `Rvalue`, suitable for use in an assignment; +//! - `as_rvalue` -- yields an `Op`, suitable for use in an assignment; //! as of this writing, never needed outside of the `expr` module itself //! //! Sometimes though want the expression's *location*. An example @@ -45,7 +45,7 @@ //! other fns cycle around. The handoff works like this: //! //! - `into(place)` -> fallback is to create a rvalue with `as_rvalue` and assign it to `place` -//! - `as_rvalue` -> fallback is to create an Operand with `as_operand` and use `Rvalue::use` +//! - `as_rvalue` -> fallback is to create an Operand with `as_operand` and use `Op::use` //! - `as_operand` -> either invokes `as_constant` or `as_temp` //! - `as_constant` -> (no fallback) //! - `as_temp` -> creates a temporary and either calls `as_place` or `into` diff --git a/src/librustc_mir_build/build/matches/mod.rs b/src/librustc_mir_build/build/matches/mod.rs index a4a9271669e4e..fc7b20627ae5b 100644 --- a/src/librustc_mir_build/build/matches/mod.rs +++ b/src/librustc_mir_build/build/matches/mod.rs @@ -1690,7 +1690,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let re_erased = tcx.lifetimes.re_erased; let scrutinee_source_info = self.source_info(scrutinee_span); for &(place, temp) in fake_borrows { - let borrow = Rvalue::Ref(re_erased, BorrowKind::Shallow, place); + let borrow = Op::Ref(re_erased, BorrowKind::Shallow, place); self.cfg.push_assign(block, scrutinee_source_info, Place::from(temp), borrow); } @@ -1857,7 +1857,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); match binding.binding_mode { BindingMode::ByValue => { - let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, binding.source); + let rvalue = Op::Ref(re_erased, BorrowKind::Shared, binding.source); self.cfg.push_assign(block, source_info, ref_for_guard, rvalue); } BindingMode::ByRef(borrow_kind) => { @@ -1869,9 +1869,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { schedule_drops, ); - let rvalue = Rvalue::Ref(re_erased, borrow_kind, binding.source); + let rvalue = Op::Ref(re_erased, borrow_kind, binding.source); self.cfg.push_assign(block, source_info, value_for_arm, rvalue); - let rvalue = Rvalue::Ref(re_erased, BorrowKind::Shared, value_for_arm); + let rvalue = Op::Ref(re_erased, BorrowKind::Shared, value_for_arm); self.cfg.push_assign(block, source_info, ref_for_guard, rvalue); } } @@ -1904,11 +1904,9 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { } let rvalue = match binding.binding_mode { BindingMode::ByValue => { - Rvalue::Use(self.consume_by_copy_or_move(binding.source.clone())) - } - BindingMode::ByRef(borrow_kind) => { - Rvalue::Ref(re_erased, borrow_kind, binding.source) + Op::Use(self.consume_by_copy_or_move(binding.source.clone())) } + BindingMode::ByRef(borrow_kind) => Op::Ref(re_erased, borrow_kind, binding.source), }; self.cfg.push_assign(block, source_info, local, rvalue); } diff --git a/src/librustc_mir_build/build/matches/test.rs b/src/librustc_mir_build/build/matches/test.rs index c049842d061bf..63102f6808623 100644 --- a/src/librustc_mir_build/build/matches/test.rs +++ b/src/librustc_mir_build/build/matches/test.rs @@ -202,7 +202,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { ); let discr_ty = adt_def.repr.discr_type().to_ty(tcx); let discr = self.temp(discr_ty, test.span); - self.cfg.push_assign(block, source_info, discr, Rvalue::Discriminant(place)); + self.cfg.push_assign(block, source_info, discr, Op::Discriminant(place)); assert_eq!(values.len() + 1, targets.len()); self.cfg.terminate( block, @@ -303,7 +303,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let actual = self.temp(usize_ty, test.span); // actual = len(place) - self.cfg.push_assign(block, source_info, actual, Rvalue::Len(place)); + self.cfg.push_assign(block, source_info, actual, Op::Len(place)); // expected = let expected = self.push_usize(block, source_info, len); @@ -342,7 +342,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { let result = self.temp(bool_ty, source_info.span); // result = op(left, right) - self.cfg.push_assign(block, source_info, result, Rvalue::BinaryOp(op, left, right)); + self.cfg.push_assign(block, source_info, result, Op::BinaryOp(op, left, right)); // branch based on result self.cfg.terminate( @@ -395,7 +395,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, temp, - Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), val, ty), + Op::Cast(CastKind::Pointer(PointerCast::Unsize), val, ty), ); val = Operand::Move(temp); } @@ -405,7 +405,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { block, source_info, slice, - Rvalue::Cast(CastKind::Pointer(PointerCast::Unsize), expect, ty), + Op::Cast(CastKind::Pointer(PointerCast::Unsize), expect, ty), ); expect = Operand::Move(slice); } diff --git a/src/librustc_mir_build/build/misc.rs b/src/librustc_mir_build/build/misc.rs index 8f98dd9b70e80..b93d012c9a99f 100644 --- a/src/librustc_mir_build/build/misc.rs +++ b/src/librustc_mir_build/build/misc.rs @@ -32,8 +32,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> { Operand::Constant(constant) } - crate fn unit_rvalue(&mut self) -> Rvalue<'tcx> { - Rvalue::Aggregate(box AggregateKind::Tuple, vec![]) + crate fn unit_rvalue(&mut self) -> Op<'tcx> { + Op::Aggregate(box AggregateKind::Tuple, vec![]) } // Returns a zero literal operand for the appropriate type, works for