Skip to content

Commit 72b5a1c

Browse files
authored
Clippy/general (#361)
* use inline format args * remove redundant clones * remove needless borrowed reference * remove needless 'to_string' * nest 'or' patterns * use 'Self' keyword to refer to own type
1 parent f20dea2 commit 72b5a1c

File tree

16 files changed

+168
-226
lines changed

16 files changed

+168
-226
lines changed

benchmark/benchmark.rs

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -365,7 +365,7 @@ where
365365
Ok(())
366366
}
367367
Err(e) => {
368-
println!("could not start process: {}", e);
368+
println!("could not start process: {e}");
369369
Ok(())
370370
}
371371
}
@@ -387,7 +387,7 @@ impl Mode {
387387
"client" => Ok(Self::Client),
388388
"server" => Ok(Self::Server),
389389
"pipe" => Ok(Self::Pipe),
390-
s => Err(::capnp::Error::failed(format!("unrecognized mode: {}", s))),
390+
s => Err(::capnp::Error::failed(format!("unrecognized mode: {s}"))),
391391
}
392392
}
393393
}
@@ -433,8 +433,7 @@ where
433433
"catrank" => do_testcase(catrank::CatRank, mode, scratch, compression, iters),
434434
"eval" => do_testcase(eval::Eval, mode, scratch, compression, iters),
435435
s => Err(::capnp::Error::failed(format!(
436-
"unrecognized test case: {}",
437-
s
436+
"unrecognized test case: {s}"
438437
))),
439438
}
440439
}
@@ -453,8 +452,7 @@ where
453452
"no-reuse" => do_testcase1(case, mode, NoScratch, compression, iters),
454453
"reuse" => do_testcase1(case, mode, UseScratch::new(), compression, iters),
455454
s => Err(::capnp::Error::failed(format!(
456-
"unrecognized reuse option: {}",
457-
s
455+
"unrecognized reuse option: {s}"
458456
))),
459457
}
460458
}
@@ -481,8 +479,7 @@ fn try_main() -> ::capnp::Result<()> {
481479
"none" => do_testcase2(&args[1], mode, &args[3], NoCompression, iters),
482480
"packed" => do_testcase2(&args[1], mode, &args[3], Packed, iters),
483481
s => Err(::capnp::Error::failed(format!(
484-
"unrecognized compression: {}",
485-
s
482+
"unrecognized compression: {s}"
486483
))),
487484
}
488485
}

benchmark/catrank.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -151,8 +151,7 @@ impl crate::TestCase for CatRank {
151151
Ok(())
152152
} else {
153153
Err(::capnp::Error::failed(format!(
154-
"check_response() expected {} but got {}",
155-
expected_good_count, good_count
154+
"check_response() expected {expected_good_count} but got {good_count}"
156155
)))
157156
}
158157
}

benchmark/common.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ impl Default for FastRand {
4141
}
4242

4343
impl FastRand {
44-
pub fn new() -> FastRand {
44+
pub fn new() -> Self {
4545
Self::default()
4646
}
4747

benchmark/run_all.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,9 @@ fn run_one(
3535
.arg(mode)
3636
.arg(scratch)
3737
.arg(compression)
38-
.arg(format!("{}", iteration_count));
38+
.arg(format!("{iteration_count}"));
3939

40-
println!("{} {} {}", mode, compression, scratch);
40+
println!("{mode} {compression} {scratch}");
4141
let start_time = time::Instant::now();
4242
let result_status = command.spawn().unwrap().wait().unwrap();
4343
let elapsed = start_time.elapsed();
@@ -91,18 +91,18 @@ fn try_main() -> ::capnp::Result<()> {
9191

9292
let executable = &*args[1];
9393

94-
println!("running carsales with {} iterations", carsales_iters);
94+
println!("running carsales with {carsales_iters} iterations");
9595
run_case(
9696
executable,
9797
"carsales",
9898
&["reuse", "no-reuse"],
9999
carsales_iters,
100100
);
101101

102-
println!("running catrank with {} iterations", catrank_iters);
102+
println!("running catrank with {catrank_iters} iterations");
103103
run_case(executable, "catrank", &["no-reuse"], catrank_iters);
104104

105-
println!("running eval with {} iterations", eval_iters);
105+
println!("running eval with {eval_iters} iterations");
106106
run_case(executable, "eval", &["no-reuse"], eval_iters);
107107

108108
Ok(())

capnp-rpc/examples/calculator/server.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ fn evaluate_impl(
6666
),
6767
calculator::expression::Parameter(p) => match params {
6868
Some(params) if p < params.len() => Promise::ok(params.get(p)),
69-
_ => Promise::err(Error::failed(format!("bad parameter: {}", p))),
69+
_ => Promise::err(Error::failed(format!("bad parameter: {p}"))),
7070
},
7171
calculator::expression::Call(call) => {
7272
let func = pry!(call.get_function());
@@ -232,7 +232,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
232232
);
233233

234234
let rpc_system = RpcSystem::new(Box::new(network), Some(calc.clone().client));
235-
tokio::task::spawn_local(rpc_system.map_err(|e| println!("error: {:?}", e)));
235+
tokio::task::spawn_local(rpc_system.map_err(|e| println!("error: {e:?}")));
236236
}
237237
})
238238
.await

capnp-rpc/examples/hello-world/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ impl hello_world::Server for HelloWorldImpl {
3737
) -> Promise<(), ::capnp::Error> {
3838
let request = pry!(pry!(params.get()).get_request());
3939
let name = pry!(request.get_name());
40-
let message = format!("Hello, {}!", name);
40+
let message = format!("Hello, {name}!");
4141

4242
results.get().init_reply().set_message(&message);
4343

capnp-rpc/examples/pubsub/server.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -179,7 +179,7 @@ pub async fn main() -> Result<(), Box<dyn std::error::Error>> {
179179
}
180180
}
181181
Err(e) => {
182-
println!("Got error: {:?}. Dropping subscriber.", e);
182+
println!("Got error: {e:?}. Dropping subscriber.");
183183
subscribers2.borrow_mut().subscribers.remove(&idx);
184184
}
185185
},

capnp-rpc/src/lib.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -275,7 +275,7 @@ impl<VatId> RpcSystem<VatId> {
275275
*connection_state_ref1.borrow_mut() = None;
276276
match shutdown_promise {
277277
Ok(s) => s,
278-
Err(e) => Promise::err(Error::failed(format!("{}", e))),
278+
Err(e) => Promise::err(Error::failed(format!("{e}"))),
279279
}
280280
}));
281281
rpc::ConnectionState::new(bootstrap_cap, connection, on_disconnect_fulfiller)
@@ -405,7 +405,7 @@ where
405405
struct SystemTaskReaper;
406406
impl crate::task_set::TaskReaper<Error> for SystemTaskReaper {
407407
fn task_failed(&mut self, error: Error) {
408-
println!("ERROR: {}", error);
408+
println!("ERROR: {error}");
409409
}
410410
}
411411

capnp-rpc/src/rpc.rs

Lines changed: 14 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -378,7 +378,7 @@ fn remote_exception_to_error(exception: exception::Reader) -> Error {
378378
_ => (::capnp::ErrorKind::Failed, "(malformed error)"),
379379
};
380380
Error {
381-
description: format!("remote exception: {}", reason),
381+
description: format!("remote exception: {reason}"),
382382
kind,
383383
}
384384
}
@@ -783,15 +783,13 @@ impl<VatId> ConnectionState<VatId> {
783783
match answers_slots.get_mut(&answer_id) {
784784
None => {
785785
return Err(Error::failed(format!(
786-
"Invalid question ID {} in Finish message.",
787-
answer_id
786+
"Invalid question ID {answer_id} in Finish message."
788787
)));
789788
}
790789
Some(answer) => {
791790
if !answer.active {
792791
return Err(Error::failed(format!(
793-
"'Finish' for invalid question ID {}.",
794-
answer_id
792+
"'Finish' for invalid question ID {answer_id}."
795793
)));
796794
}
797795
answer.received_finish.set(true);
@@ -939,8 +937,7 @@ impl<VatId> ConnectionState<VatId> {
939937
.contains_key(&question_id)
940938
{
941939
return Err(Error::failed(format!(
942-
"Received a new call on in-use question id {}",
943-
question_id
940+
"Received a new call on in-use question id {question_id}"
944941
)));
945942
}
946943

@@ -994,7 +991,7 @@ impl<VatId> ConnectionState<VatId> {
994991
if let Some(f) = redirected_results_done_fulfiller {
995992
match v {
996993
Ok(r) => drop(f.send(Ok(Response::redirected(r.clone())))),
997-
Err(e) => drop(f.send(Err(e.clone()))),
994+
Err(e) => drop(f.send(Err(e))),
998995
}
999996
}
1000997
Promise::ok(())
@@ -1095,8 +1092,7 @@ impl<VatId> ConnectionState<VatId> {
10951092
}
10961093
None => {
10971094
return Err(Error::failed(format!(
1098-
"Invalid question ID in Return message: {}",
1099-
question_id
1095+
"Invalid question ID in Return message: {question_id}"
11001096
)));
11011097
}
11021098
}
@@ -1146,11 +1142,13 @@ impl<VatId> ConnectionState<VatId> {
11461142
Ok(message::Disembargo(disembargo)) => {
11471143
Self::handle_disembargo(&connection_state, disembargo?)?
11481144
}
1149-
Ok(message::Provide(_))
1150-
| Ok(message::Accept(_))
1151-
| Ok(message::Join(_))
1152-
| Ok(message::ObsoleteSave(_))
1153-
| Ok(message::ObsoleteDelete(_))
1145+
Ok(
1146+
message::Provide(_)
1147+
| message::Accept(_)
1148+
| message::Join(_)
1149+
| message::ObsoleteSave(_)
1150+
| message::ObsoleteDelete(_),
1151+
)
11541152
| Err(::capnp::NotInSchema(_)) => {
11551153
Self::send_unimplemented(&connection_state, &message)?;
11561154
}
@@ -1225,7 +1223,7 @@ impl<VatId> ConnectionState<VatId> {
12251223
match target.which()? {
12261224
message_target::ImportedCap(export_id) => {
12271225
match self.exports.borrow().slots.get(export_id as usize) {
1228-
Some(&Some(ref exp)) => Ok(exp.client_hook.clone()),
1226+
Some(Some(exp)) => Ok(exp.client_hook.clone()),
12291227
_ => Err(Error::failed(
12301228
"Message target is not a current export ID.".to_string(),
12311229
)),

capnp-rpc/test/test.rs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -340,8 +340,7 @@ fn pipelining_return_null() {
340340
Ok(())
341341
} else {
342342
Err(Error::failed(format!(
343-
"Should have gotten null capability error. Instead got {:?}",
344-
e
343+
"Should have gotten null capability error. Instead got {e:?}"
345344
)))
346345
}
347346
}

0 commit comments

Comments
 (0)