Skip to content

Commit 59efe94

Browse files
authored
Merge pull request #343 from danieleades/clippy/general
Clippy/general
2 parents b7abb11 + 0aa12c9 commit 59efe94

File tree

20 files changed

+203
-233
lines changed

20 files changed

+203
-233
lines changed

benchmark/benchmark.rs

Lines changed: 17 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ impl Serialize for NoCompression {
106106
W: io::Write,
107107
A: message::Allocator,
108108
{
109-
serialize::write_message(write, message).map_err(|e| e.into())
109+
serialize::write_message(write, message)
110110
}
111111
}
112112

@@ -133,7 +133,7 @@ impl Serialize for Packed {
133133
W: io::Write,
134134
A: message::Allocator,
135135
{
136-
serialize_packed::write_message(write, message).map_err(|e| e.into())
136+
serialize_packed::write_message(write, message)
137137
}
138138
}
139139

@@ -161,15 +161,21 @@ pub struct UseScratch {
161161
buffer2: Vec<capnp::Word>,
162162
}
163163

164-
impl UseScratch {
165-
pub fn new() -> Self {
164+
impl Default for UseScratch {
165+
fn default() -> Self {
166166
Self {
167167
buffer1: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
168168
buffer2: capnp::Word::allocate_zeroed_vec(SCRATCH_SIZE),
169169
}
170170
}
171171
}
172172

173+
impl UseScratch {
174+
pub fn new() -> Self {
175+
Self::default()
176+
}
177+
}
178+
173179
impl<'a> Scratch<'a> for UseScratch {
174180
type Allocator = message::ScratchSpaceHeapAllocator<'a>;
175181

@@ -231,7 +237,7 @@ where
231237

232238
{
233239
let mut writer: &mut [u8] = &mut request_bytes;
234-
compression.write_message(&mut writer, &mut message_req)?;
240+
compression.write_message(&mut writer, &message_req)?;
235241
}
236242

237243
let mut request_bytes1: &[u8] = &request_bytes;
@@ -244,7 +250,7 @@ where
244250

245251
{
246252
let mut writer: &mut [u8] = &mut response_bytes;
247-
compression.write_message(&mut writer, &mut message_res)?;
253+
compression.write_message(&mut writer, &message_res)?;
248254
}
249255

250256
let mut response_bytes1: &[u8] = &response_bytes;
@@ -286,7 +292,7 @@ where
286292
testcase.handle_request(request_reader, response)?;
287293
}
288294

289-
compression.write_message(&mut out_buffered, &mut message_res)?;
295+
compression.write_message(&mut out_buffered, &message_res)?;
290296
out_buffered.flush()?;
291297
}
292298
Ok(())
@@ -317,7 +323,7 @@ where
317323
let request = message_req.init_root();
318324
testcase.setup_request(&mut rng, request)
319325
};
320-
compression.write_message(&mut out_buffered, &mut message_req)?;
326+
compression.write_message(&mut out_buffered, &message_req)?;
321327
out_buffered.flush()?;
322328

323329
let message_reader = compression.read_message(&mut in_buffered, Default::default())?;
@@ -472,11 +478,11 @@ fn try_main() -> ::capnp::Result<()> {
472478
}
473479
};
474480

475-
let mode = Mode::parse(&*args[2])?;
481+
let mode = Mode::parse(&args[2])?;
476482

