@@ -108,7 +108,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
108108 fh. low
109109 } ) ;
110110
111- this. consume_result ( fd)
111+ this. set_last_error_from_io_result ( fd)
112112 }
113113
114114 fn fcntl (
@@ -144,7 +144,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
144144 let fd = this. read_scalar ( fd_op) ?. to_i32 ( ) ?;
145145
146146 this. remove_handle_and ( fd, |handle, this| {
147- this. consume_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) )
147+ this. set_last_error_from_io_result ( handle. file . sync_all ( ) . map ( |_| 0i32 ) )
148148 } )
149149 }
150150
@@ -177,7 +177,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
177177 } ) ;
178178 // Reinsert the file handle
179179 this. machine . file_handler . handles . insert ( fd, handle) . unwrap_none ( ) ;
180- this. consume_result ( bytes?. map ( |bytes| bytes as i64 ) )
180+ this. set_last_error_from_io_result ( bytes?. map ( |bytes| bytes as i64 ) )
181181 } )
182182 }
183183
@@ -206,7 +206,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
206206 . map ( |bytes| handle. file . write ( bytes) . map ( |bytes| bytes as i64 ) )
207207 } ) ;
208208 this. machine . file_handler . handles . insert ( fd, handle) . unwrap_none ( ) ;
209- this. consume_result ( bytes?)
209+ this. set_last_error_from_io_result ( bytes?)
210210 } )
211211 }
212212
@@ -223,7 +223,7 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
223223
224224 let result = remove_file ( path) . map ( |_| 0 ) ;
225225
226- this. consume_result ( result)
226+ this. set_last_error_from_io_result ( result)
227227 }
228228
229229 /// Helper function that gets a `FileHandle` immutable reference and allows to manipulate it
@@ -271,23 +271,4 @@ pub trait EvalContextExt<'mir, 'tcx: 'mir>: crate::MiriEvalContextExt<'mir, 'tcx
271271 Ok ( ( -1 ) . into ( ) )
272272 }
273273 }
274-
275- /// Helper function that consumes an `std::io::Result<T>` and returns an
276- /// `InterpResult<'tcx,T>::Ok` instead. It is expected that the result can be converted to an
277- /// OS error using `std::io::Error::raw_os_error`.
278- ///
279- /// This function uses `T: From<i32>` instead of `i32` directly because some IO related
280- /// functions return different integer types (like `read`, that returns an `i64`)
281- fn consume_result < T : From < i32 > > (
282- & mut self ,
283- result : std:: io:: Result < T > ,
284- ) -> InterpResult < ' tcx , T > {
285- match result {
286- Ok ( ok) => Ok ( ok) ,
287- Err ( e) => {
288- self . eval_context_mut ( ) . set_last_error_from_io_error ( e) ?;
289- Ok ( ( -1 ) . into ( ) )
290- }
291- }
292- }
293274}
0 commit comments