Skip to content

Commit 81083ff

Browse files
committed
let write_byte_helper takes in io::Result<usize> as it will always take in Ok()
1 parent f9631e5 commit 81083ff

File tree

4 files changed

+15
-15
lines changed

4 files changed

+15
-15
lines changed

src/shims/unix/fd.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ impl FileDescription for io::Stdout {
164164
ecx: &mut MiriInterpCx<'tcx>,
165165
) -> InterpResult<'tcx> {
166166
// We allow writing to stderr even with isolation enabled.
167-
let result = Ok(Write::write(&mut { self }, bytes));
167+
let result = Write::write(&mut { self }, bytes);
168168
// Stdout is buffered, flush to make sure it appears on the
169169
// screen. This is the write() syscall of the interpreted
170170
// program, we want it to correspond to a write() syscall on
@@ -195,7 +195,7 @@ impl FileDescription for io::Stderr {
195195
) -> InterpResult<'tcx> {
196196
// We allow writing to stderr even with isolation enabled.
197197
// No need to flush, stderr is not buffered.
198-
let result = Ok(Write::write(&mut { self }, bytes));
198+
let result = Write::write(&mut { self }, bytes);
199199
ecx.write_byte_helper(result, dest)?;
200200
Ok(())
201201
}
@@ -223,7 +223,7 @@ impl FileDescription for NullOutput {
223223
ecx: &mut MiriInterpCx<'tcx>,
224224
) -> InterpResult<'tcx> {
225225
// We just don't write anything, but report to the user that we did.
226-
let result = Ok(Ok(bytes.len()));
226+
let result = Ok(bytes.len());
227227
ecx.write_byte_helper(result, dest)?;
228228
Ok(())
229229
}
@@ -682,11 +682,11 @@ pub trait EvalContextExt<'tcx>: crate::MiriInterpCxExt<'tcx> {
682682

683683
fn write_byte_helper(
684684
&mut self,
685-
result: InterpResult<'tcx, io::Result<usize>>,
685+
result: io::Result<usize>,
686686
dest: &MPlaceTy<'tcx>,
687687
) -> InterpResult<'tcx> {
688688
let this = self.eval_context_mut();
689-
let result = this.try_unwrap_io_result(result?.map(|c| i64::try_from(c).unwrap()))?;
689+
let result = this.try_unwrap_io_result(result.map(|c| i64::try_from(c).unwrap()))?;
690690
this.write_int(result, dest)?;
691691
Ok(())
692692
}

src/shims/unix/fs.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ impl FileDescription for FileHandle {
5454
ecx: &mut MiriInterpCx<'tcx>,
5555
) -> InterpResult<'tcx> {
5656
assert!(communicate_allowed, "isolation should have prevented even opening a file");
57-
let result = Ok((&mut &self.file).write(bytes));
57+
let result = (&mut &self.file).write(bytes);
5858
ecx.write_byte_helper(result, dest)?;
5959
Ok(())
6060
}
@@ -109,7 +109,7 @@ impl FileDescription for FileHandle {
109109
.expect("failed to restore file position, this shouldn't be possible");
110110
res
111111
};
112-
let result = Ok(f());
112+
let result = f();
113113
ecx.write_byte_helper(result, dest)?;
114114
Ok(())
115115
}

src/shims/unix/linux/eventfd.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -125,7 +125,7 @@ impl FileDescription for Event {
125125
) -> InterpResult<'tcx> {
126126
// Check the size of slice, and return error only if the size of the slice < 8.
127127
let Some(bytes) = bytes.first_chunk::<U64_ARRAY_SIZE>() else {
128-
let result = Ok(Err(Error::from(ErrorKind::InvalidInput)));
128+
let result = Err(Error::from(ErrorKind::InvalidInput));
129129
ecx.write_byte_helper(result, dest)?;
130130
return Ok(());
131131
};
@@ -136,7 +136,7 @@ impl FileDescription for Event {
136136
};
137137
// u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1.
138138
if num == u64::MAX {
139-
let result = Ok(Err(Error::from(ErrorKind::InvalidInput)));
139+
let result = Err(Error::from(ErrorKind::InvalidInput));
140140
ecx.write_byte_helper(result, dest)?;
141141
return Ok(());
142142
}
@@ -152,7 +152,7 @@ impl FileDescription for Event {
152152
}
153153
None | Some(u64::MAX) => {
154154
if self.is_nonblock {
155-
let result = Ok(Err(Error::from(ErrorKind::WouldBlock)));
155+
let result = Err(Error::from(ErrorKind::WouldBlock));
156156
ecx.write_byte_helper(result, dest)?;
157157
return Ok(());
158158
} else {
@@ -165,7 +165,7 @@ impl FileDescription for Event {
165165
// types for current file description.
166166
ecx.check_and_update_readiness(self_ref)?;
167167

168-
let result = Ok(Ok(U64_ARRAY_SIZE));
168+
let result = Ok(U64_ARRAY_SIZE);
169169
ecx.write_byte_helper(result, dest)?;
170170
Ok(())
171171
}

src/shims/unix/unnamed_socket.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -211,7 +211,7 @@ impl FileDescription for AnonSocket {
211211
// Always succeed on write size 0.
212212
// ("If count is zero and fd refers to a file other than a regular file, the results are not specified.")
213213
if write_size == 0 {
214-
let result = Ok(Ok(0));
214+
let result = Ok(0);
215215
ecx.write_byte_helper(result, dest)?;
216216
return Ok(());
217217
}
@@ -220,7 +220,7 @@ impl FileDescription for AnonSocket {
220220
let Some(peer_fd) = self.peer_fd().upgrade() else {
221221
// If the upgrade from Weak to Rc fails, it indicates that all read ends have been
222222
// closed.
223-
let result = Ok(Err(Error::from(ErrorKind::BrokenPipe)));
223+
let result = Err(Error::from(ErrorKind::BrokenPipe));
224224
ecx.write_byte_helper(result, dest)?;
225225
return Ok(());
226226
};
@@ -236,7 +236,7 @@ impl FileDescription for AnonSocket {
236236
if available_space == 0 {
237237
if self.is_nonblock {
238238
// Non-blocking socketpair with a full buffer.
239-
let result = Ok(Err(Error::from(ErrorKind::WouldBlock)));
239+
let result = Err(Error::from(ErrorKind::WouldBlock));
240240
ecx.write_byte_helper(result, dest)?;
241241
return Ok(());
242242
} else {
@@ -259,7 +259,7 @@ impl FileDescription for AnonSocket {
259259
// The kernel does this even if the fd was already readable before, so we follow suit.
260260
ecx.check_and_update_readiness(&peer_fd)?;
261261

262-
let result = Ok(Ok(actual_write_size));
262+
let result = Ok(actual_write_size);
263263
ecx.write_byte_helper(result, dest)?;
264264
return Ok(());
265265
}

0 commit comments

Comments
 (0)