Skip to content

Commit 71eb2e4

Browse files
committed
Manually fix a part of the remaining clippy warnings in capnp
Summary of fixed clippy errors and warnings: error: this public function might dereference a raw pointer but is not marked `unsafe` error: this `if` has identical blocks warning: match expression looks like `matches!` macro warning: very complex type used. Consider factoring parts into `type` definitions warning: this function has too many arguments (10/7) warning: methods called `into_*` usually take `self` by value warning: struct `FieldList` has a public `len` method, but no `is_empty` method warning: this lifetime isn't used in the impl $ cargo clippy Checking capnp v0.17.2 (/home/amiculas/work/capnproto-rust/capnp) warning: match expression looks like `matches!` macro --> capnp/src/introspect.rs:99:13 | 99 | / match self.base { 100 | | BaseType::Text 101 | | | BaseType::Data 102 | | | BaseType::AnyPointer ... | 105 | | _ => false, 106 | | } | |_____________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#match_like_matches_macro = note: `#[warn(clippy::match_like_matches_macro)]` on by default help: try this | 99 ~ matches!(self.base, BaseType::Text 100 + | BaseType::Data 101 + | BaseType::AnyPointer 102 + | BaseType::Struct(_) 103 + | BaseType::Capability) | warning: very complex type used. Consider factoring parts into `type` definitions --> capnp/src/private/capability.rs:40:10 | 40 | ) -> Option<( | __________^ 41 | | u32, 42 | | crate::capability::Promise<(), crate::Error>, 43 | | Box<dyn PipelineHook>, 44 | | )>; | |______^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#type_complexity = note: `#[warn(clippy::type_complexity)]` on by default error: this public function might dereference a raw pointer but is not marked `unsafe` --> capnp/src/private/layout.rs:164:48 | 164 | unsafe { this_addr.offset(8 * (1 + (((*ptr).offset_and_kind.get() as i32) >> 2)) as isize) } | ^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#not_unsafe_ptr_arg_deref = note: `#[deny(clippy::not_unsafe_ptr_arg_deref)]` on by default warning: this function has too many arguments (10/7) --> capnp/src/private/layout.rs:2187:5 | 2187 | / pub unsafe fn copy_pointer( 2188 | | dst_arena: &mut dyn BuilderArena, 2189 | | dst_segment_id: u32, 2190 | | #[cfg(feature = "alloc")] dst_cap_table: CapTableBuilder, ... | 2197 | | canonicalize: bool, 2198 | | ) -> Result<SegmentAnd<*mut u8>> { | |____________________________________^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#too_many_arguments = note: `#[warn(clippy::too_many_arguments)]` on by default warning: methods called `into_*` usually take `self` by value --> capnp/src/private/layout.rs:4170:34 | 4170 | pub(crate) fn into_raw_bytes(&self) -> &'a m�[Iut [u8] { | ^^^^^ | = help: consider choosing a less ambiguous name = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#wrong_self_convention = note: `#[warn(clippy::wrong_self_convention)]` on by default warning: struct `FieldList` has a public `len` method, but no `is_empty` method --> capnp/src/schema.rs:160:5 | 160 | pub fn len(&self) -> u16 { | ^^^^^^^^^^^^^^^^^^^^^^^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#len_without_is_empty = note: `#[warn(clippy::len_without_is_empty)]` on by default warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:177:6 | 177 | impl<'a> IndexMove<u16, Field> for FieldList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes = note: `#[warn(clippy::extra_unused_lifetimes)]` on by default warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:183:6 | 183 | impl<'a> ::core::iter::IntoIterator for FieldList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:223:6 | 223 | impl<'a> IndexMove<u16, Field> for FieldSubset { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:229:6 | 229 | impl<'a> ::core::iter::IntoIterator for FieldSubset { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:344:6 | 344 | impl<'a> IndexMove<u16, Enumerant> for EnumerantList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:350:6 | 350 | impl<'a> ::core::iter::IntoIterator for EnumerantList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:417:6 | 417 | impl<'a> IndexMove<u32, Annotation> for AnnotationList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes warning: this lifetime isn't used in the impl --> capnp/src/schema.rs:423:6 | 423 | impl<'a> ::core::iter::IntoIterator for AnnotationList { | ^^ | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#extra_unused_lifetimes error: this `if` has identical blocks --> capnp/src/serialize.rs:355:46 | 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 { | |_____^ | note: same as this --> capnp/src/serialize.rs:359:34 | 359 | } else if segment_count == 0 { | __________________________________^ 360 | | return Err(Error::from_kind(ErrorKind::InvalidNumberOfSegments( 361 | | segment_count, 362 | | ))); 363 | | } | |_____^ = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#if_same_then_else = note: `#[deny(clippy::if_same_then_else)]` on by default warning: `capnp` (lib) generated 16 warnings error: could not compile `capnp` (lib) due to 2 previous errors; 16 warnings emitted
1 parent 2baca94 commit 71eb2e4

File tree

11 files changed

+42
-45
lines changed

11 files changed

+42
-45
lines changed

capnp-rpc/src/broken.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121

2222
use capnp::any_pointer;
2323
use capnp::private::capability::{
24-
ClientHook, ParamsHook, PipelineHook, PipelineOp, RequestHook, ResultsHook,
24+
ClientHook, ParamsHook, PipelineHook, PipelineOp, RequestHook, ResultsHook, TailSendReturnType,
2525
};
2626
use capnp::Error;
2727

@@ -81,7 +81,7 @@ impl RequestHook for Request {
8181
pipeline: any_pointer::Pipeline::new(Box::new(pipeline)),
8282
}
8383
}
84-
fn tail_send(self: Box<Self>) -> Option<(u32, Promise<(), Error>, Box<dyn PipelineHook>)> {
84+
fn tail_send(self: Box<Self>) -> TailSendReturnType {
8585
None
8686
}
8787
}

capnp-rpc/src/local.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
use capnp::capability::{self, Promise};
2222
use capnp::private::capability::{
2323
ClientHook, ParamsHook, PipelineHook, PipelineOp, RequestHook, ResponseHook, ResultsHook,
24+
TailSendReturnType,
2425
};
2526
use capnp::traits::{Imbue, ImbueMut};
2627
use capnp::Error;
@@ -250,7 +251,7 @@ impl RequestHook for Request {
250251
pipeline,
251252
}
252253
}
253-
fn tail_send(self: Box<Self>) -> Option<(u32, Promise<(), Error>, Box<dyn PipelineHook>)> {
254+
fn tail_send(self: Box<Self>) -> TailSendReturnType {
254255
unimplemented!()
255256
}
256257
}

