Skip to content

Commit 0018386

Browse files
committed
Apply suggestion: remove unnecessary Ok(())
1 parent be30bcf commit 0018386

File tree

4 files changed

+20
-40
lines changed

4 files changed

+20
-40
lines changed

src/shims/unix/fd.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -142,8 +142,7 @@ impl FileDescription for io::Stdin {
142142
helpers::isolation_abort_error("`read` from stdin")?;
143143
}
144144
let result = Read::read(&mut { self }, &mut bytes);
145-
ecx.return_read_bytes_and_count(ptr, bytes, result, dest)?;
146-
Ok(())
145+
ecx.return_read_bytes_and_count(ptr, bytes, result, dest)
147146
}
148147

149148
fn is_tty(&self, communicate_allowed: bool) -> bool {

src/shims/unix/fs.rs

Lines changed: 4 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@ impl FileDescription for FileHandle {
4242
assert!(communicate_allowed, "isolation should have prevented even opening a file");
4343
let mut bytes = vec![0; usize::try_from(len).unwrap()];
4444
let result = (&mut &self.file).read(&mut bytes);
45-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
46-
Ok(())
45+
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
4746
}
4847

4948
fn write<'tcx>(
@@ -56,8 +55,7 @@ impl FileDescription for FileHandle {
5655
) -> InterpResult<'tcx> {
5756
assert!(communicate_allowed, "isolation should have prevented even opening a file");
5857
let result = (&mut &self.file).write(bytes);
59-
ecx.return_written_byte_count_or_error(result, dest)?;
60-
Ok(())
58+
ecx.return_written_byte_count_or_error(result, dest)
6159
}
6260

6361
fn pread<'tcx>(
@@ -85,8 +83,7 @@ impl FileDescription for FileHandle {
8583
res
8684
};
8785
let result = f();
88-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
89-
Ok(())
86+
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
9087
}
9188

9289
fn pwrite<'tcx>(
@@ -112,8 +109,7 @@ impl FileDescription for FileHandle {
112109
res
113110
};
114111
let result = f();
115-
ecx.return_written_byte_count_or_error(result, dest)?;
116-
Ok(())
112+
ecx.return_written_byte_count_or_error(result, dest)
117113
}
118114

119115
fn seek<'tcx>(

src/shims/unix/linux/eventfd.rs

