Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

squash some lints #459

Merged
merged 4 commits into from
Nov 29, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions capnp-futures/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -563,7 +563,7 @@ pub mod test {
) -> Poll<io::Result<usize>> {
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());
Expand Down Expand Up @@ -619,7 +619,7 @@ pub mod test {
) -> Poll<io::Result<usize>> {
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());
Expand Down
4 changes: 2 additions & 2 deletions capnp-futures/src/serialize_packed.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 =
Expand All @@ -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())));

Expand Down
1 change: 1 addition & 0 deletions capnp-futures/test/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
6 changes: 4 additions & 2 deletions capnp-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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>;
Expand All @@ -117,8 +119,8 @@ pub trait OutgoingMessage {
fn send(
self: Box<Self>,
) -> (
Promise<Rc<::capnp::message::Builder<::capnp::message::HeapAllocator>>, ::capnp::Error>,
Rc<::capnp::message::Builder<::capnp::message::HeapAllocator>>,
Promise<Rc<message::Builder<message::HeapAllocator>>, Error>,
Rc<message::Builder<message::HeapAllocator>>,
);

fn take(self: Box<Self>) -> ::capnp::message::Builder<::capnp::message::HeapAllocator>;
Expand Down
5 changes: 2 additions & 3 deletions capnp-rpc/src/rpc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(())),
Expand Down Expand Up @@ -1967,8 +1967,7 @@ where
VatId: 'static,
{
variant: PipelineVariant<VatId>,
redirect_later:
Option<RefCell<futures::future::Shared<Promise<Response<VatId>, ::capnp::Error>>>>,
redirect_later: Option<RefCell<futures::future::Shared<Promise<Response<VatId>, Error>>>>,
connection_state: Rc<ConnectionState<VatId>>,

#[allow(dead_code)]
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/primitive_list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/private/layout.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
2 changes: 1 addition & 1 deletion capnp/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
Expand Down
28 changes: 10 additions & 18 deletions capnpc/src/codegen.rs
Original file line number Diff line number Diff line change
Expand Up @@ -377,15 +377,15 @@ macro_rules! fmt(
pub(crate) use fmt;

fn path_to_stem_string<P: AsRef<::std::path::Path>>(path: P) -> ::capnp::Result<String> {
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),
},
)))
}
}

Expand Down Expand Up @@ -484,15 +484,7 @@ pub fn line(inner: impl ToString) -> FormattedText {
fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
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);
Expand All @@ -505,10 +497,10 @@ fn to_lines(ft: &FormattedText, indent: usize) -> Vec<String> {
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",
Expand Down
15 changes: 6 additions & 9 deletions capnpc/test/test_util.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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::<bool>()
Expand Down Expand Up @@ -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
Expand Down
20 changes: 12 additions & 8 deletions example/fill_random_values/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -56,13 +56,13 @@ impl<R: Rng> Filler<R> {
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::<u8>();
for b in builder {
*b = self.rng.gen();
}
}

Expand Down Expand Up @@ -126,7 +126,7 @@ impl<R: Rng> Filler<R> {
TypeVariant::Float32 => builder.set(field, self.rng.gen::<f32>().into()),
TypeVariant::Float64 => builder.set(field, self.rng.gen::<f64>().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!(
Expand All @@ -138,12 +138,14 @@ impl<R: Rng> Filler<R> {
)
} 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(_) => {
Expand Down Expand Up @@ -198,11 +200,13 @@ impl<R: Rng> Filler<R> {
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())
Expand Down
Loading