Skip to content
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

Satisfy Clippy #1052

Merged
merged 2 commits into from Oct 14, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
7 changes: 5 additions & 2 deletions examples/configmapgen_controller.rs
@@ -1,3 +1,6 @@
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
#![allow(clippy::unnecessary_lazy_evaluations)]

use anyhow::Result;
use futures::StreamExt;
use k8s_openapi::api::core::v1::ConfigMap;
Expand Down Expand Up @@ -50,14 +53,14 @@ async fn reconcile(generator: Arc<ConfigMapGenerator>, ctx: Arc<Data>) -> Result
.metadata
.namespace
.as_ref()
.ok_or(Error::MissingObjectKey(".metadata.namespace"))?,
.ok_or_else(|| Error::MissingObjectKey(".metadata.namespace"))?,
);
cm_api
.patch(
cm.metadata
.name
.as_ref()
.ok_or(Error::MissingObjectKey(".metadata.name"))?,
.ok_or_else(|| Error::MissingObjectKey(".metadata.name"))?,
&PatchParams::apply("configmapgenerator.kube-rt.nullable.se"),
&Patch::Apply(&cm),
)
Expand Down
4 changes: 2 additions & 2 deletions kube-client/src/api/portforward.rs
Expand Up @@ -278,7 +278,7 @@ where
match msg {
Message::FromPod(ch, mut bytes) => {
let ch = ch as usize;
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;

let port_index = ch / 2;
// Initialization
Expand Down Expand Up @@ -327,7 +327,7 @@ where
}
Message::ToPodClose(ch) => {
let ch = ch as usize;
let channel = chan_state.get_mut(ch).ok_or(Error::InvalidChannel(ch))?;
let channel = chan_state.get_mut(ch).ok_or_else(|| Error::InvalidChannel(ch))?;
let port_index = ch / 2;

if !channel.shutdown {
Expand Down
2 changes: 1 addition & 1 deletion kube-client/src/config/file_config.rs
Expand Up @@ -480,7 +480,7 @@ fn load_from_base64_or_file<P: AsRef<Path>>(
let data = value
.map(load_from_base64)
.or_else(|| file.as_ref().map(load_from_file))
.unwrap_or(Err(LoadDataError::NoBase64DataOrFile))?;
.unwrap_or_else(|| Err(LoadDataError::NoBase64DataOrFile))?;
Ok(ensure_trailing_newline(data))
}

Expand Down
2 changes: 2 additions & 0 deletions kube-client/src/lib.rs
Expand Up @@ -63,6 +63,8 @@
#![cfg_attr(docsrs, feature(doc_cfg))]
#![deny(missing_docs)]
#![forbid(unsafe_code)]
// Nightly clippy (0.1.64) considers Drop a side effect, see https://github.com/rust-lang/rust-clippy/issues/9608
#![allow(clippy::unnecessary_lazy_evaluations)]

macro_rules! cfg_client {
($($item:item)*) => {
Expand Down
4 changes: 2 additions & 2 deletions kube-core/src/schema.rs
Expand Up @@ -72,7 +72,7 @@ fn hoist_subschema_properties(
common_obj: &mut Option<Box<ObjectValidation>>,
instance_type: &mut Option<SingleOrVec<InstanceType>>,
) {
let common_obj = common_obj.get_or_insert_with(|| Box::new(ObjectValidation::default()));
let common_obj = common_obj.get_or_insert_with(Box::<ObjectValidation>::default);

for variant in subschemas {
if let Schema::Object(SchemaObject {
Expand All @@ -90,7 +90,7 @@ fn hoist_subschema_properties(
{
let metadata = variant_object
.metadata
.get_or_insert_with(|| Box::new(Metadata::default()));
.get_or_insert_with(Box::<Metadata>::default);
metadata.description = Some(description);
}
}
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/controller/mod.rs
Expand Up @@ -194,7 +194,7 @@ impl Display for ReconcileReason {
ReconcileReason::Unknown => f.write_str("unknown"),
ReconcileReason::ObjectUpdated => f.write_str("object updated"),
ReconcileReason::RelatedObjectUpdated { obj_ref: object } => {
f.write_fmt(format_args!("related object updated: {}", object))
f.write_fmt(format_args!("related object updated: {object}"))
}
ReconcileReason::BulkReconcile => f.write_str("bulk reconcile requested"),
ReconcileReason::ReconcilerRequestedRetry => f.write_str("reconciler requested retry"),
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/finalizer.rs
Expand Up @@ -129,7 +129,7 @@ where
// Short-circuit, so that we keep the finalizer if cleanup fails
.map_err(Error::CleanupFailed)?;
// Cleanup was successful, remove the finalizer so that deletion can continue
let finalizer_path = format!("/metadata/finalizers/{}", finalizer_i);
let finalizer_path = format!("/metadata/finalizers/{finalizer_i}");
api.patch::<K>(
&name,
&PatchParams::default(),
Expand Down
8 changes: 4 additions & 4 deletions kube-runtime/src/reflector/object_ref.rs
Expand Up @@ -201,7 +201,7 @@ impl<K: Resource> Display for ObjectRef<K> {
self.name
)?;
if let Some(namespace) = &self.namespace {
write!(f, ".{}", namespace)?;
write!(f, ".{namespace}")?;
}
Ok(())
}
Expand Down Expand Up @@ -251,11 +251,11 @@ mod tests {
#[test]
fn display_should_be_transparent_to_representation() {
let pod_ref = ObjectRef::<Pod>::new("my-pod").within("my-namespace");
assert_eq!(format!("{}", pod_ref), format!("{}", pod_ref.erase()));
assert_eq!(format!("{pod_ref}"), format!("{}", pod_ref.erase()));
let deploy_ref = ObjectRef::<Deployment>::new("my-deploy").within("my-namespace");
assert_eq!(format!("{}", deploy_ref), format!("{}", deploy_ref.erase()));
assert_eq!(format!("{deploy_ref}"), format!("{}", deploy_ref.erase()));
let node_ref = ObjectRef::<Node>::new("my-node");
assert_eq!(format!("{}", node_ref), format!("{}", node_ref.erase()));
assert_eq!(format!("{node_ref}"), format!("{}", node_ref.erase()));
}

#[test]
Expand Down
2 changes: 1 addition & 1 deletion kube-runtime/src/watcher.rs
Expand Up @@ -284,7 +284,7 @@ pub fn watch_object<K: Resource + Clone + DeserializeOwned + Debug + Send + 'sta
name: &str,
) -> impl Stream<Item = Result<Option<K>>> + Send {
watcher(api, ListParams {
field_selector: Some(format!("metadata.name={}", name)),
field_selector: Some(format!("metadata.name={name}")),
..Default::default()
})
.map(|event| match event? {
Expand Down