Skip to content

Commit

Permalink
still more clippy
Browse files Browse the repository at this point in the history
  • Loading branch information
dwrensha committed Sep 3, 2023
1 parent f7cac10 commit 60edb44
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 19 deletions.
11 changes: 4 additions & 7 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -381,10 +381,9 @@ fn remote_exception_to_error(exception: exception::Reader) -> Error {
}
_ => (::capnp::ErrorKind::Failed, "(malformed error)".into()),
};
let reason_str = match reason.to_str() {
Ok(s) => s,
Err(_) => "<malformed utf-8 in error reason>",
};
let reason_str = reason
.to_str()
.unwrap_or("<malformed utf-8 in error reason>");
Error {
extra: format!("remote exception: {reason_str}"),
kind,
Expand Down Expand Up @@ -570,9 +569,7 @@ impl<VatId> ConnectionState<VatId> {
}
}
});
let maybe_fulfiller =
mem::replace(&mut *self.disconnect_fulfiller.borrow_mut(), None);
match maybe_fulfiller {
match self.disconnect_fulfiller.borrow_mut().take() {
None => unreachable!(),
Some(fulfiller) => {
let _ = fulfiller.send(Promise::from_future(promise.attach(c)));
Expand Down
8 changes: 3 additions & 5 deletions capnp-rpc/src/twoparty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -104,8 +104,7 @@ where
T: AsyncRead,
{
fn drop(&mut self) {
let maybe_fulfiller = ::std::mem::replace(&mut self.on_disconnect_fulfiller, None);
match maybe_fulfiller {
match self.on_disconnect_fulfiller.take() {
Some(fulfiller) => {
let _ = fulfiller.send(());
}
Expand Down Expand Up @@ -162,7 +161,7 @@ where
) -> Promise<Option<Box<dyn crate::IncomingMessage + 'static>>, ::capnp::Error> {
let inner = self.inner.borrow_mut();

let maybe_input_stream = ::std::mem::replace(&mut *inner.input_stream.borrow_mut(), None);
let maybe_input_stream = inner.input_stream.borrow_mut().take();
let return_it_here = inner.input_stream.clone();
match maybe_input_stream {
Some(mut s) => {
Expand Down Expand Up @@ -279,8 +278,7 @@ where
}

fn accept(&mut self) -> Promise<Box<dyn crate::Connection<VatId>>, ::capnp::Error> {
let connection = ::std::mem::replace(&mut self.connection, None);
match connection {
match self.connection.take() {
Some(c) => Promise::ok(Box::new(c) as Box<dyn crate::Connection<VatId>>),
None => Promise::from_future(::futures::future::pending()),
}
Expand Down
10 changes: 3 additions & 7 deletions capnp/src/private/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ impl WirePointer {
}

#[inline]
pub fn target(ptr: *const Self) -> *const u8 {
pub unsafe fn target(ptr: *const Self) -> *const u8 {
let this_addr: *const u8 = ptr as *const _;
unsafe { this_addr.offset(8 * (1 + (((*ptr).offset_and_kind.get() as i32) >> 2)) as isize) }
}
Expand Down Expand Up @@ -2036,18 +2036,14 @@ mod wire_helpers {
// in the canonicalize=true case.
let whole_byte_size =
u64::from(value.element_count) * u64::from(value.step) / BITS_PER_BYTE as u64;
ptr::copy_nonoverlapping(
value.ptr as *const u8,
ptr as *mut u8,
whole_byte_size as usize,
);
ptr::copy_nonoverlapping(value.ptr, ptr, whole_byte_size as usize);
let leftover_bits =
u64::from(value.element_count) * u64::from(value.step) % BITS_PER_BYTE as u64;
if leftover_bits > 0 {
let mask: u8 = (1 << leftover_bits as u8) - 1;

*ptr.offset(whole_byte_size as isize) =
mask & (*(value.ptr as *const u8).offset(whole_byte_size as isize))
mask & (*value.ptr.offset(whole_byte_size as isize))
}
}

Expand Down

0 comments on commit 60edb44

Please sign in to comment.