Skip to content

Commit 951ed8d

Browse files
committed
Auto merge of #142133 - GuillaumeGomez:rollup-fvzdren, r=GuillaumeGomez
Rollup of 11 pull requests Successful merges: - rust-lang/rust#140418 (Reexport types from `c_size_t` in `std`) - rust-lang/rust#141471 (unsafe keyword docs: emphasize that an unsafe fn in a trait does not get to choose its safety contract) - rust-lang/rust#141603 (Reduce `ast::ptr::P` to a typedef of `Box`) - rust-lang/rust#142043 (Verbose suggestion to make param `const`) - rust-lang/rust#142086 (duduplicate more AST visitor methods) - rust-lang/rust#142103 (Update `InterpCx::project_field` to take `FieldIdx`) - rust-lang/rust#142105 (remove extraneous text) - rust-lang/rust#142112 (fix typo) - rust-lang/rust#142113 (Reduce confusion of some drop order tests) - rust-lang/rust#142114 (Compute number of digits instead of relying on constant value for u128 display code) - rust-lang/rust#142118 (rustc_lexer: typo fix + small cleanups) r? `@ghost` `@rustbot` modify labels: rollup
2 parents 89a0d78 + 8bdadc2 commit 951ed8d

File tree

7 files changed

+30
-24
lines changed

7 files changed

+30
-24
lines changed

