Skip to content

Commit 76db11c

Browse files
authored
Rollup merge of rust-lang#66154 - RalfJung:to_usize, r=oli-obk
miri: Rename to_{u,i}size to to_machine_{u,i}size Having a function `to_usize` that does not return a (host) usize is somewhat confusing, so let's rename it. r? @oli-obk
2 parents 3b0438a + 900fc9a commit 76db11c

File tree

8 files changed

+14
-14
lines changed

8 files changed

+14
-14
lines changed

src/librustc/mir/interpret/value.rs

+6-6
Original file line numberDiff line numberDiff line change
@@ -439,7 +439,7 @@ impl<'tcx, Tag> Scalar<Tag> {
439439
Ok(b as u64)
440440
}
441441

442-
pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
442+
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'static, u64> {
443443
let b = self.to_bits(cx.data_layout().pointer_size)?;
444444
Ok(b as u64)
445445
}
@@ -465,7 +465,7 @@ impl<'tcx, Tag> Scalar<Tag> {
465465
Ok(b as i64)
466466
}
467467

468-
pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
468+
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'static, i64> {
469469
let sz = cx.data_layout().pointer_size;
470470
let b = self.to_bits(sz)?;
471471
let b = sign_extend(b, sz) as i128;
@@ -592,8 +592,8 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
592592
}
593593

594594
#[inline(always)]
595-
pub fn to_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
596-
self.not_undef()?.to_usize(cx)
595+
pub fn to_machine_usize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, u64> {
596+
self.not_undef()?.to_machine_usize(cx)
597597
}
598598

599599
#[inline(always)]
@@ -612,8 +612,8 @@ impl<'tcx, Tag> ScalarMaybeUndef<Tag> {
612612
}
613613

614614
#[inline(always)]
615-
pub fn to_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
616-
self.not_undef()?.to_isize(cx)
615+
pub fn to_machine_isize(self, cx: &impl HasDataLayout) -> InterpResult<'tcx, i64> {
616+
self.not_undef()?.to_machine_isize(cx)
617617
}
618618
}
619619

src/librustc_mir/const_eval.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ fn op_to_const<'tcx>(
118118
0,
119119
),
120120
};
121-
let len = b.to_usize(&ecx.tcx.tcx).unwrap();
121+
let len = b.to_machine_usize(&ecx.tcx.tcx).unwrap();
122122
let start = start.try_into().unwrap();
123123
let len: usize = len.try_into().unwrap();
124124
ConstValue::Slice {

src/librustc_mir/interpret/eval_context.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -447,7 +447,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
447447
}
448448

449449
ty::Slice(_) | ty::Str => {
450-
let len = metadata.expect("slice fat ptr must have vtable").to_usize(self)?;
450+
let len = metadata.expect("slice fat ptr must have length").to_machine_usize(self)?;
451451
let elem = layout.field(self, 0)?;
452452

453453
// Make sure the slice is not too big.

src/librustc_mir/interpret/intern.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -228,7 +228,7 @@ for
228228
ty::Array(_, n)
229229
if n.eval_usize(self.ecx.tcx.tcx, self.ecx.param_env) == 0 => {}
230230
ty::Slice(_)
231-
if mplace.meta.unwrap().to_usize(self.ecx)? == 0 => {}
231+
if mplace.meta.unwrap().to_machine_usize(self.ecx)? == 0 => {}
232232
_ => bug!("const qualif failed to prevent mutable references"),
233233
}
234234
},

src/librustc_mir/interpret/intrinsics.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -263,8 +263,8 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> InterpCx<'mir, 'tcx, M> {
263263
// This is the dual to the special exception for offset-by-0
264264
// in the inbounds pointer offset operation (see the Miri code, `src/operator.rs`).
265265
if a.is_bits() && b.is_bits() {
266-
let a = a.to_usize(self)?;
267-
let b = b.to_usize(self)?;
266+
let a = a.to_machine_usize(self)?;
267+
let b = b.to_machine_usize(self)?;
268268
if a == b && a != 0 {
269269
self.write_scalar(Scalar::from_int(0, isize_layout.size), dest)?;
270270
return Ok(true);

src/librustc_mir/interpret/memory.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -919,7 +919,7 @@ impl<'mir, 'tcx, M: Machine<'mir, 'tcx>> Memory<'mir, 'tcx, M> {
919919
) -> InterpResult<'tcx, Pointer<M::PointerTag>> {
920920
match scalar {
921921
Scalar::Ptr(ptr) => Ok(ptr),
922-
_ => M::int_to_ptr(&self, scalar.to_usize(self)?)
922+
_ => M::int_to_ptr(&self, scalar.to_machine_usize(self)?)
923923
}
924924
}
925925

src/librustc_mir/interpret/place.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -195,7 +195,7 @@ impl<'tcx, Tag> MPlaceTy<'tcx, Tag> {
195195
// We need to consult `meta` metadata
196196
match self.layout.ty.kind {
197197
ty::Slice(..) | ty::Str =>
198-
return self.mplace.meta.unwrap().to_usize(cx),
198+
return self.mplace.meta.unwrap().to_machine_usize(cx),
199199
_ => bug!("len not supported on unsized type {:?}", self.layout.ty),
200200
}
201201
} else {

src/librustc_mir/interpret/validity.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -282,7 +282,7 @@ impl<'rt, 'mir, 'tcx, M: Machine<'mir, 'tcx>> ValidityVisitor<'rt, 'mir, 'tcx, M
282282
// FIXME: More checks for the vtable.
283283
}
284284
ty::Slice(..) | ty::Str => {
285-
let _len = try_validation!(meta.unwrap().to_usize(self.ecx),
285+
let _len = try_validation!(meta.unwrap().to_machine_usize(self.ecx),
286286
"non-integer slice length in wide pointer", self.path);
287287
// We do not check that `len * elem_size <= isize::MAX`:
288288
// that is only required for references, and there it falls out of the

0 commit comments

Comments
 (0)