477483
match &*args[4] {
478-
"none" => do_testcase2(&*args[1], mode, &*args[3], NoCompression, iters),
479-
"packed" => do_testcase2(&*args[1], mode, &*args[3], Packed, iters),
484+
"none" => do_testcase2(&args[1], mode, &args[3], NoCompression, iters),
485+
"packed" => do_testcase2(&args[1], mode, &args[3], Packed, iters),
480486
s => Err(::capnp::Error::failed(format!(
481487
"unrecognized compression: {}",
482488
s

benchmark/carsales.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -78,8 +78,8 @@ macro_rules! car_value_impl(
7878
car_value_impl!(Reader);
7979
car_value_impl!(Builder);
8080

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

8484
pub fn random_car(rng: &mut FastRand, mut car: car::Builder) {
8585
car.set_make(MAKES[rng.next_less_than(MAKES.len() as u32) as usize]);

benchmark/catrank.rs

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ pub struct ScoredResult<'a> {
2828
result: search_result::Reader<'a>,
2929
}
3030

31-
const URL_PREFIX: &'static str = "http://example.com";
31+
const URL_PREFIX: &str = "http://example.com";
3232

3333
pub struct CatRank;
3434

@@ -108,10 +108,7 @@ impl crate::TestCase for CatRank {
108108
if snippet.contains(" dog ") {
109109
score /= 10000.0;
110110
}
111-
scored_results.push(ScoredResult {
112-
score: score,
113-
result: result,
114-
});
111+
scored_results.push(ScoredResult { score, result });
115112
}
116113

117114
// sort in decreasing order

benchmark/common.rs

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -29,15 +29,21 @@ pub struct FastRand {
2929
w: u32,
3030
}
3131

32-
impl FastRand {
33-
pub fn new() -> Self {
32+
impl Default for FastRand {
33+
fn default() -> Self {
3434
Self {
3535
x: 0x1d2acd47,
3636
y: 0x58ca3e14,
3737
z: 0xf563f232,
3838
w: 0x0bc76199,
3939
}
4040
}
41+
}
42+
43+
impl FastRand {
44+
pub fn new() -> FastRand {
45+
Self::default()
46+
}
4147

4248
#[inline]
4349
pub fn next_u32(&mut self) -> u32 {
@@ -46,7 +52,7 @@ impl FastRand {
4652
self.y = self.z;
4753
self.z = self.w;
4854
self.w = self.w ^ (self.w >> 19) ^ tmp ^ (tmp >> 8);
49-
return self.w;
55+
self.w
5056
}
5157

5258
#[inline]
@@ -74,7 +80,7 @@ pub fn div(a: i32, b: i32) -> i32 {
7480
if a == i32::MIN && b == -1 {
7581
return i32::MAX;
7682
}
77-
return a / b;
83+
a / b
7884
}
7985

8086
#[inline]
@@ -85,10 +91,10 @@ pub fn modulus(a: i32, b: i32) -> i32 {
8591
if a == i32::MIN && b == -1 {
8692
return i32::MAX;
8793
}
88-
return a % b;
94+
a % b
8995
}
9096

91-
pub const WORDS: [&'static str; 13] = [
97+
pub const WORDS: [&str; 13] = [
9298
"foo ", "bar ", "baz ", "qux ", "quux ", "corge ", "grault ", "garply ", "waldo ", "fred ",
9399
"plugh ", "xyzzy ", "thud ",
94100
];

benchmark/eval.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,11 @@ fn make_expression(rng: &mut FastRand, mut exp: expression::Builder, depth: u32)
4242
};
4343

4444
match exp.get_op().unwrap() {
45-
Operation::Add => return left + right,
46-
Operation::Subtract => return left - right,
47-
Operation::Multiply => return left * right,
48-
Operation::Divide => return div(left, right),
49-
Operation::Modulus => return modulus(left, right),
45+
Operation::Add => left + right,
46+
Operation::Subtract => left - right,
47+
Operation::Multiply => left * right,
48+
Operation::Divide => div(left, right),
49+
Operation::Modulus => modulus(left, right),
5050
}
5151
}
5252

capnp-futures/src/serialize.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -231,8 +231,8 @@ where
231231
.copy_from_slice(&((segments[idx].len() / 8) as u32).to_le_bytes());
232232
}
233233
if segment_count == 2 {
234-
for idx in 4..8 {
235-
buf[idx] = 0
234+
for value in &mut buf[4..8] {
235+
*value = 0;
236236
}
237237
}
238238
write.write_all(&buf).await?;
@@ -258,8 +258,8 @@ async fn write_segments<W>(mut write: W, segments: &[&[u8]]) -> Result<()>
258258
where
259259
W: AsyncWrite + Unpin,
260260
{
261-
for i in 0..segments.len() {
262-
write.write_all(segments[i]).await?;
261+
for segment in segments {
262+
write.write_all(segment).await?;
263263
}
264264
Ok(())
265265
}

capnp-futures/src/serialize_packed.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -122,8 +122,8 @@ where
122122
PackedReadStage::WritingZeroes => {
123123
let num_zeroes = std::cmp::min(outbuf.len(), *num_run_bytes_remaining);
124124

125-
for ii in 0..num_zeroes {
126-
outbuf[ii] = 0;
125+
for value in outbuf.iter_mut().take(num_zeroes) {
126+
*value = 0;
127127
}
128128
if num_zeroes >= *num_run_bytes_remaining {
129129
*buf_pos = 0;

capnp-futures/src/write_queue.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -101,6 +101,10 @@ where
101101
unimplemented!()
102102
}
103103

104+
pub fn is_empty(&mut self) -> bool {
105+
self.len() == 0
106+
}
107+
104108
/// Commands the queue to stop writing messages once it is empty. After this method has been called,
105109
/// any new calls to `send()` will return a future that immediately resolves to an error.
106110
/// If the passed-in `result` is an error, then the `WriteQueue` will resolve to that error.

capnp-rpc/examples/calculator/server.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ struct ValueImpl {
3636

3737
impl ValueImpl {
3838
fn new(value: f64) -> Self {
39-
Self { value: value }
39+
Self { value }
4040
}
4141
}
4242

@@ -80,8 +80,8 @@ fn evaluate_impl(
8080
let mut request = func.call_request();
8181
{
8282
let mut params = request.get().init_params(param_values.len() as u32);
83-
for ii in 0..param_values.len() {
84-
params.set(ii as u32, param_values[ii]);
83+
for (ii, value) in param_values.iter().enumerate() {
84+
params.set(ii as u32, *value);
8585
}
8686
}
8787
Ok(request.send().promise.await?.get()?.get_value())
@@ -98,7 +98,7 @@ struct FunctionImpl {
9898
impl FunctionImpl {
9999
fn new(param_count: u32, body: calculator::expression::Reader) -> ::capnp::Result<Self> {
100100
let mut result = Self {
101-
param_count: param_count,
101+
param_count,
102102
body: ::capnp_rpc::ImbuedMessageBuilder::new(::capnp::message::HeapAllocator::new()),
103103
};
104104
result.body.set_root(body)?;
@@ -196,7 +196,7 @@ impl calculator::Server for CalculatorImpl {
196196
let op = pry!(pry!(params.get()).get_op());
197197
results
198198
.get()
199-
.set_func(capnp_rpc::new_client(OperatorImpl { op: op }));
199+
.set_func(capnp_rpc::new_client(OperatorImpl { op }));
200200
Promise::ok(())
201201
}
202202
}

capnp-rpc/examples/pubsub/server.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,10 +54,7 @@ struct SubscriptionImpl {
5454

5555
impl SubscriptionImpl {
5656
fn new(id: u64, subscribers: Rc<RefCell<SubscriberMap>>) -> Self {
57-
Self {
58-
id: id,
59-
subscribers: subscribers,
60-
}
57+
Self { id, subscribers }
6158
}
6259
}
6360

@@ -83,7 +80,7 @@ impl PublisherImpl {
8380
next_id: 0,
8481
subscribers: subscribers.clone(),
8582
},
86-
subscribers.clone(),
83+
subscribers,
8784
)
8885
}
8986
}
@@ -175,11 +172,11 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
175172
tokio::task::spawn_local(request.send().promise.map(
176173
move |r| match r {
177174
Ok(_) => {
178-
subscribers2.borrow_mut().subscribers.get_mut(&idx).map(
179-
|ref mut s| {
180-
s.requests_in_flight -= 1;
181-
},
182-
);
175+
if let Some(ref mut s) =
176+
subscribers2.borrow_mut().subscribers.get_mut(&idx)
177+
{
178+
s.requests_in_flight -= 1;
179+
}
183180
}
184181
Err(e) => {
185182
println!("Got error: {:?}. Dropping subscriber.", e);

0 commit comments

Comments
 (0)