@@ -276,29 +276,27 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
276276 fn dup ( & mut self , old_fd : i32 ) -> InterpResult < ' tcx , i32 > {
277277 let this = self . eval_context_mut ( ) ;
278278
279- match this. machine . fds . dup ( old_fd) {
280- Some ( dup_fd ) => Ok ( this. machine . fds . insert_fd_with_min_fd ( dup_fd , 0 ) ) ,
281- None => this . fd_not_found ( ) ,
282- }
279+ let Some ( dup_fd ) = this. machine . fds . dup ( old_fd) else {
280+ return this. fd_not_found ( ) ;
281+ } ;
282+ Ok ( this . machine . fds . insert_fd_with_min_fd ( dup_fd , 0 ) )
283283 }
284284
285285 fn dup2 ( & mut self , old_fd : i32 , new_fd : i32 ) -> InterpResult < ' tcx , i32 > {
286286 let this = self . eval_context_mut ( ) ;
287287
288- match this. machine . fds . dup ( old_fd) {
289- Some ( dup_fd) => {
290- if new_fd != old_fd {
291- // Close new_fd if it is previously opened.
292- // If old_fd and new_fd point to the same description, then `dup_fd` ensures we keep the underlying file description alive.
293- if let Some ( file_descriptor) = this. machine . fds . fds . insert ( new_fd, dup_fd) {
294- // Ignore close error (not interpreter's) according to dup2() doc.
295- file_descriptor. close ( this. machine . communicate ( ) ) ?. ok ( ) ;
296- }
297- }
298- Ok ( new_fd)
288+ let Some ( dup_fd) = this. machine . fds . dup ( old_fd) else {
289+ return this. fd_not_found ( ) ;
290+ } ;
291+ if new_fd != old_fd {
292+ // Close new_fd if it is previously opened.
293+ // If old_fd and new_fd point to the same description, then `dup_fd` ensures we keep the underlying file description alive.
294+ if let Some ( file_descriptor) = this. machine . fds . fds . insert ( new_fd, dup_fd) {
295+ // Ignore close error (not interpreter's) according to dup2() doc.
296+ file_descriptor. close ( this. machine . communicate ( ) ) ?. ok ( ) ;
299297 }
300- None => this. fd_not_found ( ) ,
301298 }
299+ Ok ( new_fd)
302300 }
303301
304302 fn fcntl ( & mut self , args : & [ OpTy < ' tcx > ] ) -> InterpResult < ' tcx , i32 > {
@@ -362,14 +360,13 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
362360
363361 let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
364362
365- Ok ( Scalar :: from_i32 ( if let Some ( file_descriptor) = this. machine . fds . remove ( fd) {
366- let result = file_descriptor. close ( this. machine . communicate ( ) ) ?;
367- // return `0` if close is successful
368- let result = result. map ( |( ) | 0i32 ) ;
369- this. try_unwrap_io_result ( result) ?
370- } else {
371- this. fd_not_found ( ) ?
372- } ) )
363+ let Some ( file_descriptor) = this. machine . fds . remove ( fd) else {
364+ return Ok ( Scalar :: from_i32 ( this. fd_not_found ( ) ?) ) ;
365+ } ;
366+ let result = file_descriptor. close ( this. machine . communicate ( ) ) ?;
367+ // return `0` if close is successful
368+ let result = result. map ( |( ) | 0i32 ) ;
369+ Ok ( Scalar :: from_i32 ( this. try_unwrap_io_result ( result) ?) )
373370 }
374371
375372 /// Function used when a file descriptor does not exist. It returns `Ok(-1)`and sets
0 commit comments