Skip to content

Commit 6ead622

Browse files
committed
Auto merge of #75893 - Dylan-DPC:fix/offset-to-u64, r=oli-obk
change offset from u32 to u64 References #71696 r? @oli-obk (closed the earlier pr because the rebase got messed up)
2 parents ffd59bf + f6a4a76 commit 6ead622

File tree

11 files changed

+25
-32
lines changed

11 files changed

+25
-32
lines changed

src/librustc_middle/mir/mod.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -1564,10 +1564,10 @@ pub enum ProjectionElem<V, T> {
15641564
/// ```
15651565
ConstantIndex {
15661566
/// index or -index (in Python terms), depending on from_end
1567-
offset: u32,
1567+
offset: u64,
15681568
/// The thing being indexed must be at least this long. For arrays this
15691569
/// is always the exact length.
1570-
min_length: u32,
1570+
min_length: u64,
15711571
/// Counting backwards from end? This is always false when indexing an
15721572
/// array.
15731573
from_end: bool,
@@ -1578,8 +1578,8 @@ pub enum ProjectionElem<V, T> {
15781578
/// If `from_end` is true `slice[from..slice.len() - to]`.
15791579
/// Otherwise `array[from..to]`.
15801580
Subslice {
1581-
from: u32,
1582-
to: u32,
1581+
from: u64,
1582+
to: u64,
15831583
/// Whether `to` counts from the start or end of the array/slice.
15841584
/// For `PlaceElem`s this is `true` if and only if the base is a slice.
15851585
/// For `ProjectionKind`, this can also be `true` for arrays.
@@ -1616,7 +1616,7 @@ pub type PlaceElem<'tcx> = ProjectionElem<Local, Ty<'tcx>>;
16161616

16171617
// At least on 64 bit systems, `PlaceElem` should not be larger than two pointers.
16181618
#[cfg(target_arch = "x86_64")]
1619-
static_assert_size!(PlaceElem<'_>, 16);
1619+
static_assert_size!(PlaceElem<'_>, 24);
16201620

16211621
/// Alias for projections as they appear in `UserTypeProjection`, where we
16221622
/// need neither the `V` parameter for `Index` nor the `T` for `Field`.
@@ -2330,7 +2330,7 @@ impl<'tcx> UserTypeProjections {
23302330
self.map_projections(|pat_ty_proj| pat_ty_proj.index())
23312331
}
23322332

2333-
pub fn subslice(self, from: u32, to: u32) -> Self {
2333+
pub fn subslice(self, from: u64, to: u64) -> Self {
23342334
self.map_projections(|pat_ty_proj| pat_ty_proj.subslice(from, to))
23352335
}
23362336

@@ -2376,7 +2376,7 @@ impl UserTypeProjection {
23762376
self
23772377
}
23782378

2379-
pub(crate) fn subslice(mut self, from: u32, to: u32) -> Self {
2379+
pub(crate) fn subslice(mut self, from: u64, to: u64) -> Self {
23802380
self.projs.push(ProjectionElem::Subslice { from, to, from_end: true });
23812381
self
23822382
}

src/librustc_mir/borrow_check/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1694,8 +1694,8 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
16941694
desired_action: InitializationRequiringAction,
16951695
place_span: (PlaceRef<'tcx>, Span),
16961696
maybe_uninits: &BitSet<MovePathIndex>,
1697-
from: u32,
1698-
to: u32,
1697+
from: u64,
1698+
to: u64,
16991699
) {
17001700
if let Some(mpi) = self.move_path_for_place(place_span.0) {
17011701
let move_paths = &self.move_data.move_paths;

src/librustc_mir/borrow_check/type_check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -649,7 +649,7 @@ impl<'a, 'b, 'tcx> TypeVerifier<'a, 'b, 'tcx> {
649649
PlaceTy::from_ty(match base_ty.kind {
650650
ty::Array(inner, _) => {
651651
assert!(!from_end, "array subslices should not use from_end");
652-
tcx.mk_array(inner, (to - from) as u64)
652+
tcx.mk_array(inner, to - from)
653653
}
654654
ty::Slice(..) => {
655655
assert!(from_end, "slice subslices should use from_end");

src/librustc_mir/dataflow/move_paths/builder.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ impl<'b, 'a, 'tcx> Gatherer<'b, 'a, 'tcx> {
480480
}
481481
};
482482
let base_ty = base_place.ty(self.builder.body, self.builder.tcx).ty;
483-
let len: u32 = match base_ty.kind {
483+
let len: u64 = match base_ty.kind {
484484
ty::Array(_, size) => {
485485
let length = size.eval_usize(self.builder.tcx, self.builder.param_env);
486486
length

src/librustc_mir/interpret/place.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -549,17 +549,17 @@ where
549549

550550
ConstantIndex { offset, min_length, from_end } => {
551551
let n = base.len(self)?;
552-
if n < u64::from(min_length) {
552+
if n < min_length {
553553
// This can only be reached in ConstProp and non-rustc-MIR.
554554
throw_ub!(BoundsCheckFailed { len: min_length.into(), index: n });
555555
}
556556

557557
let index = if from_end {
558558
assert!(0 < offset && offset <= min_length);
559-
n.checked_sub(u64::from(offset)).unwrap()
559+
n.checked_sub(offset).unwrap()
560560
} else {
561561
assert!(offset < min_length);
562-
u64::from(offset)
562+
offset
563563
};
564564

565565
self.mplace_index(base, index)?

src/librustc_mir/shim.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'a, 'tcx> DropElaborator<'a, 'tcx> for DropShimElaborator<'a, 'tcx> {
295295
fn downcast_subpath(&self, _path: Self::Path, _variant: VariantIdx) -> Option<Self::Path> {
296296
Some(())
297297
}
298-
fn array_subpath(&self, _path: Self::Path, _index: u32, _size: u32) -> Option<Self::Path> {
298+
fn array_subpath(&self, _path: Self::Path, _index: u64, _size: u64) -> Option<Self::Path> {
299299
None
300300
}
301301
}

src/librustc_mir/transform/elaborate_drops.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -219,7 +219,7 @@ impl<'a, 'b, 'tcx> DropElaborator<'a, 'tcx> for Elaborator<'a, 'b, 'tcx> {
219219
})
220220
}
221221

222-
fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option<Self::Path> {
222+
fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option<Self::Path> {
223223
dataflow::move_path_children_matching(self.ctxt.move_data(), path, |e| match e {
224224
ProjectionElem::ConstantIndex { offset, min_length, from_end } => {
225225
debug_assert!(size == min_length, "min_length should be exact for arrays");

src/librustc_mir/util/aggregate.rs

+2-4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use rustc_middle::mir::*;
33
use rustc_middle::ty::{Ty, TyCtxt};
44
use rustc_target::abi::VariantIdx;
55

6+
use std::convert::TryFrom;
67
use std::iter::TrustedLen;
78

89
/// Expand `lhs = Rvalue::Aggregate(kind, operands)` into assignments to the fields.
@@ -52,14 +53,11 @@ pub fn expand_aggregate<'tcx>(
5253
.enumerate()
5354
.map(move |(i, (op, ty))| {
5455
let lhs_field = if let AggregateKind::Array(_) = kind {
55-
// FIXME(eddyb) `offset` should be u64.
56-
let offset = i as u32;
57-
assert_eq!(offset as usize, i);
56+
let offset = u64::try_from(i).unwrap();
5857
tcx.mk_place_elem(
5958
lhs,
6059
ProjectionElem::ConstantIndex {
6160
offset,
62-
// FIXME(eddyb) `min_length` doesn't appear to be used.
6361
min_length: offset + 1,
6462
from_end: false,
6563
},

src/librustc_mir/util/elaborate_drops.rs

+1-6
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,6 @@ use rustc_middle::ty::{self, Ty, TyCtxt};
1010
use rustc_target::abi::VariantIdx;
1111
use std::fmt;
1212

13-
use std::convert::TryInto;
14-
1513
/// The value of an inserted drop flag.
1614
#[derive(Debug, PartialEq, Eq, Copy, Clone)]
1715
pub enum DropFlagState {
@@ -150,7 +148,7 @@ pub trait DropElaborator<'a, 'tcx>: fmt::Debug {
150148
/// If this returns `None`, elements of `path` will not get a dedicated drop flag.
151149
///
152150
/// This is only relevant for array patterns, which can move out of individual array elements.
153-
fn array_subpath(&self, path: Self::Path, index: u32, size: u32) -> Option<Self::Path>;
151+
fn array_subpath(&self, path: Self::Path, index: u64, size: u64) -> Option<Self::Path>;
154152
}
155153

156154
#[derive(Debug)]
@@ -744,9 +742,6 @@ where
744742
let tcx = self.tcx();
745743

746744
if let Some(size) = opt_size {
747-
let size: u32 = size.try_into().unwrap_or_else(|_| {
748-
bug!("move out check isn't implemented for array sizes bigger than u32::MAX");
749-
});
750745
let fields: Vec<(Place<'tcx>, Option<D::Path>)> = (0..size)
751746
.map(|i| {
752747
(

src/librustc_mir_build/build/matches/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -609,8 +609,8 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
609609

610610
PatKind::Array { ref prefix, ref slice, ref suffix }
611611
| PatKind::Slice { ref prefix, ref slice, ref suffix } => {
612-
let from = u32::try_from(prefix.len()).unwrap();
613-
let to = u32::try_from(suffix.len()).unwrap();
612+
let from = u64::try_from(prefix.len()).unwrap();
613+
let to = u64::try_from(suffix.len()).unwrap();
614614
for subpattern in prefix {
615615
self.visit_primary_bindings(subpattern, pattern_user_ty.clone().index(), f);
616616
}

src/librustc_mir_build/build/matches/util.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,17 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
4040

4141
match_pairs.extend(prefix.iter().enumerate().map(|(idx, subpattern)| {
4242
let elem =
43-
ProjectionElem::ConstantIndex { offset: idx as u32, min_length, from_end: false };
43+
ProjectionElem::ConstantIndex { offset: idx as u64, min_length, from_end: false };
4444
let place = tcx.mk_place_elem(*place, elem);
4545
MatchPair::new(place, subpattern)
4646
}));
4747

4848
if let Some(subslice_pat) = opt_slice {
49-
let suffix_len = suffix.len() as u32;
49+
let suffix_len = suffix.len() as u64;
5050
let subslice = tcx.mk_place_elem(
5151
*place,
5252
ProjectionElem::Subslice {
53-
from: prefix.len() as u32,
53+
from: prefix.len() as u64,
5454
to: if exact_size { min_length - suffix_len } else { suffix_len },
5555
from_end: !exact_size,
5656
},
@@ -59,7 +59,7 @@ impl<'a, 'tcx> Builder<'a, 'tcx> {
5959
}
6060

6161
match_pairs.extend(suffix.iter().rev().enumerate().map(|(idx, subpattern)| {
62-
let end_offset = (idx + 1) as u32;
62+
let end_offset = (idx + 1) as u64;
6363
let elem = ProjectionElem::ConstantIndex {
6464
offset: if exact_size { min_length - end_offset } else { end_offset },
6565
min_length,

0 commit comments

Comments
 (0)