Skip to content

Clippy ci #1

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

Open
wants to merge 30 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
f451550
mark unsafe methods
danieleades Nov 20, 2022
15442db
use 'std::mem::take'
danieleades Nov 20, 2022
ab81cda
remove redundant clones
danieleades Nov 20, 2022
8a41773
remove redundant static lifetimes on consts
danieleades Nov 20, 2022
010ee24
remove needless range loops
danieleades Nov 21, 2022
a30f2c8
use byte literals
danieleades Nov 21, 2022
3e1f8e4
use 'iter::next'
danieleades Nov 21, 2022
2418c5c
avoid using 'ref' on let statements
danieleades Nov 21, 2022
d0da77c
remove redundant pattern matching
danieleades Nov 21, 2022
051e3f9
add 'is_empty' method
danieleades Nov 21, 2022
bcd387c
remove redundant field names
danieleades Nov 21, 2022
2967f93
flatten single match blocks
danieleades Nov 21, 2022
4adfc8f
remove useless conversions
Nov 21, 2022
a99f036
suppress warnings for 'clippy::bool_assert_comparison'
Nov 21, 2022
3497e24
don't pass mut references if you don't need to
Nov 21, 2022
53ca6ab
remove explicit deref
Nov 21, 2022
8c83da0
add 'Default' implementation
Nov 21, 2022
b25b9f5
remove redundant static lifetimes
Nov 21, 2022
57fc748
remove needless return statements
Nov 21, 2022
fd264c6
remove needless borrows
Nov 21, 2022
ba787d4
use 'as_mut'
Nov 21, 2022
bd182b6
prefer 'if let' to 'Option::map'
Nov 21, 2022
8c6dfef
prefer 'map' to 'and_then'
Nov 21, 2022
e5d1462
use built-in 'map' method
Nov 21, 2022
10f761a
use 'is_empty'
Nov 21, 2022
c56b44e
remove comparison to unit value
Nov 21, 2022
c00d861
remove redundant closures
Nov 21, 2022
6c7e43b
omit useless 'let' binding
Nov 21, 2022
fc91ed8
flatten single match blocks
danieleades Nov 21, 2022
2cf9474
add clippy CI target
danieleades Nov 19, 2022
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
1 change: 1 addition & 0 deletions .clippy.toml
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
msrv = "1.65.0"
20 changes: 20 additions & 0 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -103,3 +103,23 @@ jobs:
with:
command: fmt
args: --all -- --check

lint:
name: lint
runs-on: ubuntu-latest
steps:
- name: Install Cap'n Proto
run: |
export DEBIAN_FRONTEND=noninteractive
sudo apt-get install -y capnproto libcapnp-dev
- uses: actions/checkout@v3
- uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: nightly-2022-10-18
override: true
components: clippy
- uses: giraffate/clippy-action@v1
with:
clippy_flags: --all --all-targets
filter_mode: nofilter
30 changes: 18 additions & 12 deletions benchmark/benchmark.rs
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ impl Serialize for NoCompression {
W: io::Write,
A: message::Allocator,
{
serialize::write_message(write, message).map_err(|e| e.into())
serialize::write_message(write, message)
}
}

Expand All @@ -133,7 +133,7 @@ impl Serialize for Packed {
W: io::Write,
A: message::Allocator,
{
serialize_packed::write_message(write, message).map_err(|e| e.into())
serialize_packed::write_message(write, message)
}
}

Expand Down Expand Up @@ -161,15 +161,21 @@ pub struct UseScratch {
buffer2: Vec<capnp::Word>,
}

