Skip to content

Commit f2b4cbc

Browse files
committed
yet more clippy
1 parent d5c74da commit f2b4cbc

File tree

7 files changed

+89
-45
lines changed

7 files changed

+89
-45
lines changed

capnp/src/dynamic_list.rs

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ impl<'a> Builder<'a> {
161161
}
162162
}
163163

164-
pub fn reborrow<'b>(&'b mut self) -> Builder<'b> {
164+
pub fn reborrow(&mut self) -> Builder<'_> {
165165
Builder {
166166
builder: self.builder.reborrow(),
167167
element_type: self.element_type,
@@ -264,40 +264,52 @@ impl<'a> Builder<'a> {
264264
match (self.element_type.which(), value) {
265265
(TypeVariant::Void, _) => Ok(()),
266266
(TypeVariant::Bool, dynamic_value::Reader::Bool(b)) => {
267-
Ok(PrimitiveElement::set(&self.builder, index, b))
267+
PrimitiveElement::set(&self.builder, index, b);
268+
Ok(())
268269
}
269270
(TypeVariant::Int8, dynamic_value::Reader::Int8(x)) => {
270-
Ok(PrimitiveElement::set(&self.builder, index, x))
271+
PrimitiveElement::set(&self.builder, index, x);
272+
Ok(())
271273
}
272274
(TypeVariant::Int16, dynamic_value::Reader::Int16(x)) => {
273-
Ok(PrimitiveElement::set(&self.builder, index, x))
275+
PrimitiveElement::set(&self.builder, index, x);
276+
Ok(())
274277
}
275278
(TypeVariant::Int32, dynamic_value::Reader::Int32(x)) => {
276-
Ok(PrimitiveElement::set(&self.builder, index, x))
279+
PrimitiveElement::set(&self.builder, index, x);
280+
Ok(())
277281
}
278282
(TypeVariant::Int64, dynamic_value::Reader::Int64(x)) => {
279-
Ok(PrimitiveElement::set(&self.builder, index, x))
283+
PrimitiveElement::set(&self.builder, index, x);
284+
Ok(())
280285
}
281286
(TypeVariant::UInt8, dynamic_value::Reader::UInt8(x)) => {
282-
Ok(PrimitiveElement::set(&self.builder, index, x))
287+
PrimitiveElement::set(&self.builder, index, x);
288+
Ok(())
283289
}
284290
(TypeVariant::UInt16, dynamic_value::Reader::UInt16(x)) => {
285-
Ok(PrimitiveElement::set(&self.builder, index, x))
291+
PrimitiveElement::set(&self.builder, index, x);
292+
Ok(())
286293
}
287294
(TypeVariant::UInt32, dynamic_value::Reader::UInt32(x)) => {
288-
Ok(PrimitiveElement::set(&self.builder, index, x))
295+
PrimitiveElement::set(&self.builder, index, x);
296+
Ok(())
289297
}
290298
(TypeVariant::UInt64, dynamic_value::Reader::UInt64(x)) => {
291-
Ok(PrimitiveElement::set(&self.builder, index, x))
299+
PrimitiveElement::set(&self.builder, index, x);
300+
Ok(())
292301
}
293302
(TypeVariant::Float32, dynamic_value::Reader::Float32(x)) => {
294-
Ok(PrimitiveElement::set(&self.builder, index, x))
303+
PrimitiveElement::set(&self.builder, index, x);
304+
Ok(())
295305
}
296306
(TypeVariant::Float64, dynamic_value::Reader::Float64(x)) => {
297-
Ok(PrimitiveElement::set(&self.builder, index, x))
307+
PrimitiveElement::set(&self.builder, index, x);
308+
Ok(())
298309
}
299310
(TypeVariant::Enum(_es), dynamic_value::Reader::Enum(e)) => {
300-
Ok(PrimitiveElement::set(&self.builder, index, e.get_value()))
311+
PrimitiveElement::set(&self.builder, index, e.get_value());
312+
Ok(())
301313
}
302314
(TypeVariant::Text, dynamic_value::Reader::Text(t)) => Ok(self
303315
.builder

capnp/src/dynamic_struct.rs

Lines changed: 50 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -659,25 +659,62 @@ impl<'a> Builder<'a> {
659659
let offset = slot.get_offset() as usize;
660660
match ty.which() {
661661
TypeVariant::Void => Ok(()),
662-
TypeVariant::Bool => Ok(self.builder.set_bool_field(offset, false)),
663-
TypeVariant::Int8 => Ok(self.builder.set_data_field::<i8>(offset, 0)),
664-
TypeVariant::Int16 => Ok(self.builder.set_data_field::<i16>(offset, 0)),
665-
TypeVariant::Int32 => Ok(self.builder.set_data_field::<i32>(offset, 0)),
666-
TypeVariant::Int64 => Ok(self.builder.set_data_field::<i64>(offset, 0)),
667-
TypeVariant::UInt8 => Ok(self.builder.set_data_field::<u8>(offset, 0)),
668-
TypeVariant::UInt16 => Ok(self.builder.set_data_field::<u16>(offset, 0)),
669-
TypeVariant::UInt32 => Ok(self.builder.set_data_field::<u32>(offset, 0)),
670-
TypeVariant::UInt64 => Ok(self.builder.set_data_field::<u64>(offset, 0)),
671-
TypeVariant::Float32 => Ok(self.builder.set_data_field::<f32>(offset, 0f32)),
672-
TypeVariant::Float64 => Ok(self.builder.set_data_field::<f64>(offset, 0f64)),
673-
TypeVariant::Enum(_) => Ok(self.builder.set_data_field::<u16>(offset, 0)),
662+
TypeVariant::Bool => {
663+
self.builder.set_bool_field(offset, false);
664+
Ok(())
665+
}
666+
TypeVariant::Int8 => {
667+
self.builder.set_data_field::<i8>(offset, 0);
668+
Ok(())
669+
}
670+
TypeVariant::Int16 => {
671+
self.builder.set_data_field::<i16>(offset, 0);
672+
Ok(())
673+
}
674+
TypeVariant::Int32 => {
675+
self.builder.set_data_field::<i32>(offset, 0);
676+
Ok(())
677+
}
678+
TypeVariant::Int64 => {
679+
self.builder.set_data_field::<i64>(offset, 0);
680+
Ok(())
681+
}
682+
TypeVariant::UInt8 => {
683+
self.builder.set_data_field::<u8>(offset, 0);
684+
Ok(())
685+
}
686+
TypeVariant::UInt16 => {
687+
self.builder.set_data_field::<u16>(offset, 0);
688+
Ok(())
689+
}
690+
TypeVariant::UInt32 => {
691+
self.builder.set_data_field::<u32>(offset, 0);
692+
Ok(())
693+
}
694+
TypeVariant::UInt64 => {
695+
self.builder.set_data_field::<u64>(offset, 0);
696+
Ok(())
697+
}
698+
TypeVariant::Float32 => {
699+
self.builder.set_data_field::<f32>(offset, 0f32);
700+
Ok(())
701+
}
702+
TypeVariant::Float64 => {
703+
self.builder.set_data_field::<f64>(offset, 0f64);
704+
Ok(())
705+
}
706+
TypeVariant::Enum(_) => {
707+
self.builder.set_data_field::<u16>(offset, 0);
708+
Ok(())
709+
}
674710
TypeVariant::Text
675711
| TypeVariant::Data
676712
| TypeVariant::Struct(_)
677713
| TypeVariant::List(_)
678714
| TypeVariant::AnyPointer
679715
| TypeVariant::Capability => {
680-
Ok(self.builder.reborrow().get_pointer_field(offset).clear())
716+
self.builder.reborrow().get_pointer_field(offset).clear();
717+
Ok(())
681718
}
682719
}
683720
}

capnp/src/dynamic_value.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -102,7 +102,7 @@ pub trait DowncastReader<'a> {
102102
}
103103

104104
impl<'a> DowncastReader<'a> for () {
105-
fn downcast_reader(value: Reader<'a>) -> () {
105+
fn downcast_reader(value: Reader<'a>) {
106106
let Reader::Void = value else {
107107
panic!("error downcasting to void")
108108
};
@@ -162,7 +162,7 @@ pub enum Builder<'a> {
162162
}
163163

164164
impl<'a> Builder<'a> {
165-
pub fn reborrow<'b>(&'b mut self) -> Builder<'b> {
165+
pub fn reborrow(&mut self) -> Builder<'_> {
166166
match self {
167167
Builder::Void => Builder::Void,
168168
Builder::Bool(b) => Builder::Bool(*b),
@@ -223,7 +223,7 @@ pub trait DowncastBuilder<'a> {
223223
}
224224

225225
impl<'a> DowncastBuilder<'a> for () {
226-
fn downcast_builder(value: Builder<'a>) -> () {
226+
fn downcast_builder(value: Builder<'a>) {
227227
let Builder::Void = value else {
228228
panic!("error downcasting to void")
229229
};

capnp/src/introspect.rs

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -94,14 +94,14 @@ impl Type {
9494
if self.list_count > 0 {
9595
true
9696
} else {
97-
match self.base {
97+
matches!(
98+
self.base,
9899
BaseType::Text
99-
| BaseType::Data
100-
| BaseType::AnyPointer
101-
| BaseType::Struct(_)
102-
| BaseType::Capability => true,
103-
_ => false,
104-
}
100+
| BaseType::Data
101+
| BaseType::AnyPointer
102+
| BaseType::Struct(_)
103+
| BaseType::Capability
104+
)
105105
}
106106
}
107107
}

capnp/src/private/layout.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -494,7 +494,7 @@ mod wire_helpers {
494494
Ok((ptr, reff, segment_id))
495495
}
496496
} else {
497-
Ok((ref_target as *mut u8, reff, segment_id))
497+
Ok((ref_target, reff, segment_id))
498498
}
499499
}
500500

@@ -2656,7 +2656,7 @@ mod wire_helpers {
26562656
));
26572657
}
26582658

2659-
let str_ptr = ptr as *const u8;
2659+
let str_ptr = ptr;
26602660

26612661
if (*str_ptr.offset((size - 1) as isize)) != 0u8 {
26622662
return Err(Error::from_kind(

capnp/src/schema.rs

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -406,12 +406,7 @@ impl AnnotationList {
406406
/// Returns the first annotation in the list that matches `id`.
407407
/// Otherwise returns `None`.
408408
pub fn find(self, id: u64) -> Option<Annotation> {
409-
for annotation in self.iter() {
410-
if annotation.get_id() == id {
411-
return Some(annotation);
412-
}
413-
}
414-
None
409+
self.iter().find(|&annotation| annotation.get_id() == id)
415410
}
416411

417412
pub fn iter(self) -> ListIter<Self, Annotation> {

capnp/src/text.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -214,7 +214,7 @@ impl<'a> Builder<'a> {
214214
self.pos = 0;
215215
}
216216

217-
pub fn reborrow<'b>(&'b mut self) -> Builder<'b> {
217+
pub fn reborrow(&mut self) -> Builder<'_> {
218218
Builder {
219219
bytes: self.bytes,
220220
pos: self.pos,

0 commit comments

Comments
 (0)