diff --git a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs index 44eae706ea8f6df56448214f8afab5383bc67ade..2144e7ed67acbc75a7e4ca0c3781e27148f5294c 100644 --- a/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs +++ b/compiler/rustc_codegen_cranelift/src/abi/pass_mode.rs @@ -92,9 +92,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn get_abi_param(&self, tcx: TyCtxt<'tcx>) -> SmallVec<[AbiParam; 2]> { match self.mode { PassMode::Ignore => smallvec![], - PassMode::Direct(attrs) => match &self.layout.abi { + PassMode::Direct(attrs) => match self.layout.abi { Abi::Scalar(scalar) => smallvec![apply_arg_attrs_to_abi_param( - AbiParam::new(scalar_to_clif_type(tcx, scalar.clone())), + AbiParam::new(scalar_to_clif_type(tcx, scalar)), attrs )], Abi::Vector { .. } => { @@ -103,10 +103,10 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { } _ => unreachable!("{:?}", self.layout.abi), }, - PassMode::Pair(attrs_a, attrs_b) => match &self.layout.abi { + PassMode::Pair(attrs_a, attrs_b) => match self.layout.abi { Abi::ScalarPair(a, b) => { - let a = scalar_to_clif_type(tcx, a.clone()); - let b = scalar_to_clif_type(tcx, b.clone()); + let a = scalar_to_clif_type(tcx, a); + let b = scalar_to_clif_type(tcx, b); smallvec![ apply_arg_attrs_to_abi_param(AbiParam::new(a), attrs_a), apply_arg_attrs_to_abi_param(AbiParam::new(b), attrs_b), @@ -139,9 +139,9 @@ impl<'tcx> ArgAbiExt<'tcx> for ArgAbi<'tcx, Ty<'tcx>> { fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option, Vec) { match self.mode { PassMode::Ignore => (None, vec![]), - PassMode::Direct(_) => match &self.layout.abi { + PassMode::Direct(_) => match self.layout.abi { Abi::Scalar(scalar) => { - (None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar.clone()))]) + (None, vec![AbiParam::new(scalar_to_clif_type(tcx, scalar))]) } Abi::Vector { .. } => { let vector_ty = crate::intrinsics::clif_vector_type(tcx, self.layout).unwrap(); @@ -149,10 +149,10 @@ fn get_abi_return(&self, tcx: TyCtxt<'tcx>) -> (Option, Vec) } _ => unreachable!("{:?}", self.layout.abi), }, - PassMode::Pair(_, _) => match &self.layout.abi { + PassMode::Pair(_, _) => match self.layout.abi { Abi::ScalarPair(a, b) => { - let a = scalar_to_clif_type(tcx, a.clone()); - let b = scalar_to_clif_type(tcx, b.clone()); + let a = scalar_to_clif_type(tcx, a); + let b = scalar_to_clif_type(tcx, b); (None, vec![AbiParam::new(a), AbiParam::new(b)]) } _ => unreachable!("{:?}", self.layout.abi), diff --git a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs index 12f61e0c564aab39944b735e7d4f34057a8df842..8b62b44df8ab30a0be927472792cee36ced3a8a6 100644 --- a/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs +++ b/compiler/rustc_codegen_cranelift/src/intrinsics/mod.rs @@ -143,8 +143,8 @@ } pub(crate) fn clif_vector_type<'tcx>(tcx: TyCtxt<'tcx>, layout: TyAndLayout<'tcx>) -> Option { - let (element, count) = match &layout.abi { - Abi::Vector { element, count } => (element.clone(), *count), + let (element, count) = match layout.abi { + Abi::Vector { element, count } => (element, count), _ => unreachable!(), }; diff --git a/compiler/rustc_codegen_cranelift/src/value_and_place.rs b/compiler/rustc_codegen_cranelift/src/value_and_place.rs index 364b3da92b88822fe614904ce75ed44582d2a288..30d5340935f14d90ea4773316340420a2fa11334 100644 --- a/compiler/rustc_codegen_cranelift/src/value_and_place.rs +++ b/compiler/rustc_codegen_cranelift/src/value_and_place.rs @@ -49,11 +49,7 @@ fn codegen_field<'tcx>( } } -fn scalar_pair_calculate_b_offset( - tcx: TyCtxt<'_>, - a_scalar: &Scalar, - b_scalar: &Scalar, -) -> Offset32 { +fn scalar_pair_calculate_b_offset(tcx: TyCtxt<'_>, a_scalar: Scalar, b_scalar: Scalar) -> Offset32 { let b_offset = a_scalar.value.size(&tcx).align_to(b_scalar.value.align(&tcx).abi); Offset32::new(b_offset.bytes().try_into().unwrap()) } @@ -124,12 +120,10 @@ pub(crate) fn load_scalar(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> Value { match self.0 { CValueInner::ByRef(ptr, None) => { let clif_ty = match layout.abi { - Abi::Scalar(ref scalar) => scalar_to_clif_type(fx.tcx, scalar.clone()), - Abi::Vector { ref element, count } => { - scalar_to_clif_type(fx.tcx, element.clone()) - .by(u16::try_from(count).unwrap()) - .unwrap() - } + Abi::Scalar(scalar) => scalar_to_clif_type(fx.tcx, scalar), + Abi::Vector { element, count } => scalar_to_clif_type(fx.tcx, element) + .by(u16::try_from(count).unwrap()) + .unwrap(), _ => unreachable!("{:?}", layout.ty), }; let mut flags = MemFlags::new(); @@ -147,13 +141,13 @@ pub(crate) fn load_scalar_pair(self, fx: &mut FunctionCx<'_, '_, 'tcx>) -> (Valu let layout = self.1; match self.0 { CValueInner::ByRef(ptr, None) => { - let (a_scalar, b_scalar) = match &layout.abi { + let (a_scalar, b_scalar) = match layout.abi { Abi::ScalarPair(a, b) => (a, b), _ => unreachable!("load_scalar_pair({:?})", self), }; let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); - let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar.clone()); - let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar.clone()); + let clif_ty1 = scalar_to_clif_type(fx.tcx, a_scalar); + let clif_ty2 = scalar_to_clif_type(fx.tcx, b_scalar); let mut flags = MemFlags::new(); flags.set_notrap(); let val1 = ptr.load(fx, clif_ty1, flags); @@ -564,7 +558,7 @@ fn transmute_value<'tcx>( to_ptr.store(fx, val, flags); return; } - Abi::ScalarPair(ref a_scalar, ref b_scalar) => { + Abi::ScalarPair(a_scalar, b_scalar) => { let (value, extra) = from.load_scalar_pair(fx); let b_offset = scalar_pair_calculate_b_offset(fx.tcx, a_scalar, b_scalar); to_ptr.store(fx, value, flags); diff --git a/compiler/rustc_codegen_llvm/src/abi.rs b/compiler/rustc_codegen_llvm/src/abi.rs index cf21c2bb6e14cbb0df2afb9107d7de2500755d26..785f9b09ff3d3e469d2ed2f5ec9cb499465fd2a5 100644 --- a/compiler/rustc_codegen_llvm/src/abi.rs +++ b/compiler/rustc_codegen_llvm/src/abi.rs @@ -536,13 +536,13 @@ fn apply_attrs_callsite(&self, bx: &mut Builder<'a, 'll, 'tcx>, callsite: &'ll V } _ => {} } - if let abi::Abi::Scalar(ref scalar) = self.ret.layout.abi { + if let abi::Abi::Scalar(scalar) = self.ret.layout.abi { // If the value is a boolean, the range is 0..2 and that ultimately // become 0..0 when the type becomes i1, which would be rejected // by the LLVM verifier. if let Int(..) = scalar.value { if !scalar.is_bool() && !scalar.is_always_valid_for(bx) { - bx.range_metadata(callsite, &scalar.valid_range); + bx.range_metadata(callsite, scalar.valid_range); } } } diff --git a/compiler/rustc_codegen_llvm/src/asm.rs b/compiler/rustc_codegen_llvm/src/asm.rs index e0d312727a57df3b48807229b5d66030238e9a37..9690ad8b24603a17490099c9218d7d414f49dee3 100644 --- a/compiler/rustc_codegen_llvm/src/asm.rs +++ b/compiler/rustc_codegen_llvm/src/asm.rs @@ -792,7 +792,7 @@ fn dummy_output_type(cx: &CodegenCx<'ll, 'tcx>, reg: InlineAsmRegClass) -> &'ll /// Helper function to get the LLVM type for a Scalar. Pointers are returned as /// the equivalent integer type. -fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: &Scalar) -> &'ll Type { +fn llvm_asm_scalar_type(cx: &CodegenCx<'ll, 'tcx>, scalar: Scalar) -> &'ll Type { match scalar.value { Primitive::Int(Integer::I8, _) => cx.type_i8(), Primitive::Int(Integer::I16, _) => cx.type_i16(), @@ -812,7 +812,7 @@ fn llvm_fixup_input( reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, ) -> &'ll Value { - match (reg, &layout.abi) { + match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { if let Primitive::Int(Integer::I8, _) = s.value { let vec_ty = bx.cx.type_vector(bx.cx.type_i8(), 8); @@ -835,7 +835,7 @@ fn llvm_fixup_input( Abi::Vector { element, count }, ) if layout.size.bytes() == 8 => { let elem_ty = llvm_asm_scalar_type(bx.cx, element); - let vec_ty = bx.cx.type_vector(elem_ty, *count); + let vec_ty = bx.cx.type_vector(elem_ty, count); let indices: Vec<_> = (0..count * 2).map(|x| bx.const_i32(x as i32)).collect(); bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices)) } @@ -890,7 +890,7 @@ fn llvm_fixup_output( reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, ) -> &'ll Value { - match (reg, &layout.abi) { + match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { if let Primitive::Int(Integer::I8, _) = s.value { bx.extract_element(value, bx.const_i32(0)) @@ -910,8 +910,8 @@ fn llvm_fixup_output( Abi::Vector { element, count }, ) if layout.size.bytes() == 8 => { let elem_ty = llvm_asm_scalar_type(bx.cx, element); - let vec_ty = bx.cx.type_vector(elem_ty, *count * 2); - let indices: Vec<_> = (0..*count).map(|x| bx.const_i32(x as i32)).collect(); + let vec_ty = bx.cx.type_vector(elem_ty, count * 2); + let indices: Vec<_> = (0..count).map(|x| bx.const_i32(x as i32)).collect(); bx.shuffle_vector(value, bx.const_undef(vec_ty), bx.const_vector(&indices)) } (InlineAsmRegClass::X86(X86InlineAsmRegClass::reg_abcd), Abi::Scalar(s)) @@ -965,7 +965,7 @@ fn llvm_fixup_output_type( reg: InlineAsmRegClass, layout: &TyAndLayout<'tcx>, ) -> &'ll Type { - match (reg, &layout.abi) { + match (reg, layout.abi) { (InlineAsmRegClass::AArch64(AArch64InlineAsmRegClass::vreg), Abi::Scalar(s)) => { if let Primitive::Int(Integer::I8, _) = s.value { cx.type_vector(cx.type_i8(), 8) diff --git a/compiler/rustc_codegen_llvm/src/builder.rs b/compiler/rustc_codegen_llvm/src/builder.rs index c7b1a805223bfdf37a8a614a3139a6bfad401150..8fddefa163b4c736902dccad92cd1b55a8b062db 100644 --- a/compiler/rustc_codegen_llvm/src/builder.rs +++ b/compiler/rustc_codegen_llvm/src/builder.rs @@ -382,7 +382,7 @@ fn from_immediate(&mut self, val: Self::Value) -> Self::Value { val } } - fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &abi::Scalar) -> Self::Value { + fn to_immediate_scalar(&mut self, val: Self::Value, scalar: abi::Scalar) -> Self::Value { if scalar.is_bool() { return self.trunc(val, self.cx().type_i1()); } @@ -460,12 +460,12 @@ fn load_operand(&mut self, place: PlaceRef<'tcx, &'ll Value>) -> OperandRef<'tcx fn scalar_load_metadata<'a, 'll, 'tcx>( bx: &mut Builder<'a, 'll, 'tcx>, load: &'ll Value, - scalar: &abi::Scalar, + scalar: abi::Scalar, ) { match scalar.value { abi::Int(..) => { if !scalar.is_always_valid_for(bx) { - bx.range_metadata(load, &scalar.valid_range); + bx.range_metadata(load, scalar.valid_range); } } abi::Pointer if !scalar.valid_range.contains(0) => { @@ -488,17 +488,17 @@ fn scalar_load_metadata<'a, 'll, 'tcx>( } let llval = const_llval.unwrap_or_else(|| { let load = self.load(place.layout.llvm_type(self), place.llval, place.align); - if let abi::Abi::Scalar(ref scalar) = place.layout.abi { + if let abi::Abi::Scalar(scalar) = place.layout.abi { scalar_load_metadata(self, load, scalar); } load }); OperandValue::Immediate(self.to_immediate(llval, place.layout)) - } else if let abi::Abi::ScalarPair(ref a, ref b) = place.layout.abi { + } else if let abi::Abi::ScalarPair(a, b) = place.layout.abi { let b_offset = a.value.size(self).align_to(b.value.align(self).abi); let pair_ty = place.layout.llvm_type(self); - let mut load = |i, scalar: &abi::Scalar, align| { + let mut load = |i, scalar: abi::Scalar, align| { let llptr = self.struct_gep(pair_ty, place.llval, i as u64); let llty = place.layout.scalar_pair_element_llvm_type(self, i, false); let load = self.load(llty, llptr, align); @@ -554,7 +554,7 @@ fn write_operand_repeatedly( next_bx } - fn range_metadata(&mut self, load: &'ll Value, range: &WrappingRange) { + fn range_metadata(&mut self, load: &'ll Value, range: WrappingRange) { if self.sess().target.arch == "amdgpu" { // amdgpu/LLVM does something weird and thinks an i64 value is // split into a v2i32, halving the bitwidth LLVM expects, diff --git a/compiler/rustc_codegen_llvm/src/common.rs b/compiler/rustc_codegen_llvm/src/common.rs index cee582aec95ebf077b818093c990d77044451c07..73a8d4644316346c3347da6ed857777521f089c1 100644 --- a/compiler/rustc_codegen_llvm/src/common.rs +++ b/compiler/rustc_codegen_llvm/src/common.rs @@ -228,7 +228,7 @@ fn const_to_opt_u128(&self, v: &'ll Value, sign_ext: bool) -> Option { }) } - fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: &'ll Type) -> &'ll Value { + fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: &'ll Type) -> &'ll Value { let bitsize = if layout.is_bool() { 1 } else { layout.value.size(self).bits() }; match cv { Scalar::Int(ScalarInt::ZST) => { diff --git a/compiler/rustc_codegen_llvm/src/consts.rs b/compiler/rustc_codegen_llvm/src/consts.rs index e673b06f1552795b6b65ec64abf335a9ba20ded7..ef3a90fdecaaa7874479e8659119ba69416e7050 100644 --- a/compiler/rustc_codegen_llvm/src/consts.rs +++ b/compiler/rustc_codegen_llvm/src/consts.rs @@ -111,7 +111,7 @@ fn append_chunks_of_init_and_uninit_bytes<'ll, 'a, 'b>( Pointer::new(alloc_id, Size::from_bytes(ptr_offset)), &cx.tcx, ), - &Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } }, + Scalar { value: Primitive::Pointer, valid_range: WrappingRange { start: 0, end: !0 } }, cx.type_i8p_ext(address_space), )); next_offset = offset + pointer_size; diff --git a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs index 9a6391443dd010a2c383ceaf3479eb477c02ad8b..f913c3e4b703d4bcc00306d595de20c372c1c188 100644 --- a/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs +++ b/compiler/rustc_codegen_llvm/src/debuginfo/metadata.rs @@ -1656,7 +1656,7 @@ fn create_member_descriptions(&self, cx: &CodegenCx<'ll, 'tcx>) -> Vec { @@ -2082,10 +2082,8 @@ fn prepare_enum_metadata( let layout = cx.layout_of(enum_type); - if let ( - &Abi::Scalar(_), - &Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, .. }, - ) = (&layout.abi, &layout.variants) + if let (Abi::Scalar(_), Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. }) = + (layout.abi, &layout.variants) { return FinalMetadata(discriminant_type_metadata(tag.value)); } @@ -2093,8 +2091,8 @@ fn prepare_enum_metadata( if use_enum_fallback(cx) { let discriminant_type_metadata = match layout.variants { Variants::Single { .. } => None, - Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, ref tag, .. } - | Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, .. } => { + Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, .. } + | Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, .. } => { Some(discriminant_type_metadata(tag.value)) } }; @@ -2146,9 +2144,7 @@ fn prepare_enum_metadata( // A single-variant enum has no discriminant. Variants::Single { .. } => None, - Variants::Multiple { - tag_encoding: TagEncoding::Niche { .. }, ref tag, tag_field, .. - } => { + Variants::Multiple { tag_encoding: TagEncoding::Niche { .. }, tag, tag_field, .. } => { // Find the integer type of the correct size. let size = tag.value.size(cx); let align = tag.value.align(cx); @@ -2179,7 +2175,7 @@ fn prepare_enum_metadata( } } - Variants::Multiple { tag_encoding: TagEncoding::Direct, ref tag, tag_field, .. } => { + Variants::Multiple { tag_encoding: TagEncoding::Direct, tag, tag_field, .. } => { let discr_type = tag.value.to_ty(cx.tcx); let (size, align) = cx.size_and_align_of(discr_type); diff --git a/compiler/rustc_codegen_llvm/src/intrinsic.rs b/compiler/rustc_codegen_llvm/src/intrinsic.rs index 1aa52d975e9a015854dedef358b1c9e67955661f..1060f911a9ed48739a9e4de5cff53559e0944b13 100644 --- a/compiler/rustc_codegen_llvm/src/intrinsic.rs +++ b/compiler/rustc_codegen_llvm/src/intrinsic.rs @@ -133,7 +133,7 @@ fn codegen_intrinsic_call( } sym::va_arg => { match fn_abi.ret.layout.abi { - abi::Abi::Scalar(ref scalar) => { + abi::Abi::Scalar(scalar) => { match scalar.value { Primitive::Int(..) => { if self.cx().size_of(ret_ty).bytes() < 4 { diff --git a/compiler/rustc_codegen_llvm/src/type_of.rs b/compiler/rustc_codegen_llvm/src/type_of.rs index d615d230ea0d19a45dc5fca07233cc39cbb67526..3e39bf3e995a25cea16d1ae100d020729c64783b 100644 --- a/compiler/rustc_codegen_llvm/src/type_of.rs +++ b/compiler/rustc_codegen_llvm/src/type_of.rs @@ -23,7 +23,7 @@ fn uncached_llvm_type<'a, 'tcx>( ) -> &'a Type { match layout.abi { Abi::Scalar(_) => bug!("handled elsewhere"), - Abi::Vector { ref element, count } => { + Abi::Vector { element, count } => { let element = layout.scalar_llvm_type_at(cx, element, Size::ZERO); return cx.type_vector(element, count); } @@ -177,7 +177,7 @@ pub trait LayoutLlvmExt<'tcx> { fn scalar_llvm_type_at<'a>( &self, cx: &CodegenCx<'a, 'tcx>, - scalar: &Scalar, + scalar: Scalar, offset: Size, ) -> &'a Type; fn scalar_pair_element_llvm_type<'a>( @@ -218,7 +218,7 @@ fn is_llvm_scalar_pair(&self) -> bool { /// of that field's type - this is useful for taking the address of /// that field and ensuring the struct has the right alignment. fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { - if let Abi::Scalar(ref scalar) = self.abi { + if let Abi::Scalar(scalar) = self.abi { // Use a different cache for scalars because pointers to DSTs // can be either fat or thin (data pointers of fat pointers). if let Some(&llty) = cx.scalar_lltypes.borrow().get(&self.ty) { @@ -286,7 +286,7 @@ fn llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { } fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { - if let Abi::Scalar(ref scalar) = self.abi { + if let Abi::Scalar(scalar) = self.abi { if scalar.is_bool() { return cx.type_i1(); } @@ -297,7 +297,7 @@ fn immediate_llvm_type<'a>(&self, cx: &CodegenCx<'a, 'tcx>) -> &'a Type { fn scalar_llvm_type_at<'a>( &self, cx: &CodegenCx<'a, 'tcx>, - scalar: &Scalar, + scalar: Scalar, offset: Size, ) -> &'a Type { match scalar.value { @@ -337,7 +337,7 @@ fn scalar_pair_element_llvm_type<'a>( } let (a, b) = match self.abi { - Abi::ScalarPair(ref a, ref b) => (a, b), + Abi::ScalarPair(a, b) => (a, b), _ => bug!("TyAndLayout::scalar_pair_element_llty({:?}): not applicable", self), }; let scalar = [a, b][index]; diff --git a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs index f0b32c96309d629f90e66a6aaa94c71967404753..e842f5e9391c806b0ba62d6b98b3ab4d4cd2c299 100644 --- a/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs +++ b/compiler/rustc_codegen_ssa/src/debuginfo/type_names.rs @@ -404,7 +404,7 @@ fn msvc_enum_fallback( // calculate the range of values for the dataful variant let dataful_discriminant_range = - &dataful_variant_layout.largest_niche.as_ref().unwrap().scalar.valid_range; + dataful_variant_layout.largest_niche.unwrap().scalar.valid_range; let min = dataful_discriminant_range.start; let min = tag.value.size(&tcx).truncate(min); diff --git a/compiler/rustc_codegen_ssa/src/mir/block.rs b/compiler/rustc_codegen_ssa/src/mir/block.rs index 93dc9850fc77d6226cb1d3930bc7732741587eee..cd0e9354c2441b419e49dd6a728b226e81234a02 100644 --- a/compiler/rustc_codegen_ssa/src/mir/block.rs +++ b/compiler/rustc_codegen_ssa/src/mir/block.rs @@ -1102,9 +1102,9 @@ fn codegen_argument( // the load would just produce `OperandValue::Ref` instead // of the `OperandValue::Immediate` we need for the call. llval = bx.load(bx.backend_type(arg.layout), llval, align); - if let abi::Abi::Scalar(ref scalar) = arg.layout.abi { + if let abi::Abi::Scalar(scalar) = arg.layout.abi { if scalar.is_bool() { - bx.range_metadata(llval, &WrappingRange { start: 0, end: 1 }); + bx.range_metadata(llval, WrappingRange { start: 0, end: 1 }); } } // We store bools as `i8` so we need to truncate to `i1`. @@ -1424,7 +1424,7 @@ fn codegen_transmute_into( let src = self.codegen_operand(bx, src); // Special-case transmutes between scalars as simple bitcasts. - match (&src.layout.abi, &dst.layout.abi) { + match (src.layout.abi, dst.layout.abi) { (abi::Abi::Scalar(src_scalar), abi::Abi::Scalar(dst_scalar)) => { // HACK(eddyb) LLVM doesn't like `bitcast`s between pointers and non-pointers. if (src_scalar.value == abi::Pointer) == (dst_scalar.value == abi::Pointer) { diff --git a/compiler/rustc_codegen_ssa/src/mir/constant.rs b/compiler/rustc_codegen_ssa/src/mir/constant.rs index fa8a53e60b169d96c4d25288556fbf29b15844ca..93b39dc8e9ee102c8015ca4b21ebfd9f5c5d5fd1 100644 --- a/compiler/rustc_codegen_ssa/src/mir/constant.rs +++ b/compiler/rustc_codegen_ssa/src/mir/constant.rs @@ -68,7 +68,7 @@ pub fn simd_shuffle_indices( if let Some(prim) = field.val.try_to_scalar() { let layout = bx.layout_of(field_ty); let scalar = match layout.abi { - Abi::Scalar(ref x) => x, + Abi::Scalar(x) => x, _ => bug!("from_const: invalid ByVal layout: {:#?}", layout), }; bx.scalar_to_backend(prim, scalar, bx.immediate_backend_type(layout)) diff --git a/compiler/rustc_codegen_ssa/src/mir/operand.rs b/compiler/rustc_codegen_ssa/src/mir/operand.rs index 5cee25b5cca3b5f9fa5362341f4617aaa21f15b5..ce6cec67ad41ef7b17f7f73bf31925d3671c6c2b 100644 --- a/compiler/rustc_codegen_ssa/src/mir/operand.rs +++ b/compiler/rustc_codegen_ssa/src/mir/operand.rs @@ -79,7 +79,7 @@ pub fn from_const>( let val = match val { ConstValue::Scalar(x) => { let scalar = match layout.abi { - Abi::Scalar(ref x) => x, + Abi::Scalar(x) => x, _ => bug!("from_const: invalid ByVal layout: {:#?}", layout), }; let llval = bx.scalar_to_backend(x, scalar, bx.immediate_backend_type(layout)); @@ -87,7 +87,7 @@ pub fn from_const>( } ConstValue::Slice { data, start, end } => { let a_scalar = match layout.abi { - Abi::ScalarPair(ref a, _) => a, + Abi::ScalarPair(a, _) => a, _ => bug!("from_const: invalid ScalarPair layout: {:#?}", layout), }; let a = Scalar::from_pointer( @@ -162,7 +162,7 @@ pub fn from_immediate_or_packed_pair>( llval: V, layout: TyAndLayout<'tcx>, ) -> Self { - let val = if let Abi::ScalarPair(ref a, ref b) = layout.abi { + let val = if let Abi::ScalarPair(a, b) = layout.abi { debug!("Operand::from_immediate_or_packed_pair: unpacking {:?} @ {:?}", llval, layout); // Deconstruct the immediate aggregate. @@ -185,7 +185,7 @@ pub fn extract_field>( let field = self.layout.field(bx.cx(), i); let offset = self.layout.fields.offset(i); - let mut val = match (self.val, &self.layout.abi) { + let mut val = match (self.val, self.layout.abi) { // If the field is ZST, it has no data. _ if field.is_zst() => { return OperandRef::new_zst(bx, field); @@ -200,7 +200,7 @@ pub fn extract_field>( } // Extract a scalar component from a pair. - (OperandValue::Pair(a_llval, b_llval), &Abi::ScalarPair(ref a, ref b)) => { + (OperandValue::Pair(a_llval, b_llval), Abi::ScalarPair(a, b)) => { if offset.bytes() == 0 { assert_eq!(field.size, a.value.size(bx.cx())); OperandValue::Immediate(a_llval) @@ -212,14 +212,14 @@ pub fn extract_field>( } // `#[repr(simd)]` types are also immediate. - (OperandValue::Immediate(llval), &Abi::Vector { .. }) => { + (OperandValue::Immediate(llval), Abi::Vector { .. }) => { OperandValue::Immediate(bx.extract_element(llval, bx.cx().const_usize(i as u64))) } _ => bug!("OperandRef::extract_field({:?}): not applicable", self), }; - match (&mut val, &field.abi) { + match (&mut val, field.abi) { (OperandValue::Immediate(llval), _) => { // Bools in union fields needs to be truncated. *llval = bx.to_immediate(*llval, field); @@ -308,7 +308,7 @@ fn store_with_flags>( } OperandValue::Pair(a, b) => { let (a_scalar, b_scalar) = match dest.layout.abi { - Abi::ScalarPair(ref a, ref b) => (a, b), + Abi::ScalarPair(a, b) => (a, b), _ => bug!("store_with_flags: invalid ScalarPair layout: {:#?}", dest.layout), }; let ty = bx.backend_type(dest.layout); diff --git a/compiler/rustc_codegen_ssa/src/mir/place.rs b/compiler/rustc_codegen_ssa/src/mir/place.rs index b48d6d42b43577d62242d06c0d2fc12b8d396815..4b07ed1a1e6c2b2bf884db3b94d42b206c58b9d4 100644 --- a/compiler/rustc_codegen_ssa/src/mir/place.rs +++ b/compiler/rustc_codegen_ssa/src/mir/place.rs @@ -99,7 +99,7 @@ pub fn project_field>( // Also handles the first field of Scalar, ScalarPair, and Vector layouts. self.llval } - Abi::ScalarPair(ref a, ref b) + Abi::ScalarPair(a, b) if offset == a.value.size(bx.cx()).align_to(b.value.align(bx.cx()).abi) => { // Offset matches second field. @@ -222,7 +222,7 @@ pub fn codegen_get_discr>( .map_or(index.as_u32() as u128, |discr| discr.val); return bx.cx().const_uint_big(cast_to, discr_val); } - Variants::Multiple { ref tag, ref tag_encoding, tag_field, .. } => { + Variants::Multiple { tag, ref tag_encoding, tag_field, .. } => { (tag, tag_encoding, tag_field) } }; diff --git a/compiler/rustc_codegen_ssa/src/traits/builder.rs b/compiler/rustc_codegen_ssa/src/traits/builder.rs index 935f2240143dfcb954b2de634d7b63c98f9f6f47..e7da96f0adafdaf53b510f3084c7f4ad684b59c3 100644 --- a/compiler/rustc_codegen_ssa/src/traits/builder.rs +++ b/compiler/rustc_codegen_ssa/src/traits/builder.rs @@ -124,13 +124,13 @@ fn checked_binop( fn from_immediate(&mut self, val: Self::Value) -> Self::Value; fn to_immediate(&mut self, val: Self::Value, layout: TyAndLayout<'_>) -> Self::Value { - if let Abi::Scalar(ref scalar) = layout.abi { + if let Abi::Scalar(scalar) = layout.abi { self.to_immediate_scalar(val, scalar) } else { val } } - fn to_immediate_scalar(&mut self, val: Self::Value, scalar: &Scalar) -> Self::Value; + fn to_immediate_scalar(&mut self, val: Self::Value, scalar: Scalar) -> Self::Value; fn alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value; fn dynamic_alloca(&mut self, ty: Self::Type, align: Align) -> Self::Value; @@ -156,7 +156,7 @@ fn write_operand_repeatedly( dest: PlaceRef<'tcx, Self::Value>, ) -> Self; - fn range_metadata(&mut self, load: Self::Value, range: &WrappingRange); + fn range_metadata(&mut self, load: Self::Value, range: WrappingRange); fn nonnull_metadata(&mut self, load: Self::Value); fn store(&mut self, val: Self::Value, ptr: Self::Value, align: Align) -> Self::Value; diff --git a/compiler/rustc_codegen_ssa/src/traits/consts.rs b/compiler/rustc_codegen_ssa/src/traits/consts.rs index 20f6618712327870212d734e8ca15062b03aacbf..5260b7cc33120e0e36c05d3d79eb0ad537b7d317 100644 --- a/compiler/rustc_codegen_ssa/src/traits/consts.rs +++ b/compiler/rustc_codegen_ssa/src/traits/consts.rs @@ -28,7 +28,7 @@ pub trait ConstMethods<'tcx>: BackendTypes { fn const_data_from_alloc(&self, alloc: &Allocation) -> Self::Value; - fn scalar_to_backend(&self, cv: Scalar, layout: &abi::Scalar, llty: Self::Type) -> Self::Value; + fn scalar_to_backend(&self, cv: Scalar, layout: abi::Scalar, llty: Self::Type) -> Self::Value; fn from_const_alloc( &self, layout: TyAndLayout<'tcx>, diff --git a/compiler/rustc_const_eval/src/interpret/intrinsics.rs b/compiler/rustc_const_eval/src/interpret/intrinsics.rs index 07e974b72664bbefc7103a91f80532ea3135ec6e..bcc4d11e64bf1ecd84a5c7f05b1a1826379b9205 100644 --- a/compiler/rustc_const_eval/src/interpret/intrinsics.rs +++ b/compiler/rustc_const_eval/src/interpret/intrinsics.rs @@ -194,7 +194,7 @@ pub fn emulate_intrinsic( let val = self.read_scalar(&args[0])?.check_init()?; let bits = val.to_bits(layout_of.size)?; let kind = match layout_of.abi { - Abi::Scalar(ref scalar) => scalar.value, + Abi::Scalar(scalar) => scalar.value, _ => span_bug!( self.cur_span(), "{} called on invalid type {:?}", diff --git a/compiler/rustc_const_eval/src/interpret/operand.rs b/compiler/rustc_const_eval/src/interpret/operand.rs index 63aca67c9443c13b1724fa6fb2087cc6e94ec327..de870bd5c6cf1be3972ad5eede57b696572a7501 100644 --- a/compiler/rustc_const_eval/src/interpret/operand.rs +++ b/compiler/rustc_const_eval/src/interpret/operand.rs @@ -274,11 +274,11 @@ fn try_read_immediate_from_mplace( let scalar = alloc.read_scalar(alloc_range(Size::ZERO, mplace.layout.size))?; Ok(Some(ImmTy { imm: scalar.into(), layout: mplace.layout })) } - Abi::ScalarPair(ref a, ref b) => { + Abi::ScalarPair(a, b) => { // We checked `ptr_align` above, so all fields will have the alignment they need. // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. - let (a, b) = (&a.value, &b.value); + let (a, b) = (a.value, b.value); let (a_size, b_size) = (a.size(self), b.size(self)); let b_offset = a_size.align_to(b.align(self).abi); assert!(b_offset.bytes() > 0); // we later use the offset to tell apart the fields @@ -648,7 +648,7 @@ pub fn read_discriminant( }; return Ok((discr, index)); } - Variants::Multiple { ref tag, ref tag_encoding, tag_field, .. } => { + Variants::Multiple { tag, ref tag_encoding, tag_field, .. } => { (tag, tag_encoding, tag_field) } }; diff --git a/compiler/rustc_const_eval/src/interpret/place.rs b/compiler/rustc_const_eval/src/interpret/place.rs index 95a44e3fecf3d19b249c1f81924f123b5ebc010b..0da6d8169bd3a7b36c25f7d9aca0d7fbb1b3f871 100644 --- a/compiler/rustc_const_eval/src/interpret/place.rs +++ b/compiler/rustc_const_eval/src/interpret/place.rs @@ -752,7 +752,7 @@ fn write_immediate_to_mplace_no_validate( // We would anyway check against `ptr_align.restrict_for_offset(b_offset)`, // which `ptr.offset(b_offset)` cannot possibly fail to satisfy. let (a, b) = match dest.layout.abi { - Abi::ScalarPair(ref a, ref b) => (&a.value, &b.value), + Abi::ScalarPair(a, b) => (a.value, b.value), _ => span_bug!( self.cur_span(), "write_immediate_to_mplace: invalid ScalarPair layout: {:#?}", @@ -1000,7 +1000,7 @@ pub fn write_discriminant( } Variants::Multiple { tag_encoding: TagEncoding::Direct, - tag: ref tag_layout, + tag: tag_layout, tag_field, .. } => { @@ -1022,7 +1022,7 @@ pub fn write_discriminant( Variants::Multiple { tag_encoding: TagEncoding::Niche { dataful_variant, ref niche_variants, niche_start }, - tag: ref tag_layout, + tag: tag_layout, tag_field, .. } => { diff --git a/compiler/rustc_const_eval/src/interpret/terminator.rs b/compiler/rustc_const_eval/src/interpret/terminator.rs index 1c8e5e9e23c3caefab88cd27f834bd67c5b8db48..a06903aedf6499a167e499e27cf7502f42958e3a 100644 --- a/compiler/rustc_const_eval/src/interpret/terminator.rs +++ b/compiler/rustc_const_eval/src/interpret/terminator.rs @@ -187,17 +187,14 @@ fn check_argument_compat( return false; } // Compare layout - match (&caller.abi, &callee.abi) { + match (caller.abi, callee.abi) { // Different valid ranges are okay (once we enforce validity, // that will take care to make it UB to leave the range, just // like for transmute). - (abi::Abi::Scalar(ref caller), abi::Abi::Scalar(ref callee)) => { - caller.value == callee.value + (abi::Abi::Scalar(caller), abi::Abi::Scalar(callee)) => caller.value == callee.value, + (abi::Abi::ScalarPair(caller1, caller2), abi::Abi::ScalarPair(callee1, callee2)) => { + caller1.value == callee1.value && caller2.value == callee2.value } - ( - abi::Abi::ScalarPair(ref caller1, ref caller2), - abi::Abi::ScalarPair(ref callee1, ref callee2), - ) => caller1.value == callee1.value && caller2.value == callee2.value, // Be conservative _ => false, } diff --git a/compiler/rustc_const_eval/src/interpret/validity.rs b/compiler/rustc_const_eval/src/interpret/validity.rs index 7ae3f98d834b49eee5c1a4e374fa0064310f2ba5..393c3e43b5d3044ed68c32dc4bfe40c208dd744b 100644 --- a/compiler/rustc_const_eval/src/interpret/validity.rs +++ b/compiler/rustc_const_eval/src/interpret/validity.rs @@ -618,7 +618,7 @@ fn try_visit_primitive( fn visit_scalar( &mut self, op: &OpTy<'tcx, M::PointerTag>, - scalar_layout: &ScalarAbi, + scalar_layout: ScalarAbi, ) -> InterpResult<'tcx> { if scalar_layout.valid_range.is_full_for(op.layout.size) { // Nothing to check @@ -784,7 +784,7 @@ fn visit_value(&mut self, op: &OpTy<'tcx, M::PointerTag>) -> InterpResult<'tcx> { "a value of uninhabited type {:?}", op.layout.ty } ); } - Abi::Scalar(ref scalar_layout) => { + Abi::Scalar(scalar_layout) => { self.visit_scalar(op, scalar_layout)?; } Abi::ScalarPair { .. } | Abi::Vector { .. } => { diff --git a/compiler/rustc_lint/src/types.rs b/compiler/rustc_lint/src/types.rs index 480f7756db3fe60476d766bc46ebffd852c38cf6..0143978cfba5f0eaa629bbe0f29b92cfbec4fa80 100644 --- a/compiler/rustc_lint/src/types.rs +++ b/compiler/rustc_lint/src/types.rs @@ -1327,10 +1327,7 @@ fn check_item(&mut self, cx: &LateContext<'_>, it: &hir::Item<'_>) { }; let (variants, tag) = match layout.variants { Variants::Multiple { - tag_encoding: TagEncoding::Direct, - ref tag, - ref variants, - .. + tag_encoding: TagEncoding::Direct, tag, ref variants, .. } => (variants, tag), _ => return, }; diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 9f9806f272e5a3c08928cf976dbdf423a678b1dd..67d33a0321f4d9ef2be2102ec8d15c6af48d395b 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -290,9 +290,9 @@ fn scalar_pair(&self, a: Scalar, b: Scalar) -> Layout { // HACK(nox): We iter on `b` and then `a` because `max_by_key` // returns the last maximum. - let largest_niche = Niche::from_scalar(dl, b_offset, b.clone()) + let largest_niche = Niche::from_scalar(dl, b_offset, b) .into_iter() - .chain(Niche::from_scalar(dl, Size::ZERO, a.clone())) + .chain(Niche::from_scalar(dl, Size::ZERO, a)) .max_by_key(|niche| niche.available(dl)); Layout { @@ -401,7 +401,7 @@ fn univariant_uninterned( offsets[i as usize] = offset; if !repr.hide_niche() { - if let Some(mut niche) = field.largest_niche.clone() { + if let Some(mut niche) = field.largest_niche { let available = niche.available(dl); if available > largest_niche_available { largest_niche_available = available; @@ -449,12 +449,12 @@ fn univariant_uninterned( // For plain scalars, or vectors of them, we can't unpack // newtypes for `#[repr(C)]`, as that affects C ABIs. Abi::Scalar(_) | Abi::Vector { .. } if optimize => { - abi = field.abi.clone(); + abi = field.abi; } // But scalar pairs are Rust-specific and get // treated as aggregates by C ABIs anyway. Abi::ScalarPair(..) => { - abi = field.abi.clone(); + abi = field.abi; } _ => {} } @@ -463,14 +463,14 @@ fn univariant_uninterned( // Two non-ZST fields, and they're both scalars. ( - Some((i, &TyAndLayout { layout: &Layout { abi: Abi::Scalar(ref a), .. }, .. })), - Some((j, &TyAndLayout { layout: &Layout { abi: Abi::Scalar(ref b), .. }, .. })), + Some((i, &TyAndLayout { layout: &Layout { abi: Abi::Scalar(a), .. }, .. })), + Some((j, &TyAndLayout { layout: &Layout { abi: Abi::Scalar(b), .. }, .. })), None, ) => { // Order by the memory placement, not source order. let ((i, a), (j, b)) = if offsets[i] < offsets[j] { ((i, a), (j, b)) } else { ((j, b), (i, a)) }; - let pair = self.scalar_pair(a.clone(), b.clone()); + let pair = self.scalar_pair(a, b); let pair_offsets = match pair.fields { FieldsShape::Arbitrary { ref offsets, ref memory_index } => { assert_eq!(memory_index, &[0, 1]); @@ -609,7 +609,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' Abi::Aggregate { sized: true } }; - let largest_niche = if count != 0 { element.largest_niche.clone() } else { None }; + let largest_niche = if count != 0 { element.largest_niche } else { None }; tcx.intern_layout(Layout { variants: Variants::Single { index: VariantIdx::new(0) }, @@ -768,8 +768,8 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' // Compute the ABI of the element type: let e_ly = self.layout_of(e_ty)?; - let e_abi = if let Abi::Scalar(ref scalar) = e_ly.abi { - scalar.clone() + let e_abi = if let Abi::Scalar(scalar) = e_ly.abi { + scalar } else { // This error isn't caught in typeck, e.g., if // the element type of the vector is generic. @@ -796,7 +796,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' variants: Variants::Single { index: VariantIdx::new(0) }, fields, abi: Abi::Vector { element: e_abi, count: e_len }, - largest_niche: e_ly.largest_niche.clone(), + largest_niche: e_ly.largest_niche, size, align, }) @@ -843,13 +843,13 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' // If all non-ZST fields have the same ABI, forward this ABI if optimize && !field.is_zst() { // Normalize scalar_unit to the maximal valid range - let field_abi = match &field.abi { + let field_abi = match field.abi { Abi::Scalar(x) => Abi::Scalar(scalar_unit(x.value)), Abi::ScalarPair(x, y) => { Abi::ScalarPair(scalar_unit(x.value), scalar_unit(y.value)) } Abi::Vector { element: x, count } => { - Abi::Vector { element: scalar_unit(x.value), count: *count } + Abi::Vector { element: scalar_unit(x.value), count } } Abi::Uninhabited | Abi::Aggregate { .. } => { Abi::Aggregate { sized: true } @@ -970,7 +970,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' Niche::from_scalar(dl, Size::ZERO, scalar.clone()) }; if let Some(niche) = niche { - match &st.largest_niche { + match st.largest_niche { Some(largest_niche) => { // Replace the existing niche even if they're equal, // because this one is at a lower offset. @@ -1045,7 +1045,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' let niche_candidate = variants[i] .iter() .enumerate() - .filter_map(|(j, &field)| Some((j, field.largest_niche.as_ref()?))) + .filter_map(|(j, field)| Some((j, field.largest_niche?))) .max_by_key(|(_, niche)| niche.available(dl)); if let Some((field_index, niche, (niche_start, niche_scalar))) = @@ -1078,31 +1078,24 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' Abi::Uninhabited } else { match st[i].abi { - Abi::Scalar(_) => Abi::Scalar(niche_scalar.clone()), - Abi::ScalarPair(ref first, ref second) => { + Abi::Scalar(_) => Abi::Scalar(niche_scalar), + Abi::ScalarPair(first, second) => { // We need to use scalar_unit to reset the // valid range to the maximal one for that // primitive, because only the niche is // guaranteed to be initialised, not the // other primitive. if offset.bytes() == 0 { - Abi::ScalarPair( - niche_scalar.clone(), - scalar_unit(second.value), - ) + Abi::ScalarPair(niche_scalar, scalar_unit(second.value)) } else { - Abi::ScalarPair( - scalar_unit(first.value), - niche_scalar.clone(), - ) + Abi::ScalarPair(scalar_unit(first.value), niche_scalar) } } _ => Abi::Aggregate { sized: true }, } }; - let largest_niche = - Niche::from_scalar(dl, offset, niche_scalar.clone()); + let largest_niche = Niche::from_scalar(dl, offset, niche_scalar); niche_filling_layout = Some(Layout { variants: Variants::Multiple { @@ -1283,7 +1276,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' }; let mut abi = Abi::Aggregate { sized: true }; if tag.value.size(dl) == size { - abi = Abi::Scalar(tag.clone()); + abi = Abi::Scalar(tag); } else { // Try to use a ScalarPair for all tagged enums. let mut common_prim = None; @@ -1303,7 +1296,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' } }; let prim = match field.abi { - Abi::Scalar(ref scalar) => scalar.value, + Abi::Scalar(scalar) => scalar.value, _ => { common_prim = None; break; @@ -1323,7 +1316,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' } } if let Some((prim, offset)) = common_prim { - let pair = self.scalar_pair(tag.clone(), scalar_unit(prim)); + let pair = self.scalar_pair(tag, scalar_unit(prim)); let pair_offsets = match pair.fields { FieldsShape::Arbitrary { ref offsets, ref memory_index } => { assert_eq!(memory_index, &[0, 1]); @@ -1347,7 +1340,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' abi = Abi::Uninhabited; } - let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag.clone()); + let largest_niche = Niche::from_scalar(dl, Size::ZERO, tag); let tagged_layout = Layout { variants: Variants::Multiple { @@ -1372,8 +1365,7 @@ fn layout_of_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx Layout, LayoutError<' // pick the layout with the larger niche; otherwise, // pick tagged as it has simpler codegen. cmp::min_by_key(tagged_layout, niche_filling_layout, |layout| { - let niche_size = - layout.largest_niche.as_ref().map_or(0, |n| n.available(dl)); + let niche_size = layout.largest_niche.map_or(0, |n| n.available(dl)); (layout.size, cmp::Reverse(niche_size)) }) } @@ -1560,7 +1552,7 @@ fn generator_layout( value: Primitive::Int(discr_int, false), valid_range: WrappingRange { start: 0, end: max_discr }, }; - let tag_layout = self.tcx.intern_layout(Layout::scalar(self, tag.clone())); + let tag_layout = self.tcx.intern_layout(Layout::scalar(self, tag)); let tag_layout = TyAndLayout { ty: discr_int_ty, layout: tag_layout }; let promoted_layouts = ineligible_locals @@ -1832,7 +1824,7 @@ fn record_layout_for_printing_outlined(&self, layout: TyAndLayout<'tcx>) { } } - Variants::Multiple { ref tag, ref tag_encoding, .. } => { + Variants::Multiple { tag, ref tag_encoding, .. } => { debug!( "print-type-size `{:#?}` adt general variants def {}", layout.ty, @@ -2240,7 +2232,7 @@ fn field_ty_or_layout( i: usize, ) -> TyMaybeWithLayout<'tcx> { let tcx = cx.tcx(); - let tag_layout = |tag: &Scalar| -> TyAndLayout<'tcx> { + let tag_layout = |tag: Scalar| -> TyAndLayout<'tcx> { let layout = Layout::scalar(cx, tag.clone()); TyAndLayout { layout: tcx.intern_layout(layout), ty: tag.value.to_ty(tcx) } }; @@ -2329,7 +2321,7 @@ fn field_ty_or_layout( .nth(i) .unwrap(), ), - Variants::Multiple { ref tag, tag_field, .. } => { + Variants::Multiple { tag, tag_field, .. } => { if i == tag_field { return TyMaybeWithLayout::TyAndLayout(tag_layout(tag)); } @@ -2347,7 +2339,7 @@ fn field_ty_or_layout( } // Discriminant field for enums (where applicable). - Variants::Multiple { ref tag, .. } => { + Variants::Multiple { tag, .. } => { assert_eq!(i, 0); return TyMaybeWithLayout::TyAndLayout(tag_layout(tag)); } @@ -2906,7 +2898,7 @@ fn new_internal( // Handle safe Rust thin and fat pointers. let adjust_for_rust_scalar = |attrs: &mut ArgAttributes, - scalar: &Scalar, + scalar: Scalar, layout: TyAndLayout<'tcx>, offset: Size, is_return: bool| { diff --git a/compiler/rustc_target/src/abi/call/mips64.rs b/compiler/rustc_target/src/abi/call/mips64.rs index 28ca93c46921e1cd7f69e770f89e99a7c722b40b..2e00ffc7e14730a916f95b3d3514ad74dc9dfe9d 100644 --- a/compiler/rustc_target/src/abi/call/mips64.rs +++ b/compiler/rustc_target/src/abi/call/mips64.rs @@ -3,7 +3,7 @@ fn extend_integer_width_mips(arg: &mut ArgAbi<'_, Ty>, bits: u64) { // Always sign extend u32 values on 64-bit mips - if let abi::Abi::Scalar(ref scalar) = arg.layout.abi { + if let abi::Abi::Scalar(scalar) = arg.layout.abi { if let abi::Int(i, signed) = scalar.value { if !signed && i.size().bits() == 32 { if let PassMode::Direct(ref mut attrs) = arg.mode { @@ -23,7 +23,7 @@ fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgAbi<'a, Ty>, i: usize) -> Option C: HasDataLayout, { match ret.layout.field(cx, i).abi { - abi::Abi::Scalar(ref scalar) => match scalar.value { + abi::Abi::Scalar(scalar) => match scalar.value { abi::F32 => Some(Reg::f32()), abi::F64 => Some(Reg::f64()), _ => None, @@ -107,7 +107,7 @@ fn classify_arg<'a, Ty, C>(cx: &C, arg: &mut ArgAbi<'a, Ty>) let offset = arg.layout.fields.offset(i); // We only care about aligned doubles - if let abi::Abi::Scalar(ref scalar) = field.abi { + if let abi::Abi::Scalar(scalar) = field.abi { if let abi::F64 = scalar.value { if offset.is_aligned(dl.f64_align.abi) { // Insert enough integers to cover [last_offset, offset) diff --git a/compiler/rustc_target/src/abi/call/mod.rs b/compiler/rustc_target/src/abi/call/mod.rs index 6d3c7318091076fbcbb0b2f7b5fab6c70ef5cfc7..927bebd8157a629aac8499de65420baece8947c7 100644 --- a/compiler/rustc_target/src/abi/call/mod.rs +++ b/compiler/rustc_target/src/abi/call/mod.rs @@ -322,7 +322,7 @@ pub fn homogeneous_aggregate(&self, cx: &C) -> Result Err(Heterogeneous), // The primitive for this algorithm. - Abi::Scalar(ref scalar) => { + Abi::Scalar(scalar) => { let kind = match scalar.value { abi::Int(..) | abi::Pointer => RegKind::Integer, abi::F32 | abi::F64 => RegKind::Float, @@ -450,9 +450,9 @@ impl<'a, Ty> ArgAbi<'a, Ty> { pub fn new( cx: &impl HasDataLayout, layout: TyAndLayout<'a, Ty>, - scalar_attrs: impl Fn(&TyAndLayout<'a, Ty>, &abi::Scalar, Size) -> ArgAttributes, + scalar_attrs: impl Fn(&TyAndLayout<'a, Ty>, abi::Scalar, Size) -> ArgAttributes, ) -> Self { - let mode = match &layout.abi { + let mode = match layout.abi { Abi::Uninhabited => PassMode::Ignore, Abi::Scalar(scalar) => PassMode::Direct(scalar_attrs(&layout, scalar, Size::ZERO)), Abi::ScalarPair(a, b) => PassMode::Pair( @@ -504,7 +504,7 @@ pub fn make_indirect_byval(&mut self) { pub fn extend_integer_width_to(&mut self, bits: u64) { // Only integers have signedness - if let Abi::Scalar(ref scalar) = self.layout.abi { + if let Abi::Scalar(scalar) = self.layout.abi { if let abi::Int(i, signed) = scalar.value { if i.size().bits() < bits { if let PassMode::Direct(ref mut attrs) = self.mode { diff --git a/compiler/rustc_target/src/abi/call/riscv.rs b/compiler/rustc_target/src/abi/call/riscv.rs index 8c2ef8c7a017dfe130e2ac1799faee0241fdaff3..bbefc73a076d7dd7ccb0b10efc8b7a6ac5a21e99 100644 --- a/compiler/rustc_target/src/abi/call/riscv.rs +++ b/compiler/rustc_target/src/abi/call/riscv.rs @@ -44,7 +44,7 @@ fn should_use_fp_conv_helper<'a, Ty, C>( Ty: TyAbiInterface<'a, C> + Copy, { match arg_layout.abi { - Abi::Scalar(ref scalar) => match scalar.value { + Abi::Scalar(scalar) => match scalar.value { abi::Int(..) | abi::Pointer => { if arg_layout.size.bits() > xlen { return Err(CannotUseFpConv); @@ -297,7 +297,7 @@ fn classify_arg<'a, Ty, C>( } fn extend_integer_width<'a, Ty>(arg: &mut ArgAbi<'a, Ty>, xlen: u64) { - if let Abi::Scalar(ref scalar) = arg.layout.abi { + if let Abi::Scalar(scalar) = arg.layout.abi { if let abi::Int(i, _) = scalar.value { // 32-bit integers are always sign-extended if i.size().bits() == 32 && xlen > 32 { diff --git a/compiler/rustc_target/src/abi/call/s390x.rs b/compiler/rustc_target/src/abi/call/s390x.rs index 594108925de8093e4ac90159ab035c714aff2c9b..38aaee64a4d6b6978daa0a02c0933aed38542958 100644 --- a/compiler/rustc_target/src/abi/call/s390x.rs +++ b/compiler/rustc_target/src/abi/call/s390x.rs @@ -18,7 +18,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool C: HasDataLayout, { match layout.abi { - abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), + abi::Abi::Scalar(scalar) => scalar.value.is_float(), abi::Abi::Aggregate { .. } => { if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 { is_single_fp_element(cx, layout.field(cx, 0)) diff --git a/compiler/rustc_target/src/abi/call/x86.rs b/compiler/rustc_target/src/abi/call/x86.rs index 3fc197b5d7537f494c7e830c776c19526b3324d5..28064d85bf1710ae6a218d43060951af9a763e5b 100644 --- a/compiler/rustc_target/src/abi/call/x86.rs +++ b/compiler/rustc_target/src/abi/call/x86.rs @@ -14,7 +14,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyAndLayout<'a, Ty>) -> bool C: HasDataLayout, { match layout.abi { - abi::Abi::Scalar(ref scalar) => scalar.value.is_float(), + abi::Abi::Scalar(scalar) => scalar.value.is_float(), abi::Abi::Aggregate { .. } => { if layout.fields.count() == 1 && layout.fields.offset(0).bytes() == 0 { is_single_fp_element(cx, layout.field(cx, 0)) diff --git a/compiler/rustc_target/src/abi/call/x86_64.rs b/compiler/rustc_target/src/abi/call/x86_64.rs index 08f0aaba59af4891333db4179448682a8f314464..fae3c3af61bf01f02c41f72f1978ff7036513671 100644 --- a/compiler/rustc_target/src/abi/call/x86_64.rs +++ b/compiler/rustc_target/src/abi/call/x86_64.rs @@ -49,7 +49,7 @@ fn classify<'a, Ty, C>( let mut c = match layout.abi { Abi::Uninhabited => return Ok(()), - Abi::Scalar(ref scalar) => match scalar.value { + Abi::Scalar(scalar) => match scalar.value { abi::Int(..) | abi::Pointer => Class::Int, abi::F32 | abi::F64 => Class::Sse, }, diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index d5b4972444506b6e9f4a0d205a0085b262209283..8764b851affad0999d010a8a1921325b6db6f08e 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -955,7 +955,7 @@ impl AddressSpace { /// Describes how values of the type are passed by target ABIs, /// in terms of categories of C types there are ABI rules for. -#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub enum Abi { Uninhabited, Scalar(Scalar), @@ -983,8 +983,8 @@ pub fn is_unsized(&self) -> bool { /// Returns `true` if this is a single signed integer scalar #[inline] pub fn is_signed(&self) -> bool { - match *self { - Abi::Scalar(ref scal) => match scal.value { + match self { + Abi::Scalar(scal) => match scal.value { Primitive::Int(_, signed) => signed, _ => false, }, @@ -1053,7 +1053,7 @@ pub enum TagEncoding { }, } -#[derive(Clone, PartialEq, Eq, Hash, Debug, HashStable_Generic)] +#[derive(Clone, Copy, PartialEq, Eq, Hash, Debug, HashStable_Generic)] pub struct Niche { pub offset: Size, pub scalar: Scalar, @@ -1259,7 +1259,7 @@ pub fn might_permit_raw_init(self, cx: &C, zero: bool) -> bool Ty: TyAbiInterface<'a, C>, C: HasDataLayout, { - let scalar_allows_raw_init = move |s: &Scalar| -> bool { + let scalar_allows_raw_init = move |s: Scalar| -> bool { if zero { // The range must contain 0. s.valid_range.contains(0) @@ -1270,11 +1270,11 @@ pub fn might_permit_raw_init(self, cx: &C, zero: bool) -> bool }; // Check the ABI. - let valid = match &self.abi { + let valid = match self.abi { Abi::Uninhabited => false, // definitely UB Abi::Scalar(s) => scalar_allows_raw_init(s), Abi::ScalarPair(s1, s2) => scalar_allows_raw_init(s1) && scalar_allows_raw_init(s2), - Abi::Vector { element: s, count } => *count == 0 || scalar_allows_raw_init(s), + Abi::Vector { element: s, count } => count == 0 || scalar_allows_raw_init(s), Abi::Aggregate { .. } => true, // Fields are checked below. }; if !valid { diff --git a/compiler/rustc_trait_selection/src/traits/object_safety.rs b/compiler/rustc_trait_selection/src/traits/object_safety.rs index 57b8a84300ff9e0db5464fc1759d913c0b6ae9c9..0ecfda19141fa4c32ac2249c469344374ef92fa9 100644 --- a/compiler/rustc_trait_selection/src/traits/object_safety.rs +++ b/compiler/rustc_trait_selection/src/traits/object_safety.rs @@ -465,9 +465,9 @@ fn virtual_call_violation_for_method<'tcx>( let param_env = tcx.param_env(method.def_id); - let abi_of_ty = |ty: Ty<'tcx>| -> Option<&Abi> { + let abi_of_ty = |ty: Ty<'tcx>| -> Option { match tcx.layout_of(param_env.and(ty)) { - Ok(layout) => Some(&layout.abi), + Ok(layout) => Some(layout.abi), Err(err) => { // #78372 tcx.sess.delay_span_bug(