impl UseScratch {
pub fn new() -> UseScratch {
UseScratch {
impl Default for UseScratch {
fn default() -> Self {
Self {
buffer1: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
buffer2: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
}
}
}

impl UseScratch {
pub fn new() -> Self {
Self::default()
}
}

impl<'a> Scratch<'a> for UseScratch {
type Allocator = message::ScratchSpaceHeapAllocator<'a>;

Expand Down Expand Up @@ -234,7 +240,7 @@ where

{
let mut writer: &mut [u8] = &mut request_bytes;
compression.write_message(&mut writer, &mut message_req)?;
compression.write_message(&mut writer, &message_req)?;
}

let mut request_bytes1: &[u8] = &request_bytes;
Expand All @@ -247,7 +253,7 @@ where

{
let mut writer: &mut [u8] = &mut response_bytes;
compression.write_message(&mut writer, &mut message_res)?;
compression.write_message(&mut writer, &message_res)?;
}

let mut response_bytes1: &[u8] = &response_bytes;
Expand Down Expand Up @@ -289,7 +295,7 @@ where
testcase.handle_request(request_reader, response)?;
}

compression.write_message(&mut out_buffered, &mut message_res)?;
compression.write_message(&mut out_buffered, &message_res)?;
out_buffered.flush()?;
}
Ok(())
Expand Down Expand Up @@ -320,7 +326,7 @@ where
let request = message_req.init_root();
testcase.setup_request(&mut rng, request)
};
compression.write_message(&mut out_buffered, &mut message_req)?;
compression.write_message(&mut out_buffered, &message_req)?;
out_buffered.flush()?;

let message_reader = compression.read_message(&mut in_buffered, Default::default())?;
Expand Down Expand Up @@ -475,11 +481,11 @@ fn try_main() -> ::capnp::Result<()> {
}
};

let mode = Mode::parse(&*args[2])?;
let mode = Mode::parse(&args[2])?;