Lines changed: 7 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -72,17 +72,15 @@ impl FileDescription for Event {
7272
// Check the size of slice, and return error only if the size of the slice < 8.
7373
if len < U64_ARRAY_SIZE.try_into().unwrap() {
7474
let result = Err(Error::from(ErrorKind::InvalidInput));
75-
return_read_bytes_and_count_ev(&buf_place, None, result, dest, ecx)?;
76-
return Ok(());
75+
return return_read_bytes_and_count_ev(&buf_place, None, result, dest, ecx);
7776
}
7877

7978
// Block when counter == 0.
8079
let counter = self.counter.get();
8180
if counter == 0 {
8281
if self.is_nonblock {
8382
let result = Err(Error::from(ErrorKind::WouldBlock));
84-
return_read_bytes_and_count_ev(&buf_place, None, result, dest, ecx)?;
85-
return Ok(());
83+
return return_read_bytes_and_count_ev(&buf_place, None, result, dest, ecx);
8684
} else {
8785
//FIXME: blocking is not supported
8886
throw_unsup_format!("eventfd: blocking is unsupported");
@@ -91,13 +89,12 @@ impl FileDescription for Event {
9189
// Synchronize with all prior `write` calls to this FD.
9290
ecx.acquire_clock(&self.clock.borrow());
9391
let result = Ok(U64_ARRAY_SIZE);
94-
return_read_bytes_and_count_ev(&buf_place, Some(counter), result, dest, ecx)?;
9592
self.counter.set(0);
9693
// When any of the event happened, we check and update the status of all supported event
9794
// types for current file description.
9895
ecx.check_and_update_readiness(self_ref)?;
9996

100-
return Ok(());
97+
return_read_bytes_and_count_ev(&buf_place, Some(counter), result, dest, ecx)
10198
}
10299
}
103100

@@ -124,8 +121,7 @@ impl FileDescription for Event {
124121
// Check the size of slice, and return error only if the size of the slice < 8.
125122
let Some(bytes) = bytes.first_chunk::<U64_ARRAY_SIZE>() else {
126123
let result = Err(Error::from(ErrorKind::InvalidInput));
127-
ecx.return_written_byte_count_or_error(result, dest)?;
128-
return Ok(());
124+
return ecx.return_written_byte_count_or_error(result, dest);
129125
};
130126
// Convert from bytes to int according to host endianness.
131127
let num = match ecx.tcx.sess.target.endian {
@@ -135,8 +131,7 @@ impl FileDescription for Event {
135131
// u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1.
136132
if num == u64::MAX {
137133
let result = Err(Error::from(ErrorKind::InvalidInput));
138-
ecx.return_written_byte_count_or_error(result, dest)?;
139-
return Ok(());
134+
return ecx.return_written_byte_count_or_error(result, dest);
140135
}
141136
// If the addition does not let the counter to exceed the maximum value, update the counter.
142137
// Else, block.
@@ -151,8 +146,7 @@ impl FileDescription for Event {
151146
None | Some(u64::MAX) => {
152147
if self.is_nonblock {
153148
let result = Err(Error::from(ErrorKind::WouldBlock));
154-
ecx.return_written_byte_count_or_error(result, dest)?;
155-
return Ok(());
149+
return ecx.return_written_byte_count_or_error(result, dest);
156150
} else {
157151
//FIXME: blocking is not supported
158152
throw_unsup_format!("eventfd: blocking is unsupported");
@@ -164,8 +158,7 @@ impl FileDescription for Event {
164158
ecx.check_and_update_readiness(self_ref)?;
165159

166160
let result = Ok(U64_ARRAY_SIZE);
167-
ecx.return_written_byte_count_or_error(result, dest)?;
168-
Ok(())
161+
ecx.return_written_byte_count_or_error(result, dest)
169162
}
170163
}
171164

src/shims/unix/unnamed_socket.rs

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,7 @@ impl FileDescription for AnonSocket {
137137
// Always succeed on read size 0.
138138
if request_byte_size == 0 {
139139
let result = Ok(0);
140-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
141-
return Ok(());
140+
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
142141
}
143142

144143
let Some(readbuf) = &self.readbuf else {
@@ -152,8 +151,7 @@ impl FileDescription for AnonSocket {
152151
// Socketpair with no peer and empty buffer.
153152
// 0 bytes successfully read indicates end-of-file.
154153
let result = Ok(0);
155-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
156-
return Ok(());
154+
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
157155
} else {
158156
if self.is_nonblock {
159157
// Non-blocking socketpair with writer and empty buffer.
@@ -162,8 +160,7 @@ impl FileDescription for AnonSocket {
162160
// POSIX.1-2001 allows either error to be returned for this case.
163161
// Since there is no ErrorKind for EAGAIN, WouldBlock is used.
164162
let result = Err(Error::from(ErrorKind::WouldBlock));
165-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
166-
return Ok(());
163+
return ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest);
167164
} else {
168165
// Blocking socketpair with writer and empty buffer.
169166
// FIXME: blocking is currently not supported
@@ -196,8 +193,7 @@ impl FileDescription for AnonSocket {
196193
}
197194

198195
let result = Ok(actual_read_size);
199-
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)?;
200-
return Ok(());
196+
ecx.return_read_bytes_and_count(ptr, bytes.to_vec(), result, dest)
201197
}
202198

203199
fn write<'tcx>(
@@ -213,17 +209,15 @@ impl FileDescription for AnonSocket {
213209
// ("If count is zero and fd refers to a file other than a regular file, the results are not specified.")
214210
if write_size == 0 {
215211
let result = Ok(0);
216-
ecx.return_written_byte_count_or_error(result, dest)?;
217-
return Ok(());
212+
return ecx.return_written_byte_count_or_error(result, dest);
218213
}
219214

220215
// We are writing to our peer's readbuf.
221216
let Some(peer_fd) = self.peer_fd().upgrade() else {
222217
// If the upgrade from Weak to Rc fails, it indicates that all read ends have been
223218
// closed.
224219
let result = Err(Error::from(ErrorKind::BrokenPipe));
225-
ecx.return_written_byte_count_or_error(result, dest)?;
226-
return Ok(());
220+
return ecx.return_written_byte_count_or_error(result, dest);
227221
};
228222

229223
let Some(writebuf) = &peer_fd.downcast::<AnonSocket>().unwrap().readbuf else {
@@ -238,8 +232,7 @@ impl FileDescription for AnonSocket {
238232
if self.is_nonblock {
239233
// Non-blocking socketpair with a full buffer.
240234
let result = Err(Error::from(ErrorKind::WouldBlock));
241-
ecx.return_written_byte_count_or_error(result, dest)?;
242-
return Ok(());
235+
return ecx.return_written_byte_count_or_error(result, dest);
243236
} else {
244237
// Blocking socketpair with a full buffer.
245238
throw_unsup_format!("socketpair write: blocking isn't supported yet");
@@ -261,8 +254,7 @@ impl FileDescription for AnonSocket {
261254
ecx.check_and_update_readiness(&peer_fd)?;
262255

263256
let result = Ok(actual_write_size);
264-
ecx.return_written_byte_count_or_error(result, dest)?;
265-
return Ok(());
257+
ecx.return_written_byte_count_or_error(result, dest)
266258
}
267259
}
268260

0 commit comments

Comments
 (0)