@@ -277,17 +277,17 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
277277
278278 let buf = this. deref_operand ( buf_op) ?;
279279
280- let stats = match FileStatus :: new ( this, path, false ) ? {
281- Some ( stats ) => stats ,
280+ let status = match FileStatus :: new ( this, path, false ) ? {
281+ Some ( status ) => status ,
282282 None => return Ok ( -1 ) ,
283283 } ;
284284
285285 // FIXME: use Scalar::to_u16
286- let mode: u16 = stats . mode . to_bits ( Size :: from_bits ( 16 ) ) ? as u16 ;
286+ let mode: u16 = status . mode . to_bits ( Size :: from_bits ( 16 ) ) ? as u16 ;
287287
288- let ( access_sec, access_nsec) = stats . accessed . unwrap_or ( ( 0 , 0 ) ) ;
289- let ( created_sec, created_nsec) = stats . created . unwrap_or ( ( 0 , 0 ) ) ;
290- let ( modified_sec, modified_nsec) = stats . modified . unwrap_or ( ( 0 , 0 ) ) ;
288+ let ( access_sec, access_nsec) = status . accessed . unwrap_or ( ( 0 , 0 ) ) ;
289+ let ( created_sec, created_nsec) = status . created . unwrap_or ( ( 0 , 0 ) ) ;
290+ let ( modified_sec, modified_nsec) = status . modified . unwrap_or ( ( 0 , 0 ) ) ;
291291
292292 let dev_t_layout = this. libc_ty_layout ( "dev_t" ) ?;
293293 let mode_t_layout = this. libc_ty_layout ( "mode_t" ) ?;
@@ -326,7 +326,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
326326 immty_from_uint_checked ( 0u128 , long_layout) ?, // st_ctime_nsec
327327 immty_from_uint_checked ( created_sec, time_t_layout) ?, // st_birthtime
328328 immty_from_uint_checked ( created_nsec, long_layout) ?, // st_birthtime_nsec
329- immty_from_uint_checked ( stats . size , off_t_layout) ?, // st_size
329+ immty_from_uint_checked ( status . size , off_t_layout) ?, // st_size
330330 immty_from_uint_checked ( 0u128 , blkcnt_t_layout) ?, // st_blocks
331331 immty_from_uint_checked ( 0u128 , blksize_t_layout) ?, // st_blksize
332332 immty_from_uint_checked ( 0u128 , uint32_t_layout) ?, // st_flags
@@ -413,41 +413,35 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
413413 // symbolic links.
414414 let is_symlink = flags & this. eval_libc ( "AT_SYMLINK_NOFOLLOW" ) ?. to_i32 ( ) ? != 0 ;
415415
416- let stats = match FileStatus :: new ( this, path, is_symlink) ? {
417- Some ( stats ) => stats ,
416+ let status = match FileStatus :: new ( this, path, is_symlink) ? {
417+ Some ( status ) => status ,
418418 None => return Ok ( -1 ) ,
419419 } ;
420420
421421 // The `mode` field specifies the type of the file and the permissions over the file for
422422 // the owner, its group and other users. Given that we can only provide the file type
423423 // without using platform specific methods, we only set the bits corresponding to the file
424424 // type. This should be an `__u16` but `libc` provides its values as `u32`.
425- let mode: u16 = stats
425+ let mode: u16 = status
426426 . mode
427427 . to_u32 ( ) ?
428428 . try_into ( )
429429 . unwrap_or_else ( |_| bug ! ( "libc contains bad value for constant" ) ) ;
430430
431- let ( access_sec, access_nsec) = if let Some ( tup) = stats. accessed {
432- tup
433- } else {
431+ let ( access_sec, access_nsec) = status. accessed . map ( |tup| {
434432 mask |= this. eval_libc ( "STATX_ATIME" ) ?. to_u32 ( ) ?;
435- ( 0 , 0 )
436- } ;
433+ InterpResult :: Ok ( tup )
434+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
437435
438- let ( created_sec, created_nsec) = if let Some ( tup) = stats. created {
439- tup
440- } else {
436+ let ( created_sec, created_nsec) = status. created . map ( |tup| {
441437 mask |= this. eval_libc ( "STATX_BTIME" ) ?. to_u32 ( ) ?;
442- ( 0 , 0 )
443- } ;
438+ InterpResult :: Ok ( tup )
439+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
444440
445- let ( modified_sec, modified_nsec) = if let Some ( tup) = stats. modified {
446- tup
447- } else {
441+ let ( modified_sec, modified_nsec) = status. modified . map ( |tup| {
448442 mask |= this. eval_libc ( "STATX_MTIME" ) ?. to_u32 ( ) ?;
449- ( 0 , 0 )
450- } ;
443+ InterpResult :: Ok ( tup )
444+ } ) . unwrap_or ( Ok ( ( 0 , 0 ) ) ) ? ;
451445
452446 let __u32_layout = this. libc_ty_layout ( "__u32" ) ?;
453447 let __u64_layout = this. libc_ty_layout ( "__u64" ) ?;
@@ -465,7 +459,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
465459 immty_from_uint_checked ( mode, __u16_layout) ?, // stx_mode
466460 immty_from_uint_checked ( 0u128 , __u16_layout) ?, // statx padding
467461 immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_ino
468- immty_from_uint_checked ( stats . size , __u64_layout) ?, // stx_size
462+ immty_from_uint_checked ( status . size , __u64_layout) ?, // stx_size
469463 immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_blocks
470464 immty_from_uint_checked ( 0u128 , __u64_layout) ?, // stx_attributes
471465 immty_from_uint_checked ( access_sec, __u64_layout) ?, // stx_atime.tv_sec
@@ -521,7 +515,11 @@ struct FileStatus {
521515}
522516
523517impl FileStatus {
524- fn new < ' tcx , ' mir > ( ecx : & mut MiriEvalContext < ' mir , ' tcx > , path : PathBuf , is_symlink : bool ) -> InterpResult < ' tcx , Option < FileStatus > > {
518+ fn new < ' tcx , ' mir > (
519+ ecx : & mut MiriEvalContext < ' mir , ' tcx > ,
520+ path : PathBuf ,
521+ is_symlink : bool
522+ ) -> InterpResult < ' tcx , Option < FileStatus > > {
525523 let metadata = if is_symlink {
526524 // FIXME: metadata for symlinks need testing.
527525 std:: fs:: symlink_metadata ( path)
0 commit comments