capnp-rpc/src/reconnect.rs

+2-8
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::marker::PhantomData;
33
use std::rc::Rc;
44

55
use capnp::capability::{FromClientHook, Promise};
6-
use capnp::private::capability::{ClientHook, RequestHook};
6+
use capnp::private::capability::{ClientHook, RequestHook, TailSendReturnType};
77
use futures::TryFutureExt;
88

99
pub trait SetTarget<C> {
@@ -203,13 +203,7 @@ where
203203
result
204204
}
205205

206-
fn tail_send(
207-
self: Box<Self>,
208-
) -> Option<(
209-
u32,
210-
Promise<(), capnp::Error>,
211-
Box<dyn capnp::private::capability::PipelineHook>,
212-
)> {
206+
fn tail_send(self: Box<Self>) -> TailSendReturnType {
213207
todo!()
214208
}
215209
}

capnp-rpc/src/rpc.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@ use capnp::any_pointer;
2626
use capnp::capability::Promise;
2727
use capnp::private::capability::{
2828
ClientHook, ParamsHook, PipelineHook, PipelineOp, RequestHook, ResponseHook, ResultsHook,
29+
TailSendReturnType,
2930
};
3031
use capnp::Error;
3132

@@ -1909,7 +1910,7 @@ impl<VatId> RequestHook for Request<VatId> {
19091910
}
19101911
}
19111912
}
1912-
fn tail_send(self: Box<Self>) -> Option<(u32, Promise<(), Error>, Box<dyn PipelineHook>)> {
1913+
fn tail_send(self: Box<Self>) -> TailSendReturnType {
19131914
let tmp = *self;
19141915
let Self {
19151916
connection_state,

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/capability.rs

+7-7
Original file line numberDiff line numberDiff line change
@@ -31,17 +31,17 @@ pub trait ResponseHook {
3131
fn get(&self) -> crate::Result<any_pointer::Reader<'_>>;
3232
}
3333

34+
pub type TailSendReturnType = Option<(
35+
u32,
36+
crate::capability::Promise<(), crate::Error>,
37+
Box<dyn PipelineHook>,
38+
)>;
39+
3440
pub trait RequestHook {
3541
fn get(&mut self) -> any_pointer::Builder<'_>;
3642
fn get_brand(&self) -> usize;
3743
fn send(self: Box<Self>) -> RemotePromise<any_pointer::Owned>;
38-
fn tail_send(
39-
self: Box<Self>,
40-
) -> Option<(
41-
u32,
42-
crate::capability::Promise<(), crate::Error>,
43-
Box<dyn PipelineHook>,
44-
)>;
44+
fn tail_send(self: Box<Self>) -> TailSendReturnType;
4545
}
4646

4747
pub trait ClientHook {

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)