Skip to content

Commit

Permalink
Use _else variants for constructing errors
Browse files Browse the repository at this point in the history
Clippy's stance here has changed.. see rust-lang/rust-clippy#9608
  • Loading branch information
nightkr committed Oct 14, 2022
1 parent 2f5ba8f commit 918346c
Show file tree
Hide file tree
Showing 5 changed files with 12 additions and 7 deletions.
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

0 comments on commit 918346c

Please sign in to comment.