Skip to content

Commit 50fc882

Browse files
authored
Auto fix if-let chains & other newer lints (#948)
1 parent 2d9e3cd commit 50fc882

File tree

29 files changed

+321
-331
lines changed

29 files changed

+321
-331
lines changed

client/src/lib.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -385,10 +385,10 @@ impl ClientHeaders {
385385
}
386386
if let Some(api_key) = &self.api_key {
387387
// Only if not already present
388-
if !metadata.contains_key("authorization") {
389-
if let Ok(val) = format!("Bearer {api_key}").parse() {
390-
metadata.insert("authorization", val);
391-
}
388+
if !metadata.contains_key("authorization")
389+
&& let Ok(val) = format!("Bearer {api_key}").parse()
390+
{
391+
metadata.insert("authorization", val);
392392
}
393393
}
394394
}

client/src/metrics.rs

Lines changed: 15 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -195,10 +195,10 @@ impl Service<http::Request<BoxBody>> for GrpcMetricSvc {
195195
if let Some(other_labels) = req.extensions_mut().remove::<AttachMetricLabels>() {
196196
m.with_new_attrs(other_labels.labels)
197197
}
198-
if let Some(ct) = req.extensions().get::<CallType>() {
199-
if ct.is_long() {
200-
m.set_is_long_poll();
201-
}
198+
if let Some(ct) = req.extensions().get::<CallType>()
199+
&& ct.is_long()
200+
{
201+
m.set_is_long_poll();
202202
}
203203
m
204204
})
@@ -218,22 +218,21 @@ impl Service<http::Request<BoxBody>> for GrpcMetricSvc {
218218
let res = callfut.await;
219219
if let Some(metrics) = metrics {
220220
metrics.record_svc_req_latency(started.elapsed());
221-
if let Ok(ref ok_res) = res {
222-
if let Some(number) = ok_res
221+
if let Ok(ref ok_res) = res
222+
&& let Some(number) = ok_res
223223
.headers()
224224
.get("grpc-status")
225225
.and_then(|s| s.to_str().ok())
226226
.and_then(|s| s.parse::<i32>().ok())
227-
{
228-
let code = Code::from(number);
229-
if code != Code::Ok {
230-
let code = if errcode_label_disabled {
231-
None
232-
} else {
233-
Some(code)
234-
};
235-
metrics.svc_request_failed(code);
236-
}
227+
{
228+
let code = Code::from(number);
229+
if code != Code::Ok {
230+
let code = if errcode_label_disabled {
231+
None
232+
} else {
233+
Some(code)
234+
};
235+
metrics.svc_request_failed(code);
237236
}
238237
}
239238
}

client/src/raw.rs

Lines changed: 4 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -592,17 +592,14 @@ proxier! {
592592
slot
593593
},
594594
|resp, slot| {
595-
if let Some(mut s) = slot {
596-
if let Ok(response) = resp.as_ref() {
597-
if let Some(task) = response.get_ref().clone().eager_workflow_task {
598-
if let Err(e) = s.schedule_wft(task) {
595+
if let Some(mut s) = slot
596+
&& let Ok(response) = resp.as_ref()
597+
&& let Some(task) = response.get_ref().clone().eager_workflow_task
598+
&& let Err(e) = s.schedule_wft(task) {
599599
// This is a latency issue, i.e., the client does not need to handle
600600
// this error, because the WFT will be retried after a timeout.
601601
warn!(details = ?e, "Eager workflow task rejected by worker.");
602602
}
603-
}
604-
}
605-
}
606603
resp
607604
}
608605
);

client/src/retry.rs

Lines changed: 11 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,10 @@ where
211211
return RetryPolicy::ForwardError(e);
212212
}
213213

214-
if let Some(sc) = self.retry_short_circuit.as_ref() {
215-
if (sc.predicate)(&e) {
216-
return RetryPolicy::ForwardError(e);
217-
}
214+
if let Some(sc) = self.retry_short_circuit.as_ref()
215+
&& (sc.predicate)(&e)
216+
{
217+
return RetryPolicy::ForwardError(e);
218218
}
219219

220220
// Short circuit if message is too large - this is not retryable
@@ -245,18 +245,17 @@ where
245245
// at most once. Ideally this bit should be removed eventually if we can repro the upstream
246246
// bug and it is fixed.
247247
let mut goaway_retry_allowed = false;
248-
if !self.have_retried_goaway_cancel && e.code() == Code::Cancelled {
249-
if let Some(e) = e
248+
if !self.have_retried_goaway_cancel
249+
&& e.code() == Code::Cancelled
250+
&& let Some(e) = e
250251
.source()
251252
.and_then(|e| e.downcast_ref::<tonic::transport::Error>())
252253
.and_then(|te| te.source())
253254
.and_then(|tec| tec.downcast_ref::<hyper::Error>())
254-
{
255-
if format!("{e:?}").contains("connection closed") {
256-
goaway_retry_allowed = true;
257-
self.have_retried_goaway_cancel = true;
258-
}
259-
}
255+
&& format!("{e:?}").contains("connection closed")
256+
{
257+
goaway_retry_allowed = true;
258+
self.have_retried_goaway_cancel = true;
260259
}
261260

262261
if RETRYABLE_ERROR_CODES.contains(&e.code()) || long_poll_allowed || goaway_retry_allowed {

client/src/worker_registry/mod.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,10 +73,10 @@ impl SlotManagerImpl {
7373
task_queue: String,
7474
) -> Option<Box<dyn Slot + Send>> {
7575
let key = SlotKey::new(namespace, task_queue);
76-
if let Some(p) = self.providers.get(&key) {
77-
if let Some(slot) = p.try_reserve_wft_slot() {
78-
return Some(slot);
79-
}
76+
if let Some(p) = self.providers.get(&key)
77+
&& let Some(slot) = p.try_reserve_wft_slot()
78+
{
79+
return Some(slot);
8080
}
8181
None
8282
}

core-api/src/envconfig.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -50,9 +50,7 @@
5050
//! ```
5151
5252
use serde::{Deserialize, Serialize};
53-
use std::collections::HashMap;
54-
use std::fs;
55-
use std::path::Path;
53+
use std::{collections::HashMap, fs, path::Path};
5654
use thiserror::Error;
5755

5856
/// Default profile name when none is specified

core-api/src/worker.rs

Lines changed: 21 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -217,12 +217,12 @@ impl WorkerConfigBuilder {
217217
b.validate()?
218218
}
219219

220-
if let Some(Some(ref x)) = self.max_worker_activities_per_second {
221-
if !x.is_normal() || x.is_sign_negative() {
222-
return Err(
223-
"`max_worker_activities_per_second` must be positive and nonzero".to_owned(),
224-
);
225-
}
220+
if let Some(Some(ref x)) = self.max_worker_activities_per_second
221+
&& (!x.is_normal() || x.is_sign_negative())
222+
{
223+
return Err(
224+
"`max_worker_activities_per_second` must be positive and nonzero".to_owned(),
225+
);
226226
}
227227

228228
if matches!(self.max_outstanding_workflow_tasks.as_ref(), Some(Some(v)) if *v == 0) {
@@ -238,25 +238,25 @@ impl WorkerConfigBuilder {
238238
return Err("`max_outstanding_nexus_tasks` must be > 0".to_owned());
239239
}
240240

241-
if let Some(cache) = self.max_cached_workflows.as_ref() {
242-
if *cache > 0 {
243-
if let Some(Some(max_wft)) = self.max_outstanding_workflow_tasks.as_ref() {
244-
if *max_wft < 2 {
245-
return Err(
246-
"`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2"
247-
.to_owned(),
248-
);
249-
}
250-
}
251-
if let Some(b) = self.workflow_task_poller_behavior.as_ref() {
252-
if matches!(b, PollerBehavior::SimpleMaximum(u) if *u < 2) {
253-
return Err(
241+
if let Some(cache) = self.max_cached_workflows.as_ref()
242+
&& *cache > 0
243+
{
244+
if let Some(Some(max_wft)) = self.max_outstanding_workflow_tasks.as_ref()
245+
&& *max_wft < 2
246+
{
247+
return Err(
248+
"`max_cached_workflows` > 0 requires `max_outstanding_workflow_tasks` >= 2"
249+
.to_owned(),
250+
);
251+
}
252+
if let Some(b) = self.workflow_task_poller_behavior.as_ref() {
253+
if matches!(b, PollerBehavior::SimpleMaximum(u) if *u < 2) {
254+
return Err(
254255
"`max_cached_workflows` > 0 requires `workflow_task_poller_behavior` to be at least 2"
255256
.to_owned(),
256257
);
257-
}
258-
b.validate()?
259258
}
259+
b.validate()?
260260
}
261261
}
262262

core/src/abstractions.rs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -101,10 +101,10 @@ where
101101
}
102102

103103
pub(crate) fn try_acquire_owned(&self) -> Result<OwnedMeteredSemPermit<SK>, ()> {
104-
if let Some(max) = self.max_permits {
105-
if *self.extant_permits.1.borrow() >= max {
106-
return Err(());
107-
}
104+
if let Some(max) = self.max_permits
105+
&& *self.extant_permits.1.borrow() >= max
106+
{
107+
return Err(());
108108
}
109109
if let Some(res) = self.supplier.try_reserve_slot(self) {
110110
Ok(self.build_owned(res))

core/src/internal_flags.rs

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -85,21 +85,20 @@ impl InternalFlags {
8585
last_sdk_version,
8686
..
8787
} = self
88+
&& let Some(metadata) = e.sdk_metadata.as_ref()
8889
{
89-
if let Some(metadata) = e.sdk_metadata.as_ref() {
90-
core.extend(
91-
metadata
92-
.core_used_flags
93-
.iter()
94-
.map(|u| CoreInternalFlags::from_u32(*u)),
95-
);
96-
lang.extend(metadata.lang_used_flags.iter());
97-
if !metadata.sdk_name.is_empty() {
98-
*last_sdk_name = metadata.sdk_name.clone();
99-
}
100-
if !metadata.sdk_version.is_empty() {
101-
*last_sdk_version = metadata.sdk_version.clone();
102-
}
90+
core.extend(
91+
metadata
92+
.core_used_flags
93+
.iter()
94+
.map(|u| CoreInternalFlags::from_u32(*u)),
95+
);
96+
lang.extend(metadata.lang_used_flags.iter());
97+
if !metadata.sdk_name.is_empty() {
98+
*last_sdk_name = metadata.sdk_name.clone();
99+
}
100+
if !metadata.sdk_version.is_empty() {
101+
*last_sdk_version = metadata.sdk_version.clone();
103102
}
104103
}
105104
}

core/src/pollers/poll_buffer.rs

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -316,10 +316,10 @@ where
316316
_ = shutdown.cancelled() => return,
317317
};
318318
drop(active_guard);
319-
if let Ok(r) = &r {
320-
if let Some(ppf) = post_pf.as_ref() {
321-
ppf(r);
322-
}
319+
if let Ok(r) = &r
320+
&& let Some(ppf) = post_pf.as_ref()
321+
{
322+
ppf(r);
323323
}
324324
if report_handle.poll_result(&r) {
325325
let _ = tx.send(r.map(|r| (r, permit)));
@@ -380,14 +380,14 @@ where
380380
}
381381

382382
async fn handle_task_panic(t: JoinHandle<()>) {
383-
if let Err(e) = t.await {
384-
if e.is_panic() {
385-
let as_panic = e.into_panic().downcast::<String>();
386-
dbg_panic!(
387-
"Poller task died or did not terminate cleanly: {:?}",
388-
as_panic
389-
);
390-
}
383+
if let Err(e) = t.await
384+
&& e.is_panic()
385+
{
386+
let as_panic = e.into_panic().downcast::<String>();
387+
dbg_panic!(
388+
"Poller task died or did not terminate cleanly: {:?}",
389+
as_panic
390+
);
391391
}
392392
}
393393

0 commit comments

Comments
 (0)