Skip to content

Commit c5e955f

Browse files
Arshia001theduke
authored andcommitted
Fix lints and nits
1 parent 94f2b9c commit c5e955f

File tree

4 files changed

+23
-21
lines changed

4 files changed

+23
-21
lines changed

lib/virtual-fs/src/pipe.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -130,18 +130,16 @@ impl PipeRx {
130130
}
131131
}
132132

133-
pub fn set_interest_handler(&mut self, interest_handler: Box<dyn InterestHandler>) {
133+
pub fn set_interest_handler(&self, interest_handler: Box<dyn InterestHandler>) {
134134
let Some(ref rx) = self.rx else {
135135
return;
136136
};
137137
let mut rx = rx.lock().unwrap();
138138
rx.interest_handler.replace(interest_handler);
139139
}
140140

141-
pub fn remove_interest_handler(&mut self) -> Option<Box<dyn InterestHandler>> {
142-
let Some(ref rx) = self.rx else {
143-
return None;
144-
};
141+
pub fn remove_interest_handler(&self) -> Option<Box<dyn InterestHandler>> {
142+
let rx = self.rx.as_ref()?;
145143
let mut rx = rx.lock().unwrap();
146144
rx.interest_handler.take()
147145
}
@@ -200,11 +198,11 @@ impl Pipe {
200198
self.recv.close();
201199
}
202200

203-
pub fn set_interest_handler(&mut self, interest_handler: Box<dyn InterestHandler>) {
201+
pub fn set_interest_handler(&self, interest_handler: Box<dyn InterestHandler>) {
204202
self.recv.set_interest_handler(interest_handler);
205203
}
206204

207-
pub fn remove_interest_handler(&mut self) -> Option<Box<dyn InterestHandler>> {
205+
pub fn remove_interest_handler(&self) -> Option<Box<dyn InterestHandler>> {
208206
self.recv.remove_interest_handler()
209207
}
210208
}
@@ -235,7 +233,7 @@ impl PipeTx {
235233
}
236234
}
237235

238-
fn push_readable_interest_to_rx_end(&self) {
236+
fn mark_other_end_readable(&self) {
239237
if let Some(rx_end) = self.rx_end.upgrade() {
240238
let mut guard = rx_end.lock().unwrap();
241239
if let Some(interest_handler) = guard.interest_handler.as_mut() {
@@ -332,7 +330,7 @@ impl std::io::Write for PipeTx {
332330

333331
tx.send(buf.to_vec())
334332
.map_err(|_| Into::<std::io::Error>::into(std::io::ErrorKind::BrokenPipe))?;
335-
self.push_readable_interest_to_rx_end();
333+
self.mark_other_end_readable();
336334
Ok(buf.len())
337335
}
338336

@@ -419,7 +417,7 @@ impl AsyncWrite for PipeTx {
419417

420418
match tx.send(buf.to_vec()) {
421419
Ok(()) => {
422-
self.push_readable_interest_to_rx_end();
420+
self.mark_other_end_readable();
423421
Poll::Ready(Ok(buf.len()))
424422
}
425423
Err(_) => Poll::Ready(Err(Into::<std::io::Error>::into(

lib/wasix/src/fs/fd.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,11 +124,11 @@ impl Drop for EpollJoinGuard {
124124
inner.remove_interest_handler();
125125
}
126126
InodeValFilePollGuardMode::DuplexPipe { pipe } => {
127-
let mut inner = pipe.write().unwrap();
127+
let inner = pipe.write().unwrap();
128128
inner.remove_interest_handler();
129129
}
130130
InodeValFilePollGuardMode::PipeRx { rx } => {
131-
let mut inner = rx.write().unwrap();
131+
let inner = rx.write().unwrap();
132132
inner.remove_interest_handler();
133133
}
134134
InodeValFilePollGuardMode::PipeTx { .. } => {

lib/wasix/src/net/socket.rs

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,9 @@ impl InodeSocket {
235235

236236
// When a sendto or connect call comes in for a UDP "pre-socket", it must be bound to
237237
// an ephemeral port automatically.
238+
// Apparently, clippy fails to recognize the write-locked guard being passed into
239+
// the other function, hence the `allow` attribute.
240+
#[allow(clippy::await_holding_lock, clippy::readonly_write_lock)]
238241
pub async fn auto_bind_udp(
239242
&self,
240243
tasks: &dyn VirtualTaskManager,
@@ -245,15 +248,15 @@ impl InodeSocket {
245248
.ok()
246249
.flatten()
247250
.unwrap_or(Duration::from_secs(30));
248-
let mut inner = self.inner.protected.write().unwrap();
251+
let inner = self.inner.protected.write().unwrap();
249252
match &inner.kind {
250253
InodeSocketKind::PreSocket { props, .. } if props.ty == Socktype::Dgram => {
251254
let addr = match props.family {
252255
Addressfamily::Inet4 => SocketAddr::new(IpAddr::V4(Ipv4Addr::UNSPECIFIED), 0),
253256
Addressfamily::Inet6 => SocketAddr::new(IpAddr::V6(Ipv6Addr::UNSPECIFIED), 0),
254257
_ => return Err(Errno::Notsup),
255258
};
256-
Self::bind_internal(tasks, net, addr, timeout, &mut inner).await
259+
Self::bind_internal(tasks, net, addr, timeout, inner).await
257260
}
258261
_ => Ok(None),
259262
}
@@ -270,16 +273,18 @@ impl InodeSocket {
270273
.ok()
271274
.flatten()
272275
.unwrap_or(Duration::from_secs(30));
273-
let mut inner = self.inner.protected.write().unwrap();
274-
Self::bind_internal(tasks, net, set_addr, timeout, &mut inner).await
276+
let inner = self.inner.protected.write().unwrap();
277+
Self::bind_internal(tasks, net, set_addr, timeout, inner).await
275278
}
276279

280+
// The lock is dropped before awaiting, but clippy doesn't realize it
281+
#[allow(clippy::await_holding_lock)]
277282
async fn bind_internal(
278283
tasks: &dyn VirtualTaskManager,
279284
net: &dyn VirtualNetworking,
280285
set_addr: SocketAddr,
281286
timeout: Duration,
282-
inner: &mut RwLockWriteGuard<'_, InodeSocketProtected>,
287+
mut inner: RwLockWriteGuard<'_, InodeSocketProtected>,
283288
) -> Result<Option<InodeSocket>, Errno> {
284289
let socket = {
285290
match &mut inner.kind {
@@ -373,6 +378,8 @@ impl InodeSocket {
373378
}
374379
};
375380

381+
drop(inner);
382+
376383
tokio::select! {
377384
socket = socket => {
378385
let socket = socket.map_err(net_error_into_wasi_err)?;

lib/wasix/src/syscalls/wasix/epoll_ctl.rs

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,7 @@ use wasmer_wasix_types::wasi::{
66
EpollCtl, EpollEvent, EpollEventCtl, EpollType, SubscriptionClock, SubscriptionUnion, Userdata,
77
};
88

9-
use std::{
10-
os::fd,
11-
task::{Context, Poll, RawWaker, RawWakerVTable, Waker},
12-
};
9+
use std::task::{Context, Poll, RawWaker, RawWakerVTable, Waker};
1310

1411
use futures::Future;
1512

0 commit comments

Comments
 (0)