match &*args[4] {
"none" => do_testcase2(&*args[1], mode, &*args[3], NoCompression, iters),
"packed" => do_testcase2(&*args[1], mode, &*args[3], Packed, iters),
"none" => do_testcase2(&args[1], mode, &args[3], NoCompression, iters),
"packed" => do_testcase2(&args[1], mode, &args[3], Packed, iters),
s => Err(::capnp::Error::failed(format!(
"unrecognized compression: {}",
s
Expand Down
4 changes: 2 additions & 2 deletions benchmark/carsales.rs
Original file line number Diff line number Diff line change
Expand Up @@ -78,8 +78,8 @@ macro_rules! car_value_impl(
car_value_impl!(Reader);
car_value_impl!(Builder);

const MAKES: [&'static str; 5] = ["Toyota", "GM", "Ford", "Honda", "Tesla"];
const MODELS: [&'static str; 6] = ["Camry", "Prius", "Volt", "Accord", "Leaf", "Model S"];
const MAKES: [&str; 5] = ["Toyota", "GM", "Ford", "Honda", "Tesla"];
const MODELS: [&str; 6] = ["Camry", "Prius", "Volt", "Accord", "Leaf", "Model S"];

pub fn random_car(rng: &mut FastRand, mut car: car::Builder) {
car.set_make(MAKES[rng.next_less_than(MAKES.len() as u32) as usize]);
Expand Down
7 changes: 2 additions & 5 deletions benchmark/catrank.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ pub struct ScoredResult<'a> {
result: search_result::Reader<'a>,
}

const URL_PREFIX: &'static str = "http://example.com";
const URL_PREFIX: &str = "http://example.com";

pub struct CatRank;

Expand Down Expand Up @@ -108,10 +108,7 @@ impl crate::TestCase for CatRank {
if snippet.contains(" dog ") {
score /= 10000.0;
}
scored_results.push(ScoredResult {
score: score,
result: result,
});
scored_results.push(ScoredResult { score, result });
}

// sort in decreasing order
Expand Down
20 changes: 13 additions & 7 deletions benchmark/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,21 @@ pub struct FastRand {
w: u32,
}

impl FastRand {
pub fn new() -> FastRand {
FastRand {
impl Default for FastRand {
fn default() -> Self {
Self {
x: 0x1d2acd47,
y: 0x58ca3e14,
z: 0xf563f232,
w: 0x0bc76199,
}
}
}

impl FastRand {
pub fn new() -> FastRand {
Self::default()
}

#[inline]
pub fn next_u32(&mut self) -> u32 {
Expand All @@ -46,7 +52,7 @@ impl FastRand {
self.y = self.z;
self.z = self.w;
self.w = self.w ^ (self.w >> 19) ^ tmp ^ (tmp >> 8);
return self.w;
self.w
}

#[inline]
Expand Down Expand Up @@ -74,7 +80,7 @@ pub fn div(a: i32, b: i32) -> i32 {
if a == i32::MIN && b == -1 {
return i32::MAX;
}
return a / b;
a / b
}

#[inline]
Expand All @@ -85,10 +91,10 @@ pub fn modulus(a: i32, b: i32) -> i32 {
if a == i32::MIN && b == -1 {
return i32::MAX;
}
return a % b;
a % b
}

pub const WORDS: [&'static str; 13] = [
pub const WORDS: [&str; 13] = [
"foo ", "bar ", "baz ", "qux ", "quux ", "corge ", "grault ", "garply ", "waldo ", "fred ",
"plugh ", "xyzzy ", "thud ",
];
10 changes: 5 additions & 5 deletions benchmark/eval.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,11 @@ fn make_expression(rng: &mut FastRand, mut exp: expression::Builder, depth: u32)
};

match exp.get_op().unwrap() {
Operation::Add => return left + right,
Operation::Subtract => return left - right,
Operation::Multiply => return left * right,
Operation::Divide => return div(left, right),
Operation::Modulus => return modulus(left, right),
Operation::Add => left + right,
Operation::Subtract => left - right,
Operation::Multiply => left * right,
Operation::Divide => div(left, right),
Operation::Modulus => modulus(left, right),
}
}

Expand Down
8 changes: 4 additions & 4 deletions capnp-futures/src/serialize.rs
Original file line number Diff line number Diff line change
Expand Up @@ -231,8 +231,8 @@ where
.copy_from_slice(&((segments[idx].len() / 8) as u32).to_le_bytes());
}
if segment_count == 2 {
for idx in 4..8 {
buf[idx] = 0
for value in buf.iter_mut().skip(4).take(4) {
*value = 0;
}
}
write.write_all(&buf).await?;
Expand All @@ -258,8 +258,8 @@ async fn write_segments<W>(mut write: W, segments: &[&[u8]]) -> Result<()>
where
W: AsyncWrite + Unpin,
{
for i in 0..segments.len() {
write.write_all(segments[i]).await?;
for segment in segments {
write.write_all(segment).await?;
}
Ok(())
}
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 @@ -122,8 +122,8 @@ where
PackedReadStage::WritingZeroes => {
let num_zeroes = std::cmp::min(outbuf.len(), *num_run_bytes_remaining);

for ii in 0..num_zeroes {
outbuf[ii] = 0;
for value in outbuf.iter_mut().take(num_zeroes) {
*value = 0;
}
if num_zeroes >= *num_run_bytes_remaining {
*buf_pos = 0;
Expand Down
4 changes: 4 additions & 0 deletions capnp-futures/src/write_queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,10 @@ where
unimplemented!()
}

pub fn is_empty(&mut self) -> bool {
self.len() == 0
}

/// Commands the queue to stop writing messages once it is empty. After this method has been called,
/// any new calls to `send()` will return a future that immediately resolves to an error.
/// If the passed-in `result` is an error, then the `WriteQueue` will resolve to that error.
Expand Down
10 changes: 5 additions & 5 deletions capnp-rpc/examples/calculator/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ struct ValueImpl {

impl ValueImpl {
fn new(value: f64) -> ValueImpl {
ValueImpl { value: value }
ValueImpl { value }
}
}

Expand Down Expand Up @@ -80,8 +80,8 @@ fn evaluate_impl(
let mut request = func.call_request();
{
let mut params = request.get().init_params(param_values.len() as u32);
for ii in 0..param_values.len() {
params.set(ii as u32, param_values[ii]);
for (ii, value) in param_values.iter().enumerate() {
params.set(ii as u32, *value);
}
}
Ok(request.send().promise.await?.get()?.get_value())
Expand All @@ -101,7 +101,7 @@ impl FunctionImpl {
body: calculator::expression::Reader,
) -> ::capnp::Result<FunctionImpl> {
let mut result = FunctionImpl {
param_count: param_count,
param_count,
body: ::capnp_rpc::ImbuedMessageBuilder::new(::capnp::message::HeapAllocator::new()),
};
result.body.set_root(body)?;
Expand Down Expand Up @@ -199,7 +199,7 @@ impl calculator::Server for CalculatorImpl {
let op = pry!(pry!(params.get()).get_op());
results
.get()
.set_func(capnp_rpc::new_client(OperatorImpl { op: op }));
.set_func(capnp_rpc::new_client(OperatorImpl { op }));
Promise::ok(())
}
}
Expand Down
17 changes: 7 additions & 10 deletions capnp-rpc/examples/pubsub/server.rs
Original file line number Diff line number Diff line change
Expand Up @@ -54,10 +54,7 @@ struct SubscriptionImpl {

impl SubscriptionImpl {
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> SubscriptionImpl {
SubscriptionImpl {
id: id,
subscribers: subscribers,
}
SubscriptionImpl { id, subscribers }
}
}

Expand All @@ -83,7 +80,7 @@ impl PublisherImpl {
next_id: 0,
subscribers: subscribers.clone(),
},
subscribers.clone(),
subscribers,
)
}
}
Expand Down Expand Up @@ -175,11 +172,11 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
tokio::task::spawn_local(request.send().promise.map(
move |r| match r {
Ok(_) => {
subscribers2.borrow_mut().subscribers.get_mut(&idx).map(
|ref mut s| {
s.requests_in_flight -= 1;
},
);
if let Some(ref mut s) =
subscribers2.borrow_mut().subscribers.get_mut(&idx)
{
s.requests_in_flight -= 1;
}
}
Err(e) => {
println!("Got error: {:?}. Dropping subscriber.", e);
Expand Down
2 changes: 1 addition & 1 deletion capnp-rpc/src/attach.rs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ where

fn poll(mut self: Pin<&mut Self>, cx: &mut Context) -> Poll<Self::Output> {
let result = Pin::new(&mut self.original_future).poll(cx);
if let Poll::Ready(_) = result {
if result.is_ready() {
self.value.take();
}
result
Expand Down
13 changes: 11 additions & 2 deletions capnp-rpc/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -330,15 +330,24 @@ where
caps: std::collections::HashMap<usize, Rc<RefCell<C::Dispatch>>>,
}

impl<S, C> CapabilityServerSet<S, C>
impl<S, C> Default for CapabilityServerSet<S, C>
where
C: capnp::capability::FromServer<S>,
{
pub fn new() -> Self {
fn default() -> Self {
Self {
caps: std::default::Default::default(),
}
}
}

impl<S, C> CapabilityServerSet<S, C>
where
C: capnp::capability::FromServer<S>,
{
pub fn new() -> Self {
Self::default()
}

/// Adds a new capability to the set and returns a client backed by it.
pub fn new_client(&mut self, s: S) -> C {
Expand Down
3 changes: 1 addition & 2 deletions capnp-rpc/src/local.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ use futures::channel::oneshot;
use futures::TryFutureExt;

use std::cell::RefCell;
use std::mem;
use std::rc::Rc;

pub trait ResultsDoneHook {
Expand Down Expand Up @@ -103,7 +102,7 @@ impl Drop for Results {
if let (Some(message), Some(fulfiller)) =
(self.message.take(), self.results_done_fulfiller.take())
{
let cap_table = mem::replace(&mut self.cap_table, Vec::new());
let cap_table = ::std::mem::take(&mut self.cap_table);
let _ = fulfiller.send(Box::new(ResultsDone::new(message, cap_table)));
} else {
unreachable!()
Expand Down
Loading