diff options
| author | Andreas Liljeqvist <bonega@gmail.com> | 2021-08-23 15:44:56 +0200 |
|---|---|---|
| committer | Andreas Liljeqvist <bonega@gmail.com> | 2021-08-23 15:44:56 +0200 |
| commit | 32d7e5b723f97092e392abc33074d8e750a9cb23 (patch) | |
| tree | 8a9f1d692faf310c638b3021cda9afcbbf1da9de | |
| parent | d230b92ba7a2a32000be5e207860aa27d1a11113 (diff) | |
| download | rust-32d7e5b723f97092e392abc33074d8e750a9cb23.tar.gz rust-32d7e5b723f97092e392abc33074d8e750a9cb23.zip | |
add `with_start` and `with_end`
| -rw-r--r-- | compiler/rustc_middle/src/ty/layout.rs | 8 | ||||
| -rw-r--r-- | compiler/rustc_target/src/abi/mod.rs | 12 |
2 files changed, 14 insertions, 6 deletions
diff --git a/compiler/rustc_middle/src/ty/layout.rs b/compiler/rustc_middle/src/ty/layout.rs index 6b628cb041b..dcb56d5b2ba 100644 --- a/compiler/rustc_middle/src/ty/layout.rs +++ b/compiler/rustc_middle/src/ty/layout.rs @@ -529,7 +529,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { }), ty::FnPtr(_) => { let mut ptr = scalar_unit(Pointer); - ptr.valid_range = WrappingRange { start: 1, end: ptr.valid_range.end }; + ptr.valid_range = ptr.valid_range.with_start(1); tcx.intern_layout(Layout::scalar(self, ptr)) } @@ -547,8 +547,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Ref(_, pointee, _) | ty::RawPtr(ty::TypeAndMut { ty: pointee, .. }) => { let mut data_ptr = scalar_unit(Pointer); if !ty.is_unsafe_ptr() { - data_ptr.valid_range = - WrappingRange { start: 1, end: data_ptr.valid_range.end }; + data_ptr.valid_range = data_ptr.valid_range.with_start(1); } let pointee = tcx.normalize_erasing_regions(param_env, pointee); @@ -564,8 +563,7 @@ impl<'tcx> LayoutCx<'tcx, TyCtxt<'tcx>> { ty::Slice(_) | ty::Str => scalar_unit(Int(dl.ptr_sized_integer(), false)), ty::Dynamic(..) => { let mut vtable = scalar_unit(Pointer); - vtable.valid_range = - WrappingRange { start: 1, end: vtable.valid_range.end }; + vtable.valid_range = vtable.valid_range.with_start(1); vtable } _ => return Err(LayoutError::Unknown(unsized_part)), diff --git a/compiler/rustc_target/src/abi/mod.rs b/compiler/rustc_target/src/abi/mod.rs index c9d0b12e739..6e2f8962eef 100644 --- a/compiler/rustc_target/src/abi/mod.rs +++ b/compiler/rustc_target/src/abi/mod.rs @@ -712,6 +712,16 @@ impl WrappingRange { pub fn contains_zero(&self) -> bool { !(self.start <= self.end && self.start != 0) } + + /// Returns new `WrappingRange` with replaced `start` + pub fn with_start(&self, start: u128) -> Self { + Self { start, end: self.end } + } + + /// Returns new `WrappingRange` with replaced `end` + pub fn with_end(&self, end: u128) -> Self { + Self { start: self.start, end } + } } impl fmt::Debug for WrappingRange { @@ -1029,7 +1039,7 @@ impl Niche { return None; } - Some((start, Scalar { value, valid_range: WrappingRange { start: v.start, end } })) + Some((start, Scalar { value, valid_range: v.with_end(end) })) } } |