src/eval.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -359,8 +359,8 @@ pub fn create_ecx<'tcx>(
359359
let argvs_layout =
360360
ecx.layout_of(Ty::new_array(tcx, u8_ptr_type, u64::try_from(argvs.len()).unwrap()))?;
361361
let argvs_place = ecx.allocate(argvs_layout, MiriMemoryKind::Machine.into())?;
362-
for (idx, arg) in argvs.into_iter().enumerate() {
363-
let place = ecx.project_field(&argvs_place, idx)?;
362+
for (arg, idx) in argvs.into_iter().zip(0..) {
363+
let place = ecx.project_index(&argvs_place, idx)?;
364364
ecx.write_immediate(arg, &place)?;
365365
}
366366
ecx.mark_immutable(&argvs_place);
@@ -389,8 +389,8 @@ pub fn create_ecx<'tcx>(
389389
ecx.allocate(ecx.layout_of(cmd_type)?, MiriMemoryKind::Machine.into())?;
390390
ecx.machine.cmd_line = Some(cmd_place.ptr());
391391
// Store the UTF-16 string. We just allocated so we know the bounds are fine.
392-
for (idx, &c) in cmd_utf16.iter().enumerate() {
393-
let place = ecx.project_field(&cmd_place, idx)?;
392+
for (&c, idx) in cmd_utf16.iter().zip(0..) {
393+
let place = ecx.project_index(&cmd_place, idx)?;
394394
ecx.write_scalar(Scalar::from_u16(c), &place)?;
395395
}
396396
ecx.mark_immutable(&cmd_place);

src/helpers.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
326326
) -> InterpResult<'tcx, Option<P>> {
327327
let this = self.eval_context_ref();
328328
let adt = base.layout().ty.ty_adt_def().unwrap();
329-
for (idx, field) in adt.non_enum_variant().fields.iter().enumerate() {
329+
for (idx, field) in adt.non_enum_variant().fields.iter_enumerated() {
330330
if field.name.as_str() == name {
331331
return interp_ok(Some(this.project_field(base, idx)?));
332332
}
@@ -376,6 +376,7 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
376376
) -> InterpResult<'tcx> {
377377
let this = self.eval_context_mut();
378378
for (idx, &val) in values.iter().enumerate() {
379+
let idx = FieldIdx::from_usize(idx);
379380
let field = this.project_field(dest, idx)?;
380381
this.write_int(val, &field)?;
381382
}
@@ -763,10 +764,10 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
763764
/// `EINVAL` in this case.
764765
fn read_timespec(&mut self, tp: &MPlaceTy<'tcx>) -> InterpResult<'tcx, Option<Duration>> {
765766
let this = self.eval_context_mut();
766-
let seconds_place = this.project_field(tp, 0)?;
767+
let seconds_place = this.project_field(tp, FieldIdx::ZERO)?;
767768
let seconds_scalar = this.read_scalar(&seconds_place)?;
768769
let seconds = seconds_scalar.to_target_isize(this)?;
769-
let nanoseconds_place = this.project_field(tp, 1)?;
770+
let nanoseconds_place = this.project_field(tp, FieldIdx::ONE)?;
770771
let nanoseconds_scalar = this.read_scalar(&nanoseconds_place)?;
771772
let nanoseconds = nanoseconds_scalar.to_target_isize(this)?;
772773

src/shims/backtrace.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_abi::{CanonAbi, Size};
1+
use rustc_abi::{CanonAbi, FieldIdx, Size};
22
use rustc_middle::ty::layout::LayoutOf as _;
33
use rustc_middle::ty::{self, Instance, Ty};
44
use rustc_span::{BytePos, Loc, Symbol, hygiene};
@@ -159,23 +159,23 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
159159
1 => {
160160
this.write_scalar(
161161
Scalar::from_target_usize(name.len().to_u64(), this),
162-
&this.project_field(dest, 0)?,
162+
&this.project_field(dest, FieldIdx::from_u32(0))?,
163163
)?;
164164
this.write_scalar(
165165
Scalar::from_target_usize(filename.len().to_u64(), this),
166-
&this.project_field(dest, 1)?,
166+
&this.project_field(dest, FieldIdx::from_u32(1))?,
167167
)?;
168168
}
169169
_ => throw_unsup_format!("unknown `miri_resolve_frame` flags {}", flags),
170170
}
171171

172-
this.write_scalar(Scalar::from_u32(lineno), &this.project_field(dest, 2)?)?;
173-
this.write_scalar(Scalar::from_u32(colno), &this.project_field(dest, 3)?)?;
172+
this.write_scalar(Scalar::from_u32(lineno), &this.project_field(dest, FieldIdx::from_u32(2))?)?;
173+
this.write_scalar(Scalar::from_u32(colno), &this.project_field(dest, FieldIdx::from_u32(3))?)?;
174174

175175
// Support a 4-field struct for now - this is deprecated
176176
// and slated for removal.
177177
if num_fields == 5 {
178-
this.write_pointer(fn_ptr, &this.project_field(dest, 4)?)?;
178+
this.write_pointer(fn_ptr, &this.project_field(dest, FieldIdx::from_u32(4))?)?;
179179
}
180180

181181
interp_ok(())

src/shims/unix/env.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,9 @@ use std::ffi::{OsStr, OsString};
22
use std::io::ErrorKind;
33
use std::{env, mem};
44

5-
use rustc_abi::Size;
5+
use rustc_abi::{FieldIdx, Size};
66
use rustc_data_structures::fx::FxHashMap;
7+
use rustc_index::IndexVec;
78
use rustc_middle::ty::Ty;
89
use rustc_middle::ty::layout::LayoutOf;
910

@@ -118,7 +119,7 @@ fn alloc_env_var<'tcx>(
118119
/// Allocates an `environ` block with the given list of pointers.
119120
fn alloc_environ_block<'tcx>(
120121
ecx: &mut InterpCx<'tcx, MiriMachine<'tcx>>,
121-
mut vars: Vec<Pointer>,
122+
mut vars: IndexVec<FieldIdx, Pointer>,
122123
) -> InterpResult<'tcx, Pointer> {
123124
// Add trailing null.
124125
vars.push(Pointer::null());
@@ -129,7 +130,7 @@ fn alloc_environ_block<'tcx>(
129130
u64::try_from(vars.len()).unwrap(),
130131
))?;
131132
let vars_place = ecx.allocate(vars_layout, MiriMemoryKind::Runtime.into())?;
132-
for (idx, var) in vars.into_iter().enumerate() {
133+
for (idx, var) in vars.into_iter_enumerated() {
133134
let place = ecx.project_field(&vars_place, idx)?;
134135
ecx.write_pointer(var, &place)?;
135136
}

src/shims/unix/freebsd/sync.rs

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@
22
33
use core::time::Duration;
44

5+
use rustc_abi::FieldIdx;
6+
57
use crate::concurrency::sync::FutexRef;
68
use crate::*;
79

@@ -214,18 +216,18 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
214216
// Only flag allowed is UMTX_ABSTIME.
215217
let abs_time = this.eval_libc_u32("UMTX_ABSTIME");
216218

217-
let timespec_place = this.project_field(ut, 0)?;
219+
let timespec_place = this.project_field(ut, FieldIdx::from_u32(0))?;
218220
// Inner `timespec` must still be valid.
219221
let duration = match this.read_timespec(&timespec_place)? {
220222
Some(dur) => dur,
221223
None => return interp_ok(None),
222224
};
223225

224-
let flags_place = this.project_field(ut, 1)?;
226+
let flags_place = this.project_field(ut, FieldIdx::from_u32(1))?;
225227
let flags = this.read_scalar(&flags_place)?.to_u32()?;
226228
let abs_time_flag = flags == abs_time;
227229

228-
let clock_id_place = this.project_field(ut, 2)?;
230+
let clock_id_place = this.project_field(ut, FieldIdx::from_u32(2))?;
229231
let clock_id = this.read_scalar(&clock_id_place)?.to_i32()?;
230232
let timeout_clock = this.translate_umtx_time_clock_id(clock_id)?;
231233

src/shims/unix/linux_like/epoll.rs

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ use std::io;
44
use std::rc::{Rc, Weak};
55
use std::time::Duration;
66

7+
use rustc_abi::FieldIdx;
8+
79
use crate::concurrency::VClock;
810
use crate::shims::files::{
911
DynFileDescriptionRef, FdId, FileDescription, FileDescriptionRef, WeakFileDescriptionRef,
@@ -284,8 +286,8 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
284286

285287
if op == epoll_ctl_add || op == epoll_ctl_mod {
286288
// Read event bitmask and data from epoll_event passed by caller.
287-
let mut events = this.read_scalar(&this.project_field(&event, 0)?)?.to_u32()?;
288-
let data = this.read_scalar(&this.project_field(&event, 1)?)?.to_u64()?;
289+
let mut events = this.read_scalar(&this.project_field(&event, FieldIdx::ZERO)?)?.to_u32()?;
290+
let data = this.read_scalar(&this.project_field(&event, FieldIdx::ONE)?)?.to_u64()?;
289291

290292
// Unset the flag we support to discover if any unsupported flags are used.
291293
let mut flags = events;

src/shims/x86/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
use rustc_abi::{CanonAbi, Size};
1+
use rustc_abi::{CanonAbi, FieldIdx, Size};
22
use rustc_apfloat::Float;
33
use rustc_apfloat::ieee::Single;
44
use rustc_middle::ty::Ty;
@@ -54,8 +54,8 @@ pub(super) trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
5454
};
5555

5656
let (sum, cb_out) = carrying_add(this, cb_in, a, b, op)?;
57-
this.write_scalar(cb_out, &this.project_field(dest, 0)?)?;
58-
this.write_immediate(*sum, &this.project_field(dest, 1)?)?;
57+
this.write_scalar(cb_out, &this.project_field(dest, FieldIdx::ZERO)?)?;
58+
this.write_immediate(*sum, &this.project_field(dest, FieldIdx::ONE)?)?;
5959
}
6060

6161
// Used to implement the `_addcarryx_u{32, 64}` functions. They are semantically identical with the `_addcarry_u{32, 64}` functions,

0 commit comments

Comments
 (0)