Skip to content

Commit 6e70f4c

Browse files
committed
Manually fix a part of the remaining clippy warnings in capnp
1 parent 2baca94 commit 6e70f4c

File tree

6 files changed

+27
-26
lines changed

6 files changed

+27
-26
lines changed

capnp/src/introspect.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -96,14 +96,14 @@ impl Type {
9696
if self.list_count > 0 {
9797
true
9898
} else {
99-
match self.base {
99+
matches!(
100+
self.base,
100101
BaseType::Text
101-
| BaseType::Data
102-
| BaseType::AnyPointer
103-
| BaseType::Struct(_)
104-
| BaseType::Capability => true,
105-
_ => false,
106-
}
102+
| BaseType::Data
103+
| BaseType::AnyPointer
104+
| BaseType::Struct(_)
105+
| BaseType::Capability
106+
)
107107
}
108108
}
109109
}

capnp/src/primitive_list.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,7 @@ impl<'a, T: PrimitiveElement> Reader<'a, T> {
116116
/// Returns something if the slice is as expected in memory.
117117
pub fn as_slice(&self) -> Option<&[T]> {
118118
if self.reader.get_element_size() == T::element_size() {
119-
let bytes = self.reader.into_raw_bytes();
119+
let bytes = self.reader.as_raw_bytes();
120120
Some(unsafe {
121121
use core::slice;
122122
slice::from_raw_parts(
@@ -174,7 +174,7 @@ where
174174
#[cfg(all(target_endian = "little"))]
175175
pub fn as_slice(&mut self) -> Option<&mut [T]> {
176176
if self.builder.get_element_size() == T::element_size() {
177-
let bytes = self.builder.into_raw_bytes();
177+
let bytes = self.builder.as_raw_bytes();
178178
Some(unsafe {
179179
core::slice::from_raw_parts_mut(
180180
bytes.as_mut_ptr() as *mut T,

capnp/src/private/layout.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ impl WirePointer {
159159
}
160160

161161
#[inline]
162-
pub fn target(ptr: *const Self) -> *const u8 {
162+
pub unsafe fn target(ptr: *const Self) -> *const u8 {
163163
let this_addr: *const u8 = ptr as *const _;
164164
unsafe { this_addr.offset(8 * (1 + (((*ptr).offset_and_kind.get() as i32) >> 2)) as isize) }
165165
}
@@ -2184,6 +2184,7 @@ mod wire_helpers {
21842184
}
21852185
}
21862186

2187+
#[allow(clippy::too_many_arguments)]
21872188
pub unsafe fn copy_pointer(
21882189
dst_arena: &mut dyn BuilderArena,
21892190
dst_segment_id: u32,
@@ -3904,7 +3905,7 @@ impl<'a> ListReader<'a> {
39043905
self.element_size
39053906
}
39063907

3907-
pub(crate) fn into_raw_bytes(self) -> &'a [u8] {
3908+
pub(crate) fn as_raw_bytes(self) -> &'a [u8] {
39083909
if self.element_count == 0 {
39093910
// Explictly handle this case to avoid forming a slice to a null pointer,
39103911
// which would be undefined behavior.
@@ -4167,7 +4168,7 @@ impl<'a> ListBuilder<'a> {
41674168
}
41684169
}
41694170

4170-
pub(crate) fn into_raw_bytes(&self) -> &'a mut [u8] {
4171+
pub(crate) fn as_raw_bytes(&self) -> &'a mut [u8] {
41714172
if self.element_count == 0 {
41724173
// Explictly handle this case to avoid forming a slice to a null pointer,
41734174
// which would be undefined behavior.

capnp/src/raw.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -65,5 +65,5 @@ pub fn get_list_bytes<'a, T>(value: T) -> &'a [u8]
6565
where
6666
T: IntoInternalListReader<'a>,
6767
{
68-
value.into_internal_list_reader().into_raw_bytes()
68+
value.into_internal_list_reader().as_raw_bytes()
6969
}

capnp/src/schema.rs

+12-8
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ impl FieldList {
161161
self.fields.len() as u16
162162
}
163163

164+
pub fn is_empty(&self) -> bool {
165+
self.len() == 0
166+
}
167+
164168
pub fn get(self, index: u16) -> Field {
165169
Field {
166170
proto: self.fields.get(index as u32),
@@ -174,13 +178,13 @@ impl FieldList {
174178
}
175179
}
176180

177-
impl<'a> IndexMove<u16, Field> for FieldList {
181+
impl IndexMove<u16, Field> for FieldList {
178182
fn index_move(&self, index: u16) -> Field {
179183
self.get(index)
180184
}
181185
}
182186

183-
impl<'a> ::core::iter::IntoIterator for FieldList {
187+
impl ::core::iter::IntoIterator for FieldList {
184188
type Item = Field;
185189
type IntoIter = ShortListIter<FieldList, Self::Item>;
186190

@@ -220,13 +224,13 @@ impl FieldSubset {
220224
}
221225
}
222226

223-
impl<'a> IndexMove<u16, Field> for FieldSubset {
227+
impl IndexMove<u16, Field> for FieldSubset {
224228
fn index_move(&self, index: u16) -> Field {
225229
self.get(index)
226230
}
227231
}
228232

229-
impl<'a> ::core::iter::IntoIterator for FieldSubset {
233+
impl ::core::iter::IntoIterator for FieldSubset {
230234
type Item = Field;
231235
type IntoIter = ShortListIter<FieldSubset, Self::Item>;
232236

@@ -341,13 +345,13 @@ impl EnumerantList {
341345
}
342346
}
343347

344-
impl<'a> IndexMove<u16, Enumerant> for EnumerantList {
348+
impl IndexMove<u16, Enumerant> for EnumerantList {
345349
fn index_move(&self, index: u16) -> Enumerant {
346350
self.get(index)
347351
}
348352
}
349353

350-
impl<'a> ::core::iter::IntoIterator for EnumerantList {
354+
impl ::core::iter::IntoIterator for EnumerantList {
351355
type Item = Enumerant;
352356
type IntoIter = ShortListIter<Self, Self::Item>;
353357

@@ -414,13 +418,13 @@ impl AnnotationList {
414418
}
415419
}
416420

417-
impl<'a> IndexMove<u32, Annotation> for AnnotationList {
421+
impl IndexMove<u32, Annotation> for AnnotationList {
418422
fn index_move(&self, index: u32) -> Annotation {
419423
self.get(index)
420424
}
421425
}
422426

423-
impl<'a> ::core::iter::IntoIterator for AnnotationList {
427+
impl ::core::iter::IntoIterator for AnnotationList {
424428
type Item = Annotation;
425429
type IntoIter = ListIter<Self, Self::Item>;
426430

capnp/src/serialize.rs

+1-5
Original file line numberDiff line numberDiff line change
@@ -352,11 +352,7 @@ where
352352

353353
let segment_count = u32::from_le_bytes(buf[0..4].try_into().unwrap()).wrapping_add(1) as usize;
354354

355-
if segment_count >= SEGMENTS_COUNT_LIMIT {
356-
return Err(Error::from_kind(ErrorKind::InvalidNumberOfSegments(
357-
segment_count,
358-
)));
359-
} else if segment_count == 0 {
355+
if segment_count >= SEGMENTS_COUNT_LIMIT || segment_count == 0 {
360356
return Err(Error::from_kind(ErrorKind::InvalidNumberOfSegments(
361357
segment_count,
362358
)));

0 commit comments

Comments
 (0)