Skip to content

Commit dc74101

Browse files
committed
Inline a bunch of variable
1 parent 6bcdcde commit dc74101

File tree

4 files changed

+38
-44
lines changed

4 files changed

+38
-44
lines changed

src/shims/unix/fd.rs

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -140,8 +140,7 @@ impl FileDescription for io::Stdin {
140140
// We want isolation mode to be deterministic, so we have to disallow all reads, even stdin.
141141
helpers::isolation_abort_error("`read` from stdin")?;
142142
}
143-
let result = Read::read(&mut { self }, bytes);
144-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
143+
ecx.read_byte_helper(ptr, bytes.to_vec(), Read::read(&mut { self }, bytes), dest)?;
145144
Ok(())
146145
}
147146

@@ -195,8 +194,7 @@ impl FileDescription for io::Stderr {
195194
) -> InterpResult<'tcx> {
196195
// We allow writing to stderr even with isolation enabled.
197196
// No need to flush, stderr is not buffered.
198-
let result = Write::write(&mut { self }, bytes);
199-
ecx.write_byte_helper(result, dest)?;
197+
ecx.write_byte_helper(Write::write(&mut { self }, bytes), dest)?;
200198
Ok(())
201199
}
202200

@@ -223,8 +221,7 @@ impl FileDescription for NullOutput {
223221
ecx: &mut MiriInterpCx<'tcx>,
224222
) -> InterpResult<'tcx> {
225223
// We just don't write anything, but report to the user that we did.
226-
let result = Ok(bytes.len());
227-
ecx.write_byte_helper(result, dest)?;
224+
ecx.write_byte_helper(Ok(bytes.len()), dest)?;
228225
Ok(())
229226
}
230227
}

src/shims/unix/fs.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@ impl FileDescription for FileHandle {
4040
ecx: &mut MiriInterpCx<'tcx>,
4141
) -> InterpResult<'tcx> {
4242
assert!(communicate_allowed, "isolation should have prevented even opening a file");
43-
let result = (&mut &self.file).read(bytes);
44-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
43+
ecx.read_byte_helper(ptr, bytes.to_vec(), (&mut &self.file).read(bytes), dest)?;
4544
Ok(())
4645
}
4746

@@ -54,8 +53,7 @@ impl FileDescription for FileHandle {
5453
ecx: &mut MiriInterpCx<'tcx>,
5554
) -> InterpResult<'tcx> {
5655
assert!(communicate_allowed, "isolation should have prevented even opening a file");
57-
let result = (&mut &self.file).write(bytes);
58-
ecx.write_byte_helper(result, dest)?;
56+
ecx.write_byte_helper((&mut &self.file).write(bytes), dest)?;
5957
Ok(())
6058
}
6159

@@ -82,8 +80,8 @@ impl FileDescription for FileHandle {
8280
.expect("failed to restore file position, this shouldn't be possible");
8381
res
8482
};
85-
let result = f();
86-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
83+
let res = f();
84+
ecx.read_byte_helper(ptr, bytes.to_vec(), res, dest)?;
8785
Ok(())
8886
}
8987

@@ -109,8 +107,7 @@ impl FileDescription for FileHandle {
109107
.expect("failed to restore file position, this shouldn't be possible");
110108
res
111109
};
112-
let result = f();
113-
ecx.write_byte_helper(result, dest)?;
110+
ecx.write_byte_helper(f(), dest)?;
114111
Ok(())
115112
}
116113

src/shims/unix/linux/eventfd.rs

Lines changed: 17 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,16 +69,24 @@ impl FileDescription for Event {
6969
) -> InterpResult<'tcx> {
7070
// Check the size of slice, and return error only if the size of the slice < 8.
7171
let Some(bytes) = bytes.first_chunk_mut::<U64_ARRAY_SIZE>() else {
72-
let result = Err(Error::from(ErrorKind::InvalidInput));
73-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
72+
ecx.read_byte_helper(
73+
ptr,
74+
bytes.to_vec(),
75+
Err(Error::from(ErrorKind::InvalidInput)),
76+
dest,
77+
)?;
7478
return Ok(());
7579
};
7680
// Block when counter == 0.
7781
let counter = self.counter.get();
7882
if counter == 0 {
7983
if self.is_nonblock {
80-
let result = Err(Error::from(ErrorKind::WouldBlock));
81-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
84+
ecx.read_byte_helper(
85+
ptr,
86+
bytes.to_vec(),
87+
Err(Error::from(ErrorKind::WouldBlock)),
88+
dest,
89+
)?;
8290
return Ok(());
8391
} else {
8492
//FIXME: blocking is not supported
@@ -97,8 +105,7 @@ impl FileDescription for Event {
97105
// types for current file description.
98106
ecx.check_and_update_readiness(self_ref)?;
99107

100-
let result = Ok(U64_ARRAY_SIZE);
101-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
108+
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(U64_ARRAY_SIZE), dest)?;
102109
return Ok(());
103110
}
104111
}
@@ -125,8 +132,7 @@ impl FileDescription for Event {
125132
) -> InterpResult<'tcx> {
126133
// Check the size of slice, and return error only if the size of the slice < 8.
127134
let Some(bytes) = bytes.first_chunk::<U64_ARRAY_SIZE>() else {
128-
let result = Err(Error::from(ErrorKind::InvalidInput));
129-
ecx.write_byte_helper(result, dest)?;
135+
ecx.write_byte_helper(Err(Error::from(ErrorKind::InvalidInput)), dest)?;
130136
return Ok(());
131137
};
132138
// Convert from bytes to int according to host endianness.
@@ -136,8 +142,7 @@ impl FileDescription for Event {
136142
};
137143
// u64::MAX as input is invalid because the maximum value of counter is u64::MAX - 1.
138144
if num == u64::MAX {
139-
let result = Err(Error::from(ErrorKind::InvalidInput));
140-
ecx.write_byte_helper(result, dest)?;
145+
ecx.write_byte_helper(Err(Error::from(ErrorKind::InvalidInput)), dest)?;
141146
return Ok(());
142147
}
143148
// If the addition does not let the counter to exceed the maximum value, update the counter.
@@ -152,8 +157,7 @@ impl FileDescription for Event {
152157
}
153158
None | Some(u64::MAX) => {
154159
if self.is_nonblock {
155-
let result = Err(Error::from(ErrorKind::WouldBlock));
156-
ecx.write_byte_helper(result, dest)?;
160+
ecx.write_byte_helper(Err(Error::from(ErrorKind::WouldBlock)), dest)?;
157161
return Ok(());
158162
} else {
159163
//FIXME: blocking is not supported
@@ -165,8 +169,7 @@ impl FileDescription for Event {
165169
// types for current file description.
166170
ecx.check_and_update_readiness(self_ref)?;
167171

168-
let result = Ok(U64_ARRAY_SIZE);
169-
ecx.write_byte_helper(result, dest)?;
172+
ecx.write_byte_helper(Ok(U64_ARRAY_SIZE), dest)?;
170173
Ok(())
171174
}
172175
}

src/shims/unix/unnamed_socket.rs

Lines changed: 13 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -135,8 +135,7 @@ impl FileDescription for AnonSocket {
135135

136136
// Always succeed on read size 0.
137137
if request_byte_size == 0 {
138-
let result = Ok(0);
139-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
138+
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(0), dest)?;
140139
return Ok(());
141140
}
142141

@@ -150,8 +149,7 @@ impl FileDescription for AnonSocket {
150149
if self.peer_fd().upgrade().is_none() {
151150
// Socketpair with no peer and empty buffer.
152151
// 0 bytes successfully read indicates end-of-file.
153-
let result = Ok(0);
154-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
152+
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(0), dest)?;
155153
return Ok(());
156154
} else {
157155
if self.is_nonblock {
@@ -160,8 +158,12 @@ impl FileDescription for AnonSocket {
160158
// EAGAIN or EWOULDBLOCK can be returned for socket,
161159
// POSIX.1-2001 allows either error to be returned for this case.
162160
// Since there is no ErrorKind for EAGAIN, WouldBlock is used.
163-
let result = Err(Error::from(ErrorKind::WouldBlock));
164-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
161+
ecx.read_byte_helper(
162+
ptr,
163+
bytes.to_vec(),
164+
Err(Error::from(ErrorKind::WouldBlock)),
165+
dest,
166+
)?;
165167
return Ok(());
166168
} else {
167169
// Blocking socketpair with writer and empty buffer.
@@ -194,8 +196,7 @@ impl FileDescription for AnonSocket {
194196
ecx.check_and_update_readiness(&peer_fd)?;
195197
}
196198

197-
let result = Ok(actual_read_size);
198-
ecx.read_byte_helper(ptr, bytes.to_vec(), result, dest)?;
199+
ecx.read_byte_helper(ptr, bytes.to_vec(), Ok(actual_read_size), dest)?;
199200
return Ok(());
200201
}
201202

@@ -211,17 +212,15 @@ impl FileDescription for AnonSocket {
211212
// Always succeed on write size 0.
212213
// ("If count is zero and fd refers to a file other than a regular file, the results are not specified.")
213214
if write_size == 0 {
214-
let result = Ok(0);
215-
ecx.write_byte_helper(result, dest)?;
215+
ecx.write_byte_helper(Ok(0), dest)?;
216216
return Ok(());
217217
}
218218

219219
// We are writing to our peer's readbuf.
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 = Err(Error::from(ErrorKind::BrokenPipe));
224-
ecx.write_byte_helper(result, dest)?;
223+
ecx.write_byte_helper(Err(Error::from(ErrorKind::BrokenPipe)), dest)?;
225224
return Ok(());
226225
};
227226

@@ -236,8 +235,7 @@ impl FileDescription for AnonSocket {
236235
if available_space == 0 {
237236
if self.is_nonblock {
238237
// Non-blocking socketpair with a full buffer.
239-
let result = Err(Error::from(ErrorKind::WouldBlock));
240-
ecx.write_byte_helper(result, dest)?;
238+
ecx.write_byte_helper(Err(Error::from(ErrorKind::WouldBlock)), dest)?;
241239
return Ok(());
242240
} else {
243241
// Blocking socketpair with a full buffer.
@@ -259,8 +257,7 @@ impl FileDescription for AnonSocket {
259257
// The kernel does this even if the fd was already readable before, so we follow suit.
260258
ecx.check_and_update_readiness(&peer_fd)?;
261259

262-
let result = Ok(actual_write_size);
263-
ecx.write_byte_helper(result, dest)?;
260+
ecx.write_byte_helper(Ok(actual_write_size), dest)?;
264261
return Ok(());
265262
}
266263
}

0 commit comments

Comments
 (0)