From d00d42d079236893f0a8b2cd726c6957d96ec296 Mon Sep 17 00:00:00 2001 From: Eduard-Mihai Burtescu Date: Sat, 3 Nov 2018 22:57:53 +0200 Subject: [PATCH] rustc_target: pass contexts by reference, not value. --- src/librustc/lint/context.rs | 4 +- src/librustc/middle/intrinsicck.rs | 2 +- src/librustc/mir/interpret/mod.rs | 24 ++++++------ src/librustc/mir/interpret/value.rs | 40 ++++++++++---------- src/librustc/traits/error_reporting.rs | 2 +- src/librustc/ty/layout.rs | 29 +++++++------- src/librustc/ty/util.rs | 6 +-- src/librustc_codegen_llvm/context.rs | 12 +++--- src/librustc_codegen_llvm/mir/constant.rs | 6 +-- src/librustc_lint/types.rs | 6 +-- src/librustc_mir/hair/cx/mod.rs | 2 +- src/librustc_mir/hair/pattern/_match.rs | 6 +-- src/librustc_mir/hair/pattern/mod.rs | 2 +- src/librustc_mir/interpret/cast.rs | 4 +- src/librustc_mir/interpret/eval_context.rs | 44 ++++------------------ src/librustc_mir/interpret/memory.rs | 12 +----- src/librustc_mir/interpret/operand.rs | 8 ++-- src/librustc_mir/interpret/place.rs | 20 +++++----- src/librustc_mir/interpret/step.rs | 6 +-- src/librustc_mir/interpret/terminator.rs | 6 +-- src/librustc_mir/interpret/traits.rs | 6 +-- src/librustc_mir/transform/const_prop.rs | 8 ++-- src/librustc_target/abi/call/aarch64.rs | 8 ++-- src/librustc_target/abi/call/amdgpu.rs | 6 +-- src/librustc_target/abi/call/arm.rs | 8 ++-- src/librustc_target/abi/call/asmjs.rs | 4 +- src/librustc_target/abi/call/mips.rs | 6 +-- src/librustc_target/abi/call/mips64.rs | 8 ++-- src/librustc_target/abi/call/mod.rs | 14 +++---- src/librustc_target/abi/call/powerpc.rs | 6 +-- src/librustc_target/abi/call/powerpc64.rs | 8 ++-- src/librustc_target/abi/call/s390x.rs | 6 +-- src/librustc_target/abi/call/sparc.rs | 6 +-- src/librustc_target/abi/call/sparc64.rs | 8 ++-- src/librustc_target/abi/call/x86.rs | 4 +- src/librustc_target/abi/call/x86_64.rs | 6 +-- src/librustc_target/abi/mod.rs | 32 ++++++++-------- src/librustc_target/spec/mod.rs | 4 +- 38 files changed, 175 insertions(+), 214 deletions(-) diff --git a/src/librustc/lint/context.rs b/src/librustc/lint/context.rs index 7e2532bb1c4e8..5470aff77f8a4 100644 --- a/src/librustc/lint/context.rs +++ b/src/librustc/lint/context.rs @@ -783,11 +783,11 @@ impl<'a, 'tcx> LateContext<'a, 'tcx> { } } -impl<'a, 'tcx> LayoutOf for &'a LateContext<'a, 'tcx> { +impl<'a, 'tcx> LayoutOf for LateContext<'a, 'tcx> { type Ty = Ty<'tcx>; type TyLayout = Result, LayoutError<'tcx>>; - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } } diff --git a/src/librustc/middle/intrinsicck.rs b/src/librustc/middle/intrinsicck.rs index 9d54e798469f7..0a5b1e184deec 100644 --- a/src/librustc/middle/intrinsicck.rs +++ b/src/librustc/middle/intrinsicck.rs @@ -84,7 +84,7 @@ impl<'a, 'tcx> ExprVisitor<'a, 'tcx> { // `Option` to present a clearer error. let from = unpack_option_like(self.tcx.global_tcx(), from); if let (&ty::FnDef(..), SizeSkeleton::Known(size_to)) = (&from.sty, sk_to) { - if size_to == Pointer.size(self.tcx) { + if size_to == Pointer.size(&self.tcx) { struct_span_err!(self.tcx.sess, span, E0591, "can't transmute zero-sized type") .note(&format!("source type: {}", from)) diff --git a/src/librustc/mir/interpret/mod.rs b/src/librustc/mir/interpret/mod.rs index 61b5886e7832d..f8a5dbc6905ca 100644 --- a/src/librustc/mir/interpret/mod.rs +++ b/src/librustc/mir/interpret/mod.rs @@ -86,18 +86,18 @@ pub trait PointerArithmetic: layout::HasDataLayout { // These are not supposed to be overridden. #[inline(always)] - fn pointer_size(self) -> Size { + fn pointer_size(&self) -> Size { self.data_layout().pointer_size } //// Trunace the given value to the pointer size; also return whether there was an overflow - fn truncate_to_ptr(self, val: u128) -> (u64, bool) { + fn truncate_to_ptr(&self, val: u128) -> (u64, bool) { let max_ptr_plus_1 = 1u128 << self.pointer_size().bits(); ((val % max_ptr_plus_1) as u64, val >= max_ptr_plus_1) } // Overflow checking only works properly on the range from -u64 to +u64. - fn overflowing_signed_offset(self, val: u64, i: i128) -> (u64, bool) { + fn overflowing_signed_offset(&self, val: u64, i: i128) -> (u64, bool) { // FIXME: is it possible to over/underflow here? if i < 0 { // trickery to ensure that i64::min_value() works fine @@ -109,23 +109,23 @@ pub trait PointerArithmetic: layout::HasDataLayout { } } - fn overflowing_offset(self, val: u64, i: u64) -> (u64, bool) { + fn overflowing_offset(&self, val: u64, i: u64) -> (u64, bool) { let (res, over1) = val.overflowing_add(i); let (res, over2) = self.truncate_to_ptr(res as u128); (res, over1 || over2) } - fn signed_offset<'tcx>(self, val: u64, i: i64) -> EvalResult<'tcx, u64> { + fn signed_offset<'tcx>(&self, val: u64, i: i64) -> EvalResult<'tcx, u64> { let (res, over) = self.overflowing_signed_offset(val, i as i128); if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) } } - fn offset<'tcx>(self, val: u64, i: u64) -> EvalResult<'tcx, u64> { + fn offset<'tcx>(&self, val: u64, i: u64) -> EvalResult<'tcx, u64> { let (res, over) = self.overflowing_offset(val, i); if over { err!(Overflow(mir::BinOp::Add)) } else { Ok(res) } } - fn wrapping_signed_offset(self, val: u64, i: i64) -> u64 { + fn wrapping_signed_offset(&self, val: u64, i: i64) -> u64 { self.overflowing_signed_offset(val, i as i128).0 } } @@ -176,7 +176,7 @@ impl<'tcx, Tag> Pointer { Pointer { alloc_id, offset, tag } } - pub fn wrapping_signed_offset(self, i: i64, cx: impl HasDataLayout) -> Self { + pub fn wrapping_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> Self { Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().wrapping_signed_offset(self.offset.bytes(), i)), @@ -184,12 +184,12 @@ impl<'tcx, Tag> Pointer { ) } - pub fn overflowing_signed_offset(self, i: i128, cx: impl HasDataLayout) -> (Self, bool) { + pub fn overflowing_signed_offset(self, i: i128, cx: &impl HasDataLayout) -> (Self, bool) { let (res, over) = cx.data_layout().overflowing_signed_offset(self.offset.bytes(), i); (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over) } - pub fn signed_offset(self, i: i64, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { + pub fn signed_offset(self, i: i64, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> { Ok(Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().signed_offset(self.offset.bytes(), i)?), @@ -197,12 +197,12 @@ impl<'tcx, Tag> Pointer { )) } - pub fn overflowing_offset(self, i: Size, cx: impl HasDataLayout) -> (Self, bool) { + pub fn overflowing_offset(self, i: Size, cx: &impl HasDataLayout) -> (Self, bool) { let (res, over) = cx.data_layout().overflowing_offset(self.offset.bytes(), i.bytes()); (Pointer::new_with_tag(self.alloc_id, Size::from_bytes(res), self.tag), over) } - pub fn offset(self, i: Size, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { + pub fn offset(self, i: Size, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> { Ok(Pointer::new_with_tag( self.alloc_id, Size::from_bytes(cx.data_layout().offset(self.offset.bytes(), i.bytes())?), diff --git a/src/librustc/mir/interpret/value.rs b/src/librustc/mir/interpret/value.rs index 4304f08a78f0c..3b8e19c6ecaa9 100644 --- a/src/librustc/mir/interpret/value.rs +++ b/src/librustc/mir/interpret/value.rs @@ -65,7 +65,7 @@ impl<'tcx> ConstValue<'tcx> { pub fn new_slice( val: Scalar, len: u64, - cx: impl HasDataLayout + cx: &impl HasDataLayout ) -> Self { ConstValue::ScalarPair(val, Scalar::Bits { bits: len as u128, @@ -121,7 +121,7 @@ impl<'tcx, Tag> Scalar { } #[inline] - pub fn ptr_null(cx: impl HasDataLayout) -> Self { + pub fn ptr_null(cx: &impl HasDataLayout) -> Self { Scalar::Bits { bits: 0, size: cx.data_layout().pointer_size.bytes() as u8, @@ -134,52 +134,52 @@ impl<'tcx, Tag> Scalar { } #[inline] - pub fn ptr_signed_offset(self, i: i64, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { - let layout = cx.data_layout(); + pub fn ptr_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> { + let dl = cx.data_layout(); match self { Scalar::Bits { bits, size } => { - assert_eq!(size as u64, layout.pointer_size.bytes()); + assert_eq!(size as u64, dl.pointer_size.bytes()); Ok(Scalar::Bits { - bits: layout.signed_offset(bits as u64, i)? as u128, + bits: dl.signed_offset(bits as u64, i)? as u128, size, }) } - Scalar::Ptr(ptr) => ptr.signed_offset(i, layout).map(Scalar::Ptr), + Scalar::Ptr(ptr) => ptr.signed_offset(i, dl).map(Scalar::Ptr), } } #[inline] - pub fn ptr_offset(self, i: Size, cx: impl HasDataLayout) -> EvalResult<'tcx, Self> { - let layout = cx.data_layout(); + pub fn ptr_offset(self, i: Size, cx: &impl HasDataLayout) -> EvalResult<'tcx, Self> { + let dl = cx.data_layout(); match self { Scalar::Bits { bits, size } => { - assert_eq!(size as u64, layout.pointer_size.bytes()); + assert_eq!(size as u64, dl.pointer_size.bytes()); Ok(Scalar::Bits { - bits: layout.offset(bits as u64, i.bytes())? as u128, + bits: dl.offset(bits as u64, i.bytes())? as u128, size, }) } - Scalar::Ptr(ptr) => ptr.offset(i, layout).map(Scalar::Ptr), + Scalar::Ptr(ptr) => ptr.offset(i, dl).map(Scalar::Ptr), } } #[inline] - pub fn ptr_wrapping_signed_offset(self, i: i64, cx: impl HasDataLayout) -> Self { - let layout = cx.data_layout(); + pub fn ptr_wrapping_signed_offset(self, i: i64, cx: &impl HasDataLayout) -> Self { + let dl = cx.data_layout(); match self { Scalar::Bits { bits, size } => { - assert_eq!(size as u64, layout.pointer_size.bytes()); + assert_eq!(size as u64, dl.pointer_size.bytes()); Scalar::Bits { - bits: layout.wrapping_signed_offset(bits as u64, i) as u128, + bits: dl.wrapping_signed_offset(bits as u64, i) as u128, size, } } - Scalar::Ptr(ptr) => Scalar::Ptr(ptr.wrapping_signed_offset(i, layout)), + Scalar::Ptr(ptr) => Scalar::Ptr(ptr.wrapping_signed_offset(i, dl)), } } #[inline] - pub fn is_null_ptr(self, cx: impl HasDataLayout) -> bool { + pub fn is_null_ptr(self, cx: &impl HasDataLayout) -> bool { match self { Scalar::Bits { bits, size } => { assert_eq!(size as u64, cx.data_layout().pointer_size.bytes()); @@ -301,7 +301,7 @@ impl<'tcx, Tag> Scalar { Ok(b as u64) } - pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'static, u64> { + pub fn to_usize(self, cx: &impl HasDataLayout) -> EvalResult<'static, u64> { let b = self.to_bits(cx.data_layout().pointer_size)?; assert_eq!(b as u64 as u128, b); Ok(b as u64) @@ -331,7 +331,7 @@ impl<'tcx, Tag> Scalar { Ok(b as i64) } - pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'static, i64> { + pub fn to_isize(self, cx: &impl HasDataLayout) -> EvalResult<'static, i64> { let b = self.to_bits(cx.data_layout().pointer_size)?; let b = sign_extend(b, cx.data_layout().pointer_size) as i128; assert_eq!(b as i64 as i128, b); diff --git a/src/librustc/traits/error_reporting.rs b/src/librustc/traits/error_reporting.rs index e6ae0557c33af..fbada789956be 100644 --- a/src/librustc/traits/error_reporting.rs +++ b/src/librustc/traits/error_reporting.rs @@ -428,7 +428,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> { )); let tcx = self.tcx; if let Some(len) = len.val.try_to_scalar().and_then(|scalar| { - scalar.to_usize(tcx).ok() + scalar.to_usize(&tcx).ok() }) { flags.push(( "_Self".to_owned(), diff --git a/src/librustc/ty/layout.rs b/src/librustc/ty/layout.rs index 5500572161735..5aeba652f3228 100644 --- a/src/librustc/ty/layout.rs +++ b/src/librustc/ty/layout.rs @@ -30,7 +30,7 @@ pub use rustc_target::abi::*; pub trait IntegerExt { fn to_ty<'a, 'tcx>(&self, tcx: TyCtxt<'a, 'tcx, 'tcx>, signed: bool) -> Ty<'tcx>; - fn from_attr(cx: C, ity: attr::IntType) -> Integer; + fn from_attr(cx: &C, ity: attr::IntType) -> Integer; fn repr_discr<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>, ty: Ty<'tcx>, repr: &ReprOptions, @@ -56,7 +56,7 @@ impl IntegerExt for Integer { } /// Get the Integer type from an attr::IntType. - fn from_attr(cx: C, ity: attr::IntType) -> Integer { + fn from_attr(cx: &C, ity: attr::IntType) -> Integer { let dl = cx.data_layout(); match ity { @@ -92,7 +92,7 @@ impl IntegerExt for Integer { let min_default = I8; if let Some(ity) = repr.int { - let discr = Integer::from_attr(tcx, ity); + let discr = Integer::from_attr(&tcx, ity); let fit = if ity.is_signed() { signed_fit } else { unsigned_fit }; if discr < fit { bug!("Integer::repr_discr: `#[repr]` hint too small for \ @@ -202,14 +202,13 @@ pub fn provide(providers: &mut ty::query::Providers<'_>) { }; } -#[derive(Copy, Clone)] pub struct LayoutCx<'tcx, C> { pub tcx: C, pub param_env: ty::ParamEnv<'tcx> } impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { - fn layout_raw_uncached(self, ty: Ty<'tcx>) + fn layout_raw_uncached(&self, ty: Ty<'tcx>) -> Result<&'tcx LayoutDetails, LayoutError<'tcx>> { let tcx = self.tcx; let param_env = self.param_env; @@ -899,7 +898,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { let (mut min, mut max) = (i128::max_value(), i128::min_value()); let discr_type = def.repr.discr_type(); - let bits = Integer::from_attr(tcx, discr_type).size().bits(); + let bits = Integer::from_attr(self, discr_type).size().bits(); for (i, discr) in def.discriminants(tcx).enumerate() { if variants[i].iter().any(|f| f.abi.is_uninhabited()) { continue; @@ -1141,7 +1140,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { /// This is invoked by the `layout_raw` query to record the final /// layout of each type. #[inline] - fn record_layout_for_printing(self, layout: TyLayout<'tcx>) { + fn record_layout_for_printing(&self, layout: TyLayout<'tcx>) { // If we are running with `-Zprint-type-sizes`, record layouts for // dumping later. Ignore layouts that are done with non-empty // environments or non-monomorphic layouts, as the user only wants @@ -1158,7 +1157,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { self.record_layout_for_printing_outlined(layout) } - fn record_layout_for_printing_outlined(self, layout: TyLayout<'tcx>) { + fn record_layout_for_printing_outlined(&self, layout: TyLayout<'tcx>) { // (delay format until we actually need it) let record = |kind, packed, opt_discr_size, variants| { let type_desc = format!("{:?}", layout.ty); @@ -1478,7 +1477,7 @@ impl<'a, 'tcx> LayoutOf for LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { let param_env = self.param_env.with_reveal_all(); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let details = self.tcx.layout_raw(param_env.and(ty))?; @@ -1505,7 +1504,7 @@ impl<'a, 'tcx> LayoutOf for LayoutCx<'tcx, ty::query::TyCtxtAt<'a, 'tcx, 'tcx>> /// Computes the layout of a type. Note that this implicitly /// executes in "reveal all" mode. - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { let param_env = self.param_env.with_reveal_all(); let ty = self.tcx.normalize_erasing_regions(param_env, ty); let details = self.tcx.layout_raw(param_env.and(ty))?; @@ -1563,7 +1562,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> where C: LayoutOf> + HasTyCtxt<'tcx>, C::TyLayout: MaybeResult> { - fn for_variant(this: TyLayout<'tcx>, cx: C, variant_index: usize) -> TyLayout<'tcx> { + fn for_variant(this: TyLayout<'tcx>, cx: &C, variant_index: usize) -> TyLayout<'tcx> { let details = match this.variants { Variants::Single { index } if index == variant_index => this.details, @@ -1602,7 +1601,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> } } - fn field(this: TyLayout<'tcx>, cx: C, i: usize) -> C::TyLayout { + fn field(this: TyLayout<'tcx>, cx: &C, i: usize) -> C::TyLayout { let tcx = cx.tcx(); cx.layout_of(match this.ty.sty { ty::Bool | @@ -1699,7 +1698,7 @@ impl<'a, 'tcx, C> TyLayoutMethods<'tcx, C> for Ty<'tcx> Variants::Tagged { tag: ref discr, .. } | Variants::NicheFilling { niche: ref discr, .. } => { assert_eq!(i, 0); - let layout = LayoutDetails::scalar(tcx, discr.clone()); + let layout = LayoutDetails::scalar(cx, discr.clone()); return MaybeResult::from_ok(TyLayout { details: tcx.intern_layout(layout), ty: discr.value.to_ty(tcx) @@ -1725,7 +1724,7 @@ struct Niche { impl Niche { fn reserve<'a, 'tcx>( &self, - cx: LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>>, + cx: &LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>>, count: u128, ) -> Option<(u128, Scalar)> { if count > self.available { @@ -1745,7 +1744,7 @@ impl<'a, 'tcx> LayoutCx<'tcx, TyCtxt<'a, 'tcx, 'tcx>> { /// Find the offset of a niche leaf field, starting from /// the given type and recursing through aggregates. // FIXME(eddyb) traverse already optimized enums. - fn find_niche(self, layout: TyLayout<'tcx>) -> Result, LayoutError<'tcx>> { + fn find_niche(&self, layout: TyLayout<'tcx>) -> Result, LayoutError<'tcx>> { let scalar_niche = |scalar: &Scalar, offset| { let Scalar { value, valid_range: ref v } = *scalar; diff --git a/src/librustc/ty/util.rs b/src/librustc/ty/util.rs index 9ba5bf9add110..3d0c54d6b0a5b 100644 --- a/src/librustc/ty/util.rs +++ b/src/librustc/ty/util.rs @@ -43,7 +43,7 @@ impl<'tcx> fmt::Display for Discr<'tcx> { match self.ty.sty { ty::Int(ity) => { let bits = ty::tls::with(|tcx| { - Integer::from_attr(tcx, SignedInt(ity)).size().bits() + Integer::from_attr(&tcx, SignedInt(ity)).size().bits() }); let x = self.val as i128; // sign extend the raw representation to be an i128 @@ -62,8 +62,8 @@ impl<'tcx> Discr<'tcx> { } pub fn checked_add<'a, 'gcx>(self, tcx: TyCtxt<'a, 'gcx, 'tcx>, n: u128) -> (Self, bool) { let (int, signed) = match self.ty.sty { - Int(ity) => (Integer::from_attr(tcx, SignedInt(ity)), true), - Uint(uty) => (Integer::from_attr(tcx, UnsignedInt(uty)), false), + Int(ity) => (Integer::from_attr(&tcx, SignedInt(ity)), true), + Uint(uty) => (Integer::from_attr(&tcx, UnsignedInt(uty)), false), _ => bug!("non integer discriminant"), }; diff --git a/src/librustc_codegen_llvm/context.rs b/src/librustc_codegen_llvm/context.rs index 241f7989e1681..120449ae2af4c 100644 --- a/src/librustc_codegen_llvm/context.rs +++ b/src/librustc_codegen_llvm/context.rs @@ -446,29 +446,29 @@ impl<'b, 'tcx> CodegenCx<'b, 'tcx> { } } -impl ty::layout::HasDataLayout for &'a CodegenCx<'ll, 'tcx> { +impl ty::layout::HasDataLayout for CodegenCx<'ll, 'tcx> { fn data_layout(&self) -> &ty::layout::TargetDataLayout { &self.tcx.data_layout } } -impl HasTargetSpec for &'a CodegenCx<'ll, 'tcx> { +impl HasTargetSpec for CodegenCx<'ll, 'tcx> { fn target_spec(&self) -> &Target { &self.tcx.sess.target.target } } -impl ty::layout::HasTyCtxt<'tcx> for &'a CodegenCx<'ll, 'tcx> { - fn tcx<'b>(&'b self) -> TyCtxt<'b, 'tcx, 'tcx> { +impl ty::layout::HasTyCtxt<'tcx> for CodegenCx<'ll, 'tcx> { + fn tcx<'a>(&'a self) -> TyCtxt<'a, 'tcx, 'tcx> { self.tcx } } -impl LayoutOf for &'a CodegenCx<'ll, 'tcx> { +impl LayoutOf for CodegenCx<'ll, 'tcx> { type Ty = Ty<'tcx>; type TyLayout = TyLayout<'tcx>; - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(ty::ParamEnv::reveal_all().and(ty)) .unwrap_or_else(|e| if let LayoutError::SizeOverflow(_) = e { self.sess().fatal(&e.to_string()) diff --git a/src/librustc_codegen_llvm/mir/constant.rs b/src/librustc_codegen_llvm/mir/constant.rs index 1f66ee36170dc..586a490774023 100644 --- a/src/librustc_codegen_llvm/mir/constant.rs +++ b/src/librustc_codegen_llvm/mir/constant.rs @@ -87,8 +87,8 @@ pub fn scalar_to_llvm( pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll Value { let mut llvals = Vec::with_capacity(alloc.relocations.len() + 1); - let layout = cx.data_layout(); - let pointer_size = layout.pointer_size.bytes() as usize; + let dl = cx.data_layout(); + let pointer_size = dl.pointer_size.bytes() as usize; let mut next_offset = 0; for &(offset, ((), alloc_id)) in alloc.relocations.iter() { @@ -99,7 +99,7 @@ pub fn const_alloc_to_llvm(cx: &CodegenCx<'ll, '_>, alloc: &Allocation) -> &'ll llvals.push(C_bytes(cx, &alloc.bytes[next_offset..offset])); } let ptr_offset = read_target_uint( - layout.endian, + dl.endian, &alloc.bytes[offset..(offset + pointer_size)], ).expect("const_alloc_to_llvm: could not read relocation pointer") as u64; llvals.push(scalar_to_llvm( diff --git a/src/librustc_lint/types.rs b/src/librustc_lint/types.rs index 2e19b441d0e39..0b788a8fd9763 100644 --- a/src/librustc_lint/types.rs +++ b/src/librustc_lint/types.rs @@ -377,13 +377,13 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for TypeLimits { let (t, actually) = match ty { ty::Int(t) => { let ity = attr::IntType::SignedInt(t); - let bits = layout::Integer::from_attr(cx.tcx, ity).size().bits(); + let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits(); let actually = (val << (128 - bits)) as i128 >> (128 - bits); (format!("{:?}", t), actually.to_string()) } ty::Uint(t) => { let ity = attr::IntType::UnsignedInt(t); - let bits = layout::Integer::from_attr(cx.tcx, ity).size().bits(); + let bits = layout::Integer::from_attr(&cx.tcx, ity).size().bits(); let actually = (val << (128 - bits)) >> (128 - bits); (format!("{:?}", t), actually.to_string()) } @@ -829,7 +829,7 @@ impl<'a, 'tcx> LateLintPass<'a, 'tcx> for VariantSizeDifferences { Ok(layout) => { let variants = &layout.variants; if let layout::Variants::Tagged { ref variants, ref tag, .. } = variants { - let discr_size = tag.value.size(cx.tcx).bytes(); + let discr_size = tag.value.size(&cx.tcx).bytes(); debug!("enum `{}` is {} bytes large with layout:\n{:#?}", t, layout.size.bytes(), layout); diff --git a/src/librustc_mir/hair/cx/mod.rs b/src/librustc_mir/hair/cx/mod.rs index 5f798135966d4..3a56d261111ee 100644 --- a/src/librustc_mir/hair/cx/mod.rs +++ b/src/librustc_mir/hair/cx/mod.rs @@ -165,7 +165,7 @@ impl<'a, 'gcx, 'tcx> Cx<'a, 'gcx, 'tcx> { LitKind::Str(ref s, _) => { let s = s.as_str(); let id = self.tcx.allocate_bytes(s.as_bytes()); - ConstValue::new_slice(Scalar::Ptr(id.into()), s.len() as u64, self.tcx) + ConstValue::new_slice(Scalar::Ptr(id.into()), s.len() as u64, &self.tcx) }, LitKind::ByteStr(ref data) => { let id = self.tcx.allocate_bytes(data); diff --git a/src/librustc_mir/hair/pattern/_match.rs b/src/librustc_mir/hair/pattern/_match.rs index d53bb1dc4d63a..69ca21c56242f 100644 --- a/src/librustc_mir/hair/pattern/_match.rs +++ b/src/librustc_mir/hair/pattern/_match.rs @@ -669,14 +669,14 @@ fn all_constructors<'a, 'tcx: 'a>(cx: &mut MatchCheckCtxt<'a, 'tcx>, } ty::Int(ity) if exhaustive_integer_patterns => { // FIXME(49937): refactor these bit manipulations into interpret. - let bits = Integer::from_attr(cx.tcx, SignedInt(ity)).size().bits() as u128; + let bits = Integer::from_attr(&cx.tcx, SignedInt(ity)).size().bits() as u128; let min = 1u128 << (bits - 1); let max = (1u128 << (bits - 1)) - 1; vec![ConstantRange(min, max, pcx.ty, RangeEnd::Included)] } ty::Uint(uty) if exhaustive_integer_patterns => { // FIXME(49937): refactor these bit manipulations into interpret. - let bits = Integer::from_attr(cx.tcx, UnsignedInt(uty)).size().bits() as u128; + let bits = Integer::from_attr(&cx.tcx, UnsignedInt(uty)).size().bits() as u128; let max = !0u128 >> (128 - bits); vec![ConstantRange(0, max, pcx.ty, RangeEnd::Included)] } @@ -862,7 +862,7 @@ impl<'tcx> IntRange<'tcx> { fn signed_bias(tcx: TyCtxt<'_, 'tcx, 'tcx>, ty: Ty<'tcx>) -> u128 { match ty.sty { ty::Int(ity) => { - let bits = Integer::from_attr(tcx, SignedInt(ity)).size().bits() as u128; + let bits = Integer::from_attr(&tcx, SignedInt(ity)).size().bits() as u128; 1u128 << (bits - 1) } _ => 0 diff --git a/src/librustc_mir/hair/pattern/mod.rs b/src/librustc_mir/hair/pattern/mod.rs index bff87da9c771d..0e1f8d1d32816 100644 --- a/src/librustc_mir/hair/pattern/mod.rs +++ b/src/librustc_mir/hair/pattern/mod.rs @@ -1313,7 +1313,7 @@ fn lit_to_const<'a, 'tcx>(lit: &'tcx ast::LitKind, LitKind::Str(ref s, _) => { let s = s.as_str(); let id = tcx.allocate_bytes(s.as_bytes()); - ConstValue::new_slice(Scalar::Ptr(id.into()), s.len() as u64, tcx) + ConstValue::new_slice(Scalar::Ptr(id.into()), s.len() as u64, &tcx) }, LitKind::ByteStr(ref data) => { let id = tcx.allocate_bytes(data); diff --git a/src/librustc_mir/interpret/cast.rs b/src/librustc_mir/interpret/cast.rs index 01dd995bbeec0..06748d60e4583 100644 --- a/src/librustc_mir/interpret/cast.rs +++ b/src/librustc_mir/interpret/cast.rs @@ -331,7 +331,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> let val = Immediate::new_slice( ptr, length.unwrap_usize(self.tcx.tcx), - self.tcx.tcx, + self, ); self.write_immediate(val, dest) } @@ -394,7 +394,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> src_field.into() } Err(..) => { - let src_field_layout = src.layout.field(&self, i)?; + let src_field_layout = src.layout.field(self, i)?; // this must be a field covering the entire thing assert_eq!(src.layout.fields.offset(i).bytes(), 0); assert_eq!(src_field_layout.size, src.layout.size); diff --git a/src/librustc_mir/interpret/eval_context.rs b/src/librustc_mir/interpret/eval_context.rs index 8cb3f9d4d7481..fc13c5fef2dda 100644 --- a/src/librustc_mir/interpret/eval_context.rs +++ b/src/librustc_mir/interpret/eval_context.rs @@ -139,8 +139,8 @@ impl<'tcx, Tag> LocalValue { } } -impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout - for &'b EvalContext<'a, 'mir, 'tcx, M> +impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout + for EvalContext<'a, 'mir, 'tcx, M> { #[inline] fn data_layout(&self) -> &layout::TargetDataLayout { @@ -148,16 +148,7 @@ impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout } } -impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout - for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M> -{ - #[inline] - fn data_layout(&self) -> &layout::TargetDataLayout { - &self.tcx.data_layout - } -} - -impl<'b, 'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &'b EvalContext<'a, 'mir, 'tcx, M> +impl<'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for EvalContext<'a, 'mir, 'tcx, M> where M: Machine<'a, 'mir, 'tcx> { #[inline] @@ -166,40 +157,19 @@ impl<'b, 'a, 'mir, 'tcx, M> layout::HasTyCtxt<'tcx> for &'b EvalContext<'a, 'mir } } -impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> layout::HasTyCtxt<'tcx> - for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M> -{ - #[inline] - fn tcx<'d>(&'d self) -> TyCtxt<'d, 'tcx, 'tcx> { - *self.tcx - } -} - -impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf - for &'b EvalContext<'a, 'mir, 'tcx, M> +impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf + for EvalContext<'a, 'mir, 'tcx, M> { type Ty = Ty<'tcx>; type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>; #[inline] - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) .map_err(|layout| EvalErrorKind::Layout(layout).into()) } } -impl<'c, 'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> LayoutOf - for &'c &'b mut EvalContext<'a, 'mir, 'tcx, M> -{ - type Ty = Ty<'tcx>; - type TyLayout = EvalResult<'tcx, TyLayout<'tcx>>; - - #[inline] - fn layout_of(self, ty: Ty<'tcx>) -> Self::TyLayout { - (&**self).layout_of(ty) - } -} - impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> { pub fn new( tcx: TyCtxtAt<'a, 'tcx, 'tcx>, @@ -335,7 +305,7 @@ impl<'a, 'mir, 'tcx: 'mir, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tc pub fn str_to_immediate(&mut self, s: &str) -> EvalResult<'tcx, Immediate> { let ptr = self.memory.allocate_static_bytes(s.as_bytes()).with_default_tag(); - Ok(Immediate::new_slice(Scalar::Ptr(ptr), s.len() as u64, self.tcx.tcx)) + Ok(Immediate::new_slice(Scalar::Ptr(ptr), s.len() as u64, self)) } /// Return the actual dynamic size and alignment of the place at the given type. diff --git a/src/librustc_mir/interpret/memory.rs b/src/librustc_mir/interpret/memory.rs index a9ef35845fc82..a0231f3feb13a 100644 --- a/src/librustc_mir/interpret/memory.rs +++ b/src/librustc_mir/interpret/memory.rs @@ -77,16 +77,8 @@ pub struct Memory<'a, 'mir, 'tcx: 'a + 'mir, M: Machine<'a, 'mir, 'tcx>> { pub(super) tcx: TyCtxtAt<'a, 'tcx, 'tcx>, } -impl<'b, 'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout - for &'b Memory<'a, 'mir, 'tcx, M> -{ - #[inline] - fn data_layout(&self) -> &TargetDataLayout { - &self.tcx.data_layout - } -} -impl<'a, 'b, 'c, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout - for &'b &'c mut Memory<'a, 'mir, 'tcx, M> +impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> HasDataLayout + for Memory<'a, 'mir, 'tcx, M> { #[inline] fn data_layout(&self) -> &TargetDataLayout { diff --git a/src/librustc_mir/interpret/operand.rs b/src/librustc_mir/interpret/operand.rs index 0da0300944830..6f66dd1e70a55 100644 --- a/src/librustc_mir/interpret/operand.rs +++ b/src/librustc_mir/interpret/operand.rs @@ -112,7 +112,7 @@ impl<'tcx, Tag> ScalarMaybeUndef { } #[inline(always)] - pub fn to_usize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> { + pub fn to_usize(self, cx: &impl HasDataLayout) -> EvalResult<'tcx, u64> { self.not_undef()?.to_usize(cx) } @@ -132,7 +132,7 @@ impl<'tcx, Tag> ScalarMaybeUndef { } #[inline(always)] - pub fn to_isize(self, cx: impl HasDataLayout) -> EvalResult<'tcx, i64> { + pub fn to_isize(self, cx: &impl HasDataLayout) -> EvalResult<'tcx, i64> { self.not_undef()?.to_isize(cx) } } @@ -178,7 +178,7 @@ impl<'tcx, Tag> Immediate { pub fn new_slice( val: Scalar, len: u64, - cx: impl HasDataLayout + cx: &impl HasDataLayout ) -> Self { Immediate::ScalarPair( val.into(), @@ -743,7 +743,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> .ty_adt_def().expect("tagged layout corresponds to adt") .repr .discr_type(); - let discr_ty = layout::Integer::from_attr(self.tcx.tcx, discr_ty); + let discr_ty = layout::Integer::from_attr(self, discr_ty); let shift = 128 - discr_ty.size().bits(); let truncatee = sexted as u128; (truncatee << shift) >> shift diff --git a/src/librustc_mir/interpret/place.rs b/src/librustc_mir/interpret/place.rs index 58e4e3ce96b0b..fa4d31846df4a 100644 --- a/src/librustc_mir/interpret/place.rs +++ b/src/librustc_mir/interpret/place.rs @@ -128,7 +128,7 @@ impl MemPlace { /// Produces a Place that will error if attempted to be read from or written to #[inline(always)] - pub fn null(cx: impl HasDataLayout) -> Self { + pub fn null(cx: &impl HasDataLayout) -> Self { Self::from_scalar_ptr(Scalar::ptr_null(cx), Align::from_bytes(1, 1).unwrap()) } @@ -156,7 +156,7 @@ impl MemPlace { impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { /// Produces a MemPlace that works for ZST but nothing else #[inline] - pub fn dangling(layout: TyLayout<'tcx>, cx: impl HasDataLayout) -> Self { + pub fn dangling(layout: TyLayout<'tcx>, cx: &impl HasDataLayout) -> Self { MPlaceTy { mplace: MemPlace::from_scalar_ptr( Scalar::from_uint(layout.align.abi(), cx.pointer_size()), @@ -172,7 +172,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> { } #[inline] - pub(super) fn len(self, cx: impl HasDataLayout) -> EvalResult<'tcx, u64> { + pub(super) fn len(self, cx: &impl HasDataLayout) -> EvalResult<'tcx, u64> { if self.layout.is_unsized() { // We need to consult `meta` metadata match self.layout.ty.sty { @@ -217,7 +217,7 @@ impl<'tcx, Tag: ::std::fmt::Debug> OpTy<'tcx, Tag> { impl<'tcx, Tag: ::std::fmt::Debug> Place { /// Produces a Place that will error if attempted to be read from or written to #[inline(always)] - pub fn null(cx: impl HasDataLayout) -> Self { + pub fn null(cx: &impl HasDataLayout) -> Self { Place::Ptr(MemPlace::null(cx)) } @@ -510,7 +510,7 @@ where Place::Ptr(mplace) => self.mplace_downcast(MPlaceTy { mplace, layout: base.layout }, variant)?.into(), Place::Local { .. } => { - let layout = base.layout.for_variant(&self, variant); + let layout = base.layout.for_variant(self, variant); PlaceTy { layout, ..base } } }) @@ -738,10 +738,10 @@ where _ => bug!("write_immediate_to_mplace: invalid ScalarPair layout: {:#?}", dest.layout) }; - let (a_size, b_size) = (a.size(&self), b.size(&self)); - let (a_align, b_align) = (a.align(&self), b.align(&self)); + let (a_size, b_size) = (a.size(self), b.size(self)); + let (a_align, b_align) = (a.align(self), b.align(self)); let b_offset = a_size.abi_align(b_align); - let b_ptr = ptr.offset(b_offset, &self)?.into(); + let b_ptr = ptr.offset(b_offset, self)?.into(); // It is tempting to verify `b_offset` against `layout.fields.offset(1)`, // but that does not work: We could be a newtype around a pair, then the @@ -896,7 +896,7 @@ where if layout.is_unsized() { assert!(self.tcx.features().unsized_locals, "cannot alloc memory for unsized type"); // FIXME: What should we do here? We should definitely also tag! - Ok(MPlaceTy::dangling(layout, &self)) + Ok(MPlaceTy::dangling(layout, self)) } else { let ptr = self.memory.allocate(layout.size, layout.align, kind)?; let ptr = M::tag_new_allocation(self, ptr, kind)?; @@ -923,7 +923,7 @@ where // raw discriminants for enums are isize or bigger during // their computation, but the in-memory tag is the smallest possible // representation - let size = tag.value.size(self.tcx.tcx); + let size = tag.value.size(self); let shift = 128 - size.bits(); let discr_val = (discr_val << shift) >> shift; diff --git a/src/librustc_mir/interpret/step.rs b/src/librustc_mir/interpret/step.rs index ea8fcfe260b79..db055204c0a19 100644 --- a/src/librustc_mir/interpret/step.rs +++ b/src/librustc_mir/interpret/step.rs @@ -217,7 +217,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> Repeat(ref operand, _) => { let op = self.eval_operand(operand, None)?; let dest = self.force_allocation(dest)?; - let length = dest.len(&self)?; + let length = dest.len(self)?; if length > 0 { // write the first @@ -227,7 +227,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> if length > 1 { // copy the rest let (dest, dest_align) = first.to_scalar_ptr_align(); - let rest = dest.ptr_offset(first.layout.size, &self)?; + let rest = dest.ptr_offset(first.layout.size, self)?; self.memory.copy_repeatedly( dest, dest_align, rest, dest_align, first.layout.size, length - 1, true )?; @@ -239,7 +239,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> // FIXME(CTFE): don't allow computing the length of arrays in const eval let src = self.eval_place(place)?; let mplace = self.force_allocation(src)?; - let len = mplace.len(&self)?; + let len = mplace.len(self)?; let size = self.pointer_size(); self.write_scalar( Scalar::from_uint(len, size), diff --git a/src/librustc_mir/interpret/terminator.rs b/src/librustc_mir/interpret/terminator.rs index 44262aeae0214..b5df625b3028b 100644 --- a/src/librustc_mir/interpret/terminator.rs +++ b/src/librustc_mir/interpret/terminator.rs @@ -405,7 +405,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> let ptr = self.ref_to_mplace(self.read_immediate(args[0])?)?; let vtable = ptr.vtable()?; let fn_ptr = self.memory.read_ptr_sized( - vtable.offset(ptr_size * (idx as u64 + 3), &self)?, + vtable.offset(ptr_size * (idx as u64 + 3), self)?, ptr_align )?.to_ptr()?; let instance = self.memory.get_fn(fn_ptr)?; @@ -416,7 +416,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> let mut args = args.to_vec(); let pointee = args[0].layout.ty.builtin_deref(true).unwrap().ty; let fake_fat_ptr_ty = self.tcx.mk_mut_ptr(pointee); - args[0].layout = self.layout_of(fake_fat_ptr_ty)?.field(&self, 0)?; + args[0].layout = self.layout_of(fake_fat_ptr_ty)?.field(self, 0)?; args[0].op = Operand::Immediate(Immediate::Scalar(ptr.ptr.into())); // strip vtable trace!("Patched self operand to {:#?}", args[0]); // recurse with concrete function @@ -455,7 +455,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> }; let ty = self.tcx.mk_unit(); // return type is () - let dest = MPlaceTy::dangling(self.layout_of(ty)?, &self); + let dest = MPlaceTy::dangling(self.layout_of(ty)?, self); self.eval_fn_call( instance, diff --git a/src/librustc_mir/interpret/traits.rs b/src/librustc_mir/interpret/traits.rs index c189ec0ca5c77..c5366a5ce6a4d 100644 --- a/src/librustc_mir/interpret/traits.rs +++ b/src/librustc_mir/interpret/traits.rs @@ -60,9 +60,9 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> let drop = self.memory.create_fn_alloc(drop).with_default_tag(); self.memory.write_ptr_sized(vtable, ptr_align, Scalar::Ptr(drop).into())?; - let size_ptr = vtable.offset(ptr_size, &self)?; + let size_ptr = vtable.offset(ptr_size, self)?; self.memory.write_ptr_sized(size_ptr, ptr_align, Scalar::from_uint(size, ptr_size).into())?; - let align_ptr = vtable.offset(ptr_size * 2, &self)?; + let align_ptr = vtable.offset(ptr_size * 2, self)?; self.memory.write_ptr_sized(align_ptr, ptr_align, Scalar::from_uint(align, ptr_size).into())?; @@ -70,7 +70,7 @@ impl<'a, 'mir, 'tcx, M: Machine<'a, 'mir, 'tcx>> EvalContext<'a, 'mir, 'tcx, M> if let Some((def_id, substs)) = *method { let instance = self.resolve(def_id, substs)?; let fn_ptr = self.memory.create_fn_alloc(instance).with_default_tag(); - let method_ptr = vtable.offset(ptr_size * (3 + i as u64), &self)?; + let method_ptr = vtable.offset(ptr_size * (3 + i as u64), self)?; self.memory.write_ptr_sized(method_ptr, ptr_align, Scalar::Ptr(fn_ptr).into())?; } } diff --git a/src/librustc_mir/transform/const_prop.rs b/src/librustc_mir/transform/const_prop.rs index 24d9e761d97db..52ef37ab40e57 100644 --- a/src/librustc_mir/transform/const_prop.rs +++ b/src/librustc_mir/transform/const_prop.rs @@ -87,23 +87,23 @@ struct ConstPropagator<'a, 'mir, 'tcx:'a+'mir> { param_env: ParamEnv<'tcx>, } -impl<'a, 'b, 'tcx> LayoutOf for &'a ConstPropagator<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx> LayoutOf for ConstPropagator<'a, 'b, 'tcx> { type Ty = ty::Ty<'tcx>; type TyLayout = Result, LayoutError<'tcx>>; - fn layout_of(self, ty: ty::Ty<'tcx>) -> Self::TyLayout { + fn layout_of(&self, ty: ty::Ty<'tcx>) -> Self::TyLayout { self.tcx.layout_of(self.param_env.and(ty)) } } -impl<'a, 'b, 'tcx> HasDataLayout for &'a ConstPropagator<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx> HasDataLayout for ConstPropagator<'a, 'b, 'tcx> { #[inline] fn data_layout(&self) -> &TargetDataLayout { &self.tcx.data_layout } } -impl<'a, 'b, 'tcx> HasTyCtxt<'tcx> for &'a ConstPropagator<'a, 'b, 'tcx> { +impl<'a, 'b, 'tcx> HasTyCtxt<'tcx> for ConstPropagator<'a, 'b, 'tcx> { #[inline] fn tcx<'c>(&'c self) -> TyCtxt<'c, 'tcx, 'tcx> { self.tcx diff --git a/src/librustc_target/abi/call/aarch64.rs b/src/librustc_target/abi/call/aarch64.rs index 90b5b97b51ee2..b4d393749c486 100644 --- a/src/librustc_target/abi/call/aarch64.rs +++ b/src/librustc_target/abi/call/aarch64.rs @@ -11,7 +11,7 @@ use abi::call::{FnType, ArgType, Reg, RegKind, Uniform}; use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; -fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) -> Option where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout @@ -41,7 +41,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) }) } -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -75,7 +75,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) ret.make_indirect(); } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -109,7 +109,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) arg.make_indirect(); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/amdgpu.rs b/src/librustc_target/abi/call/amdgpu.rs index 62462f04d8f56..85789d7d4d745 100644 --- a/src/librustc_target/abi/call/amdgpu.rs +++ b/src/librustc_target/abi/call/amdgpu.rs @@ -11,21 +11,21 @@ use abi::call::{ArgType, FnType, }; use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; -fn classify_ret_ty<'a, Ty, C>(_tuncx: C, ret: &mut ArgType<'a, Ty>) +fn classify_ret_ty<'a, Ty, C>(_cx: &C, ret: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { ret.extend_integer_width_to(32); } -fn classify_arg_ty<'a, Ty, C>(_cx: C, arg: &mut ArgType<'a, Ty>) +fn classify_arg_ty<'a, Ty, C>(_cx: &C, arg: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { arg.extend_integer_width_to(32); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/arm.rs b/src/librustc_target/abi/call/arm.rs index 249aad2d937ea..b4ffae7385aa7 100644 --- a/src/librustc_target/abi/call/arm.rs +++ b/src/librustc_target/abi/call/arm.rs @@ -12,7 +12,7 @@ use abi::call::{Conv, FnType, ArgType, Reg, RegKind, Uniform}; use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; use spec::HasTargetSpec; -fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) -> Option where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout @@ -42,7 +42,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) }) } -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>, vfp: bool) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>, vfp: bool) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -77,7 +77,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>, vfp: bool) ret.make_indirect(); } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, vfp: bool) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>, vfp: bool) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -101,7 +101,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, vfp: bool) }); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout + HasTargetSpec { diff --git a/src/librustc_target/abi/call/asmjs.rs b/src/librustc_target/abi/call/asmjs.rs index 81d6f7b134b3e..3bd2594bdb972 100644 --- a/src/librustc_target/abi/call/asmjs.rs +++ b/src/librustc_target/abi/call/asmjs.rs @@ -16,7 +16,7 @@ use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; // See the https://github.com/kripken/emscripten-fastcomp-clang repository. // The class `EmscriptenABIInfo` in `/lib/CodeGen/TargetInfo.cpp` contains the ABI definitions. -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -42,7 +42,7 @@ fn classify_arg_ty(arg: &mut ArgType) { } } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/mips.rs b/src/librustc_target/abi/call/mips.rs index 1e8af52e3e819..a40cb6c76f0cd 100644 --- a/src/librustc_target/abi/call/mips.rs +++ b/src/librustc_target/abi/call/mips.rs @@ -11,7 +11,7 @@ use abi::call::{ArgType, FnType, Reg, Uniform}; use abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods}; -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { if !ret.layout.is_aggregate() { @@ -22,7 +22,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) } } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let dl = cx.data_layout(); @@ -44,7 +44,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) *offset = offset.abi_align(align) + size.abi_align(align); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let mut offset = Size::ZERO; diff --git a/src/librustc_target/abi/call/mips64.rs b/src/librustc_target/abi/call/mips64.rs index 8e2dd99696e17..adf5a3c94ea01 100644 --- a/src/librustc_target/abi/call/mips64.rs +++ b/src/librustc_target/abi/call/mips64.rs @@ -27,7 +27,7 @@ fn extend_integer_width_mips(arg: &mut ArgType, bits: u64) { arg.extend_integer_width_to(bits); } -fn float_reg<'a, Ty, C>(cx: C, ret: &ArgType<'a, Ty>, i: usize) -> Option +fn float_reg<'a, Ty, C>(cx: &C, ret: &ArgType<'a, Ty>, i: usize) -> Option where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -41,7 +41,7 @@ fn float_reg<'a, Ty, C>(cx: C, ret: &ArgType<'a, Ty>, i: usize) -> Option } } -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -83,7 +83,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) } } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -151,7 +151,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) }); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/mod.rs b/src/librustc_target/abi/call/mod.rs index 788497a378fe9..8f9ef2544e602 100644 --- a/src/librustc_target/abi/call/mod.rs +++ b/src/librustc_target/abi/call/mod.rs @@ -137,7 +137,7 @@ impl Reg { } impl Reg { - pub fn align(&self, cx: C) -> Align { + pub fn align(&self, cx: &C) -> Align { let dl = cx.data_layout(); match self.kind { RegKind::Integer => { @@ -188,7 +188,7 @@ impl From for Uniform { } impl Uniform { - pub fn align(&self, cx: C) -> Align { + pub fn align(&self, cx: &C) -> Align { self.unit.align(cx) } } @@ -225,12 +225,12 @@ impl CastTarget { } } - pub fn size(&self, cx: C) -> Size { + pub fn size(&self, cx: &C) -> Size { (self.prefix_chunk * self.prefix.iter().filter(|x| x.is_some()).count() as u64) .abi_align(self.rest.align(cx)) + self.rest.total } - pub fn align(&self, cx: C) -> Align { + pub fn align(&self, cx: &C) -> Align { self.prefix.iter() .filter_map(|x| x.map(|kind| Reg { kind, size: self.prefix_chunk }.align(cx))) .fold(cx.data_layout().aggregate_align.max(self.rest.align(cx)), @@ -249,8 +249,8 @@ impl<'a, Ty> TyLayout<'a, Ty> { } } - fn homogeneous_aggregate(&self, cx: C) -> Option - where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf + Copy + fn homogeneous_aggregate(&self, cx: &C) -> Option + where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf { match self.abi { Abi::Uninhabited => None, @@ -483,7 +483,7 @@ pub struct FnType<'a, Ty> { } impl<'a, Ty> FnType<'a, Ty> { - pub fn adjust_for_cabi(&mut self, cx: C, abi: ::spec::abi::Abi) -> Result<(), String> + pub fn adjust_for_cabi(&mut self, cx: &C, abi: ::spec::abi::Abi) -> Result<(), String> where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout + HasTargetSpec { diff --git a/src/librustc_target/abi/call/powerpc.rs b/src/librustc_target/abi/call/powerpc.rs index 3be3034143a34..b9b012020b7f4 100644 --- a/src/librustc_target/abi/call/powerpc.rs +++ b/src/librustc_target/abi/call/powerpc.rs @@ -11,7 +11,7 @@ use abi::call::{ArgType, FnType, Reg, Uniform}; use abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods}; -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { if !ret.layout.is_aggregate() { @@ -22,7 +22,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) } } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let dl = cx.data_layout(); @@ -44,7 +44,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) *offset = offset.abi_align(align) + size.abi_align(align); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let mut offset = Size::ZERO; diff --git a/src/librustc_target/abi/call/powerpc64.rs b/src/librustc_target/abi/call/powerpc64.rs index 0c5ec77a3982d..80a4d693dc36b 100644 --- a/src/librustc_target/abi/call/powerpc64.rs +++ b/src/librustc_target/abi/call/powerpc64.rs @@ -22,7 +22,7 @@ enum ABI { } use self::ABI::*; -fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, abi: ABI) +fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>, abi: ABI) -> Option where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout @@ -52,7 +52,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, abi: AB }) } -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>, abi: ABI) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>, abi: ABI) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -95,7 +95,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>, abi: ABI) ret.make_indirect(); } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, abi: ABI) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>, abi: ABI) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -134,7 +134,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>, abi: ABI) }); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/s390x.rs b/src/librustc_target/abi/call/s390x.rs index 37be6ea41c63a..d6d8ea719180a 100644 --- a/src/librustc_target/abi/call/s390x.rs +++ b/src/librustc_target/abi/call/s390x.rs @@ -24,7 +24,7 @@ fn classify_ret_ty<'a, Ty, C>(ret: &mut ArgType) } } -fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool +fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool where Ty: TyLayoutMethods<'a, C>, C: LayoutOf> + HasDataLayout { @@ -41,7 +41,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool } } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -67,7 +67,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) } } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/sparc.rs b/src/librustc_target/abi/call/sparc.rs index 1e8af52e3e819..a40cb6c76f0cd 100644 --- a/src/librustc_target/abi/call/sparc.rs +++ b/src/librustc_target/abi/call/sparc.rs @@ -11,7 +11,7 @@ use abi::call::{ArgType, FnType, Reg, Uniform}; use abi::{HasDataLayout, LayoutOf, Size, TyLayoutMethods}; -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { if !ret.layout.is_aggregate() { @@ -22,7 +22,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType, offset: &mut Size) } } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType, offset: &mut Size) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let dl = cx.data_layout(); @@ -44,7 +44,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType, offset: &mut Size) *offset = offset.abi_align(align) + size.abi_align(align); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType) where Ty: TyLayoutMethods<'a, C>, C: LayoutOf + HasDataLayout { let mut offset = Size::ZERO; diff --git a/src/librustc_target/abi/call/sparc64.rs b/src/librustc_target/abi/call/sparc64.rs index a58aebc2ff063..a609feb3f57ec 100644 --- a/src/librustc_target/abi/call/sparc64.rs +++ b/src/librustc_target/abi/call/sparc64.rs @@ -13,7 +13,7 @@ use abi::call::{FnType, ArgType, Reg, RegKind, Uniform}; use abi::{HasDataLayout, LayoutOf, TyLayout, TyLayoutMethods}; -fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn is_homogeneous_aggregate<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) -> Option where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout @@ -41,7 +41,7 @@ fn is_homogeneous_aggregate<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) }) } -fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) +fn classify_ret_ty<'a, Ty, C>(cx: &C, ret: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -69,7 +69,7 @@ fn classify_ret_ty<'a, Ty, C>(cx: C, ret: &mut ArgType<'a, Ty>) ret.make_indirect(); } -fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) +fn classify_arg_ty<'a, Ty, C>(cx: &C, arg: &mut ArgType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -95,7 +95,7 @@ fn classify_arg_ty<'a, Ty, C>(cx: C, arg: &mut ArgType<'a, Ty>) }); } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/call/x86.rs b/src/librustc_target/abi/call/x86.rs index 1dcaafcf77fcf..9a95e5b192b21 100644 --- a/src/librustc_target/abi/call/x86.rs +++ b/src/librustc_target/abi/call/x86.rs @@ -18,7 +18,7 @@ pub enum Flavor { Fastcall } -fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool +fn is_single_fp_element<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>) -> bool where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { @@ -35,7 +35,7 @@ fn is_single_fp_element<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>) -> bool } } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>, flavor: Flavor) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>, flavor: Flavor) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout + HasTargetSpec { diff --git a/src/librustc_target/abi/call/x86_64.rs b/src/librustc_target/abi/call/x86_64.rs index eade086ec48ec..4c9446508939e 100644 --- a/src/librustc_target/abi/call/x86_64.rs +++ b/src/librustc_target/abi/call/x86_64.rs @@ -31,12 +31,12 @@ struct Memory; const LARGEST_VECTOR_SIZE: usize = 512; const MAX_EIGHTBYTES: usize = LARGEST_VECTOR_SIZE / 64; -fn classify_arg<'a, Ty, C>(cx: C, arg: &ArgType<'a, Ty>) +fn classify_arg<'a, Ty, C>(cx: &C, arg: &ArgType<'a, Ty>) -> Result<[Option; MAX_EIGHTBYTES], Memory> where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { - fn classify<'a, Ty, C>(cx: C, layout: TyLayout<'a, Ty>, + fn classify<'a, Ty, C>(cx: &C, layout: TyLayout<'a, Ty>, cls: &mut [Option], off: Size) -> Result<(), Memory> where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout @@ -178,7 +178,7 @@ fn cast_target(cls: &[Option], size: Size) -> CastTarget { target } -pub fn compute_abi_info<'a, Ty, C>(cx: C, fty: &mut FnType<'a, Ty>) +pub fn compute_abi_info<'a, Ty, C>(cx: &C, fty: &mut FnType<'a, Ty>) where Ty: TyLayoutMethods<'a, C> + Copy, C: LayoutOf> + HasDataLayout { diff --git a/src/librustc_target/abi/mod.rs b/src/librustc_target/abi/mod.rs index 1a5d2801af0c5..c7d0469e556a7 100644 --- a/src/librustc_target/abi/mod.rs +++ b/src/librustc_target/abi/mod.rs @@ -203,11 +203,11 @@ impl TargetDataLayout { } } -pub trait HasDataLayout: Copy { +pub trait HasDataLayout { fn data_layout(&self) -> &TargetDataLayout; } -impl<'a> HasDataLayout for &'a TargetDataLayout { +impl HasDataLayout for TargetDataLayout { fn data_layout(&self) -> &TargetDataLayout { self } @@ -267,7 +267,7 @@ impl Size { } #[inline] - pub fn checked_add(self, offset: Size, cx: C) -> Option { + pub fn checked_add(self, offset: Size, cx: &C) -> Option { let dl = cx.data_layout(); let bytes = self.bytes().checked_add(offset.bytes())?; @@ -280,7 +280,7 @@ impl Size { } #[inline] - pub fn checked_mul(self, count: u64, cx: C) -> Option { + pub fn checked_mul(self, count: u64, cx: &C) -> Option { let dl = cx.data_layout(); let bytes = self.bytes().checked_mul(count)?; @@ -457,7 +457,7 @@ impl Integer { } } - pub fn align(self, cx: C) -> Align { + pub fn align(self, cx: &C) -> Align { let dl = cx.data_layout(); match self { @@ -492,7 +492,7 @@ impl Integer { } /// Find the smallest integer with the given alignment. - pub fn for_abi_align(cx: C, align: Align) -> Option { + pub fn for_abi_align(cx: &C, align: Align) -> Option { let dl = cx.data_layout(); let wanted = align.abi(); @@ -505,7 +505,7 @@ impl Integer { } /// Find the largest integer with the given alignment or less. - pub fn approximate_abi_align(cx: C, align: Align) -> Integer { + pub fn approximate_abi_align(cx: &C, align: Align) -> Integer { let dl = cx.data_layout(); let wanted = align.abi(); @@ -571,7 +571,7 @@ pub enum Primitive { } impl<'a, 'tcx> Primitive { - pub fn size(self, cx: C) -> Size { + pub fn size(self, cx: &C) -> Size { let dl = cx.data_layout(); match self { @@ -582,7 +582,7 @@ impl<'a, 'tcx> Primitive { } } - pub fn align(self, cx: C) -> Align { + pub fn align(self, cx: &C) -> Align { let dl = cx.data_layout(); match self { @@ -642,7 +642,7 @@ impl Scalar { /// Returns the valid range as a `x..y` range. /// /// If `x` and `y` are equal, the range is full, not empty. - pub fn valid_range_exclusive(&self, cx: C) -> Range { + pub fn valid_range_exclusive(&self, cx: &C) -> Range { // For a (max) value of -1, max will be `-1 as usize`, which overflows. // However, that is fine here (it would still represent the full range), // i.e., if the range is everything. @@ -854,7 +854,7 @@ pub struct LayoutDetails { } impl LayoutDetails { - pub fn scalar(cx: C, scalar: Scalar) -> Self { + pub fn scalar(cx: &C, scalar: Scalar) -> Self { let size = scalar.value.size(cx); let align = scalar.value.align(cx); LayoutDetails { @@ -891,20 +891,20 @@ pub trait LayoutOf { type Ty; type TyLayout; - fn layout_of(self, ty: Self::Ty) -> Self::TyLayout; + fn layout_of(&self, ty: Self::Ty) -> Self::TyLayout; } pub trait TyLayoutMethods<'a, C: LayoutOf>: Sized { - fn for_variant(this: TyLayout<'a, Self>, cx: C, variant_index: usize) -> TyLayout<'a, Self>; - fn field(this: TyLayout<'a, Self>, cx: C, i: usize) -> C::TyLayout; + fn for_variant(this: TyLayout<'a, Self>, cx: &C, variant_index: usize) -> TyLayout<'a, Self>; + fn field(this: TyLayout<'a, Self>, cx: &C, i: usize) -> C::TyLayout; } impl<'a, Ty> TyLayout<'a, Ty> { - pub fn for_variant(self, cx: C, variant_index: usize) -> Self + pub fn for_variant(self, cx: &C, variant_index: usize) -> Self where Ty: TyLayoutMethods<'a, C>, C: LayoutOf { Ty::for_variant(self, cx, variant_index) } - pub fn field(self, cx: C, i: usize) -> C::TyLayout + pub fn field(self, cx: &C, i: usize) -> C::TyLayout where Ty: TyLayoutMethods<'a, C>, C: LayoutOf { Ty::field(self, cx, i) } diff --git a/src/librustc_target/spec/mod.rs b/src/librustc_target/spec/mod.rs index 49b4d6ec0f954..c8af81c02ea4a 100644 --- a/src/librustc_target/spec/mod.rs +++ b/src/librustc_target/spec/mod.rs @@ -444,11 +444,11 @@ pub struct Target { pub options: TargetOptions, } -pub trait HasTargetSpec: Copy { +pub trait HasTargetSpec { fn target_spec(&self) -> &Target; } -impl<'a> HasTargetSpec for &'a Target { +impl HasTargetSpec for Target { fn target_spec(&self) -> &Target { self }