From aae600012f4547a1a14c75fe5f0f94f925d44c4e Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Wed, 29 Nov 2023 06:27:26 +0000 Subject: [PATCH 1/4] squash some lints --- capnp-futures/src/serialize.rs | 4 ++-- capnp-futures/src/serialize_packed.rs | 4 ++-- capnp-futures/test/test.rs | 1 + capnp-rpc/src/rpc.rs | 2 +- capnp/src/primitive_list.rs | 2 +- capnp/src/private/layout.rs | 2 +- capnp/src/serialize.rs | 2 +- capnpc/test/test_util.rs | 15 ++++++--------- example/fill_random_values/src/lib.rs | 20 ++++++++++++-------- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/capnp-futures/src/serialize.rs b/capnp-futures/src/serialize.rs index ec6d08abb..40c95003b 100644 --- a/capnp-futures/src/serialize.rs +++ b/capnp-futures/src/serialize.rs @@ -563,7 +563,7 @@ pub mod test { ) -> Poll> { if self.idx == 0 { self.idx = self.blocking_period; - cx.waker().clone().wake(); + cx.waker().wake_by_ref(); Poll::Pending } else { let len = cmp::min(self.idx, buf.len()); @@ -619,7 +619,7 @@ pub mod test { ) -> Poll> { if self.idx == 0 { self.idx = self.blocking_period; - cx.waker().clone().wake(); + cx.waker().wake_by_ref(); Poll::Pending } else { let len = cmp::min(self.idx, buf.len()); diff --git a/capnp-futures/src/serialize_packed.rs b/capnp-futures/src/serialize_packed.rs index 10b0fd1c5..8b10ee087 100644 --- a/capnp-futures/src/serialize_packed.rs +++ b/capnp-futures/src/serialize_packed.rs @@ -705,7 +705,7 @@ pub mod test { #[test] fn read_empty() { - let words = vec![]; + let words = []; // Before https://github.com/capnproto/capnproto-rust/pull/446 // this would loop forever. let message = @@ -716,7 +716,7 @@ pub mod test { #[test] fn eof_mid_message() { - let words = vec![0xfe, 0x3, 0x3]; + let words = [0xfe, 0x3, 0x3]; let result = futures::executor::block_on(Box::pin(try_read_message(&words[..], Default::default()))); diff --git a/capnp-futures/test/test.rs b/capnp-futures/test/test.rs index 45a8b5c35..9afe65baa 100644 --- a/capnp-futures/test/test.rs +++ b/capnp-futures/test/test.rs @@ -165,6 +165,7 @@ mod tests { } #[test] + #[allow(clippy::let_underscore_future)] fn static_lifetime_not_required_funcs() { let (mut write, mut read) = async_byte_channel::channel(); let _ = serialize::try_read_message(&mut read, message::ReaderOptions::default()); diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index d189cf8ab..b754400b2 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -1645,7 +1645,7 @@ where match self.state { DisconnectorState::Connected => unreachable!(), DisconnectorState::Disconnecting => { - cx.waker().clone().wake(); + cx.waker().wake_by_ref(); Poll::Pending } DisconnectorState::Disconnected => Poll::Ready(Ok(())), diff --git a/capnp/src/primitive_list.rs b/capnp/src/primitive_list.rs index 4ea31a7b5..a35658a46 100644 --- a/capnp/src/primitive_list.rs +++ b/capnp/src/primitive_list.rs @@ -174,7 +174,7 @@ where #[cfg(target_endian = "little")] pub fn as_slice(&mut self) -> Option<&mut [T]> { if self.builder.get_element_size() == T::element_size() { - let bytes = self.builder.into_raw_bytes(); + let bytes = self.builder.as_raw_bytes(); Some(unsafe { core::slice::from_raw_parts_mut( bytes.as_mut_ptr() as *mut T, diff --git a/capnp/src/private/layout.rs b/capnp/src/private/layout.rs index 02ecb6e7b..646cc1d18 100644 --- a/capnp/src/private/layout.rs +++ b/capnp/src/private/layout.rs @@ -4091,7 +4091,7 @@ impl<'a> ListBuilder<'a> { } } - pub(crate) fn into_raw_bytes(&self) -> &'a mut [u8] { + pub(crate) fn as_raw_bytes(&self) -> &'a mut [u8] { if self.element_count == 0 { // Explictly handle this case to avoid forming a slice to a null pointer, // which would be undefined behavior. diff --git a/capnp/src/serialize.rs b/capnp/src/serialize.rs index 4f2568a83..af1476698 100644 --- a/capnp/src/serialize.rs +++ b/capnp/src/serialize.rs @@ -400,7 +400,7 @@ where } let start = (num_segment_counts_read + 1) * 4; - let end = start + (total_body_words as usize * 8); + let end = start + (total_body_words * 8); if buffer.len() < end { return Err(Error::from_kind(ErrorKind::BufferNotLargeEnough)); } diff --git a/capnpc/test/test_util.rs b/capnpc/test/test_util.rs index c5f299f6b..c4e38ffa7 100644 --- a/capnpc/test/test_util.rs +++ b/capnpc/test/test_util.rs @@ -527,7 +527,7 @@ pub fn dynamic_init_test_message(mut builder: ::capnp::dynamic_struct::Builder<' } pub fn dynamic_check_test_message(reader: capnp::dynamic_struct::Reader<'_>) { - assert_eq!((), reader.get_named("voidField").unwrap().downcast()); + reader.get_named("voidField").unwrap().downcast::<()>(); assert_eq!( true, reader.get_named("boolField").unwrap().downcast::() @@ -716,14 +716,11 @@ pub fn dynamic_check_test_message(reader: capnp::dynamic_struct::Reader<'_>) { } pub fn dynamic_check_test_message_builder(mut builder: capnp::dynamic_struct::Builder<'_>) { - assert_eq!( - (), - builder - .reborrow() - .get_named("voidField") - .unwrap() - .downcast() - ); + builder + .reborrow() + .get_named("voidField") + .unwrap() + .downcast::<()>(); assert_eq!( true, builder diff --git a/example/fill_random_values/src/lib.rs b/example/fill_random_values/src/lib.rs index 4601e6233..8a2b247af 100644 --- a/example/fill_random_values/src/lib.rs +++ b/example/fill_random_values/src/lib.rs @@ -56,13 +56,13 @@ impl Filler { fn fill_text(&mut self, mut builder: ::capnp::text::Builder) { builder.clear(); for _ in 0..builder.len() { - builder.push_ascii(self.rng.gen_range(b'a'..b'z')); + builder.push_ascii(self.rng.gen_range(b'a'..=b'z')); } } fn fill_data(&mut self, builder: ::capnp::data::Builder) { - for idx in 0..builder.len() { - builder[idx] = self.rng.gen::(); + for b in builder { + *b = self.rng.gen(); } } @@ -126,7 +126,7 @@ impl Filler { TypeVariant::Float32 => builder.set(field, self.rng.gen::().into()), TypeVariant::Float64 => builder.set(field, self.rng.gen::().into()), TypeVariant::Text => { - if let Some(_) = annotations.find(fill_capnp::phone_number::ID) { + if annotations.find(fill_capnp::phone_number::ID).is_some() { builder.set( field, format!( @@ -138,12 +138,14 @@ impl Filler { ) } else { let len = self.rng.gen_range(0..20); - Ok(self.fill_text(builder.initn(field, len)?.downcast())) + self.fill_text(builder.initn(field, len)?.downcast()); + Ok(()) } } TypeVariant::Data => { let len = self.rng.gen_range(0..20); - Ok(self.fill_data(builder.initn(field, len)?.downcast())) + self.fill_data(builder.initn(field, len)?.downcast()); + Ok(()) } TypeVariant::Enum(e) => builder.set(field, self.random_enum_value(e.into())?.into()), TypeVariant::Struct(_) => { @@ -198,11 +200,13 @@ impl Filler { TypeVariant::Enum(e) => builder.set(index, self.random_enum_value(e.into())?.into()), TypeVariant::Text => { let len = self.rng.gen_range(0..20); - Ok(self.fill_text(builder.init(index, len)?.downcast())) + self.fill_text(builder.init(index, len)?.downcast()); + Ok(()) } TypeVariant::Data => { let len = self.rng.gen_range(0..20); - Ok(self.fill_data(builder.init(index, len)?.downcast())) + self.fill_data(builder.init(index, len)?.downcast()); + Ok(()) } TypeVariant::Struct(_) => { self.fill_struct(recursion_depth + 1, builder.get(index)?.downcast()) From 28566ee497fe84064df76b989f89cbaf94343f55 Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Wed, 29 Nov 2023 06:35:25 +0000 Subject: [PATCH 2/4] fixup --- capnp-rpc/src/lib.rs | 6 ++++-- capnp-rpc/src/rpc.rs | 3 +-- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/capnp-rpc/src/lib.rs b/capnp-rpc/src/lib.rs index cfe538011..bcb01dd5e 100644 --- a/capnp-rpc/src/lib.rs +++ b/capnp-rpc/src/lib.rs @@ -108,6 +108,8 @@ mod split; mod task_set; pub mod twoparty; +use capnp::message; + pub trait OutgoingMessage { fn get_body(&mut self) -> ::capnp::Result<::capnp::any_pointer::Builder>; fn get_body_as_reader(&self) -> ::capnp::Result<::capnp::any_pointer::Reader>; @@ -117,8 +119,8 @@ pub trait OutgoingMessage { fn send( self: Box, ) -> ( - Promise>, ::capnp::Error>, - Rc<::capnp::message::Builder<::capnp::message::HeapAllocator>>, + Promise>, Error>, + Rc>, ); fn take(self: Box) -> ::capnp::message::Builder<::capnp::message::HeapAllocator>; diff --git a/capnp-rpc/src/rpc.rs b/capnp-rpc/src/rpc.rs index b754400b2..18e3a685e 100644 --- a/capnp-rpc/src/rpc.rs +++ b/capnp-rpc/src/rpc.rs @@ -1967,8 +1967,7 @@ where VatId: 'static, { variant: PipelineVariant, - redirect_later: - Option, ::capnp::Error>>>>, + redirect_later: Option, Error>>>>, connection_state: Rc>, #[allow(dead_code)] From 313aec373098fbdad129b51ec278ffb22b356bdb Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Wed, 29 Nov 2023 07:47:14 +0000 Subject: [PATCH 3/4] fixup --- capnpc/src/codegen.rs | 14 +++----------- 1 file changed, 3 insertions(+), 11 deletions(-) diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index 9449718eb..293934d64 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -484,15 +484,7 @@ pub fn line(inner: impl ToString) -> FormattedText { fn to_lines(ft: &FormattedText, indent: usize) -> Vec { match ft { Indent(ft) => to_lines(ft, indent + 1), - Branch(fts) => { - let mut result = Vec::new(); - for ft in fts { - for line in &to_lines(ft, indent) { - result.push(line.clone()); // TODO there's probably a better way to do this. - } - } - result - } + Branch(fts) => fts.iter().flat_map(|ft| to_lines(ft, indent)).collect(), Line(s) => { let mut s1: String = " ".repeat(indent * 2); s1.push_str(s); @@ -505,10 +497,10 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec { fn stringify(ft: &FormattedText) -> String { let mut result = to_lines(ft, 0).join("\n"); result.push('\n'); - result.to_string() + result } -const RUST_KEYWORDS: [&str; 53] = [ +const RUST_KEYWORDS: &[&str] = &[ "abstract", "alignof", "as", "be", "become", "box", "break", "const", "continue", "crate", "do", "else", "enum", "extern", "false", "final", "fn", "for", "if", "impl", "in", "let", "loop", "macro", "match", "mod", "move", "mut", "offsetof", "once", "override", "priv", "proc", From 9b376050e8faa42b205b7063686bc898d21268db Mon Sep 17 00:00:00 2001 From: Daniel Eades Date: Wed, 29 Nov 2023 08:06:33 +0000 Subject: [PATCH 4/4] fixup --- capnpc/src/codegen.rs | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/capnpc/src/codegen.rs b/capnpc/src/codegen.rs index 293934d64..db7a4703f 100644 --- a/capnpc/src/codegen.rs +++ b/capnpc/src/codegen.rs @@ -377,15 +377,15 @@ macro_rules! fmt( pub(crate) use fmt; fn path_to_stem_string>(path: P) -> ::capnp::Result { - match path.as_ref().file_stem() { - None => Err(Error::failed(format!( + if let Some(stem) = path.as_ref().file_stem() { + stem.to_owned() + .into_string() + .map_err(|os_string| Error::failed(format!("bad filename: {os_string:?}"))) + } else { + Err(Error::failed(format!( "file has no stem: {:?}", path.as_ref() - ))), - Some(stem) => match stem.to_owned().into_string() { - Err(os_string) => Err(Error::failed(format!("bad filename: {os_string:?}"))), - Ok(s) => Ok(s), - }, + ))) } }