Skip to content

Commit 0b12c6a

Browse files
authoredOct 14, 2022
Merge pull request #1052 from teozkr/clippy/2022-10-14
Satisfy Clippy
2 parents b2e5f77 + f2f9c44 commit 0b12c6a

File tree

9 files changed

+19
-14
lines changed

9 files changed

+19
-14
lines changed
 

‎examples/configmapgen_controller.rs

+5-2
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
2+
#![allow(clippy::unnecessary_lazy_evaluations)]
3+
14
use anyhow::Result;
25
use futures::StreamExt;
36
use k8s_openapi::api::core::v1::ConfigMap;
@@ -50,14 +53,14 @@ async fn reconcile(generator: Arc<ConfigMapGenerator>, ctx: Arc<Data>) -> Result
5053
.metadata
5154
.namespace
5255
.as_ref()
53-
.ok_or(Error::MissingObjectKey(".metadata.namespace"))?,
56+
.ok_or_else(|| Error::MissingObjectKey(".metadata.namespace"))?,
5457
);
5558
cm_api
5659
.patch(
5760
cm.metadata
5861
.name
5962
.as_ref()
60-
.ok_or(Error::MissingObjectKey(".metadata.name"))?,
63+
.ok_or_else(|| Error::MissingObjectKey(".metadata.name"))?,
6164
&PatchParams::apply("configmapgenerator.kube-rt.nullable.se"),
6265
&Patch::Apply(&cm),
6366
)

‎kube-client/src/api/portforward.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -278,7 +278,7 @@ where
278278
match msg {
279279
Message::FromPod(ch, mut bytes) => {
280280
let ch = ch as usize;
281-
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
281+
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;
282282

283283
let port_index = ch / 2;
284284
// Initialization
@@ -327,7 +327,7 @@ where
327327
}
328328
Message::ToPodClose(ch) => {
329329
let ch = ch as usize;
330-
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
330+
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;
331331
let port_index = ch / 2;
332332

333333
if !channel.shutdown {

‎kube-client/src/config/file_config.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -480,7 +480,7 @@ fn load_from_base64_or_file<P: AsRef<Path>>(
480480
let data = value
481481
.map(load_from_base64)
482482
.or_else(|| file.as_ref().map(load_from_file))
483-
.unwrap_or(Err(LoadDataError::NoBase64DataOrFile))?;
483+
.unwrap_or_else(|| Err(LoadDataError::NoBase64DataOrFile))?;
484484
Ok(ensure_trailing_newline(data))
485485
}
486486

‎kube-client/src/lib.rs

+2
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,8 @@
6363
#![cfg_attr(docsrs, feature(doc_cfg))]
6464
#![deny(missing_docs)]
6565
#![forbid(unsafe_code)]
66+
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
67+
#![allow(clippy::unnecessary_lazy_evaluations)]
6668

6769
macro_rules! cfg_client {
6870
($($item:item)*) => {

‎kube-core/src/schema.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ fn hoist_subschema_properties(
7272
common_obj: &mut Option<Box<ObjectValidation>>,
7373
instance_type: &mut Option<SingleOrVec<InstanceType>>,
7474
) {
75-
let common_obj = common_obj.get_or_insert_with(|| Box::new(ObjectValidation::default()));
75+
let common_obj = common_obj.get_or_insert_with(Box::<ObjectValidation>::default);
7676

7777
for variant in subschemas {
7878
if let Schema::Object(SchemaObject {
@@ -90,7 +90,7 @@ fn hoist_subschema_properties(
9090
{
9191
let metadata = variant_object
9292
.metadata
93-
.get_or_insert_with(|| Box::new(Metadata::default()));
93+
.get_or_insert_with(Box::<Metadata>::default);
9494
metadata.description = Some(description);
9595
}
9696
}

‎kube-runtime/src/controller/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -194,7 +194,7 @@ impl Display for ReconcileReason {
194194
ReconcileReason::Unknown => f.write_str("unknown"),
195195
ReconcileReason::ObjectUpdated => f.write_str("object updated"),
196196
ReconcileReason::RelatedObjectUpdated { obj_ref: object } => {
197-
f.write_fmt(format_args!("related object updated: {}", object))
197+
f.write_fmt(format_args!("related object updated: {object}"))
198198
}
199199
ReconcileReason::BulkReconcile => f.write_str("bulk reconcile requested"),
200200
ReconcileReason::ReconcilerRequestedRetry => f.write_str("reconciler requested retry"),

‎kube-runtime/src/finalizer.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ where
129129
// Short-circuit, so that we keep the finalizer if cleanup fails
130130
.map_err(Error::CleanupFailed)?;
131131
// Cleanup was successful, remove the finalizer so that deletion can continue
132-
let finalizer_path = format!("/metadata/finalizers/{}", finalizer_i);
132+
let finalizer_path = format!("/metadata/finalizers/{finalizer_i}");
133133
api.patch::<K>(
134134
&name,
135135
&PatchParams::default(),

‎kube-runtime/src/reflector/object_ref.rs

+4-4
Original file line numberDiff line numberDiff line change
@@ -201,7 +201,7 @@ impl<K: Resource> Display for ObjectRef<K> {
201201
self.name
202202
)?;
203203
if let Some(namespace) = &self.namespace {
204-
write!(f, ".{}", namespace)?;
204+
write!(f, ".{namespace}")?;
205205
}
206206
Ok(())
207207
}
@@ -251,11 +251,11 @@ mod tests {
251251
#[test]
252252
fn display_should_be_transparent_to_representation() {
253253
let pod_ref = ObjectRef::<Pod>::new("my-pod").within("my-namespace");
254-
assert_eq!(format!("{}", pod_ref), format!("{}", pod_ref.erase()));
254+
assert_eq!(format!("{pod_ref}"), format!("{}", pod_ref.erase()));
255255
let deploy_ref = ObjectRef::<Deployment>::new("my-deploy").within("my-namespace");
256-
assert_eq!(format!("{}", deploy_ref), format!("{}", deploy_ref.erase()));
256+
assert_eq!(format!("{deploy_ref}"), format!("{}", deploy_ref.erase()));
257257
let node_ref = ObjectRef::<Node>::new("my-node");
258-
assert_eq!(format!("{}", node_ref), format!("{}", node_ref.erase()));
258+
assert_eq!(format!("{node_ref}"), format!("{}", node_ref.erase()));
259259
}
260260

261261
#[test]

‎kube-runtime/src/watcher.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ pub fn watch_object<K: Resource + Clone + DeserializeOwned + Debug + Send + 'sta
284284
name: &str,
285285
) -> impl Stream<Item = Result<Option<K>>> + Send {
286286
watcher(api, ListParams {
287-
field_selector: Some(format!("metadata.name={}", name)),
287+
field_selector: Some(format!("metadata.name={name}")),
288288
..Default::default()
289289
})
290290
.map(|event| match event? {

0 commit comments

Comments
 (0)