chore: clippy enforce unwrap_used, expect_used and panic

release is not far
This commit is contained in:
Alexander Medvedev committed 2026-08-08 13:44:51 +02:00
1 parent 0eb7b936db
commit 49360e53ef
291 files changed
+3200 -1783

No files matched your search

+2 -2
View File
@@ -67,8 +67,8 @@ impl<L: Decode, R: Decode> Decode for Either<L, R> {
DataResult::new_error(format!(
"Failed to parse either. First: {}; Second: {}",
left.get_message().unwrap(),
right.get_message().unwrap()
left.get_message().as_deref().unwrap_or("unknown error"),
right.get_message().as_deref().unwrap_or("unknown error")
))
}
}
+9 -4
View File
@@ -26,9 +26,10 @@ macro_rules! impl_apply {
let result_1 = $self;
if !(result_1.is_error() $(|| $result.is_error())+) {
// All n results are successful.
#[allow(clippy::expect_used)]
return DataResult::new_success($f(
result_1.into_result().unwrap()
$( , $result.into_result().unwrap() )+
result_1.into_result().expect("checked is_error")
$( , $result.into_result().expect("checked is_error") )+
));
}
let mut messages: Vec<String> = vec![];
@@ -231,21 +232,25 @@ impl<R> DataResult<R> {
}
/// Tries to get a complete result from this `DataResult`. If no such result exists, this function panics.
#[allow(clippy::unwrap_used, clippy::expect_used)]
pub fn unwrap(self) -> R {
self.expect("No complete result found for DataResult")
}
/// Tries to get a complete or partial result from this `DataResult`. If no such result exists, this function panics.
#[allow(clippy::unwrap_used, clippy::expect_used)]
pub fn unwrap_or_partial(self) -> R {
self.expect_or_partial("No complete or partial result found for DataResult")
}
/// Tries to get a complete result from this `DataResult`. If no such result exists, this function panics with a custom message.
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn expect(self, message: &str) -> R {
self.into_result().unwrap_or_else(|| panic!("{}", message))
}
/// Tries to get a complete or partial result from this `DataResult`. If no such result exists, this function panics with a custom message.
#[allow(clippy::unwrap_used, clippy::expect_used, clippy::panic)]
pub fn expect_or_partial(self, message: &str) -> R {
self.into_result_or_partial()
.unwrap_or_else(|| panic!("{}", message))
@@ -614,7 +619,7 @@ macro_rules! assert_success {
result
);
assert_eq!(
result.unwrap(),
result.into_result().expect("DataResult success"),
$right,
"`DataResult` was successful but the value doesn't match"
);
@@ -632,7 +637,7 @@ macro_rules! assert_encode_success {
result
);
assert_eq!(
result.unwrap(),
result.into_result().expect("DataResult success"),
$right,
"`DataResult` was successful but the value doesn't match"
);
+11 -16
View File
@@ -106,9 +106,8 @@ impl DynamicOps for JsonOps {
}
fn get_string(&self, input: &Self::Value) -> DataResult<String> {
if let Value::String(_) = input {
// Unwrapping is fine as only strings are possible here.
DataResult::new_success(Self::get_as_string(input).unwrap())
if let Value::String(s) = input {
DataResult::new_success(s.clone())
} else {
DataResult::new_error(format!("Not a string: {input}"))
}
@@ -194,13 +193,14 @@ impl DynamicOps for JsonOps {
if !Self::is_valid_key(&key) {
return DataResult::new_partial_error(format!("Key is not a string: {key}"), map);
}
let mut output_map = Map::new();
if let Value::Object(mut m) = map {
output_map.append(&mut m);
}
output_map.insert(Self::get_as_string(&key).unwrap(), value);
if let Some(key_str) = Self::get_as_string(&key) {
output_map.insert(key_str, value);
}
DataResult::new_success(Value::Object(output_map))
}
@@ -225,23 +225,19 @@ impl DynamicOps for JsonOps {
let mut missed = vec![];
for entry in other_map_like.iter() {
if Self::is_valid_key(&entry.0) {
output_map.insert(Self::get_as_string(&entry.0).unwrap(), entry.1.clone());
if let Some(key_str) = Self::get_as_string(&entry.0) {
output_map.insert(key_str, entry.1.clone());
} else {
missed.push(entry.0);
}
}
let object = Value::Object(output_map);
let pretty_missed = serde_json::to_string_pretty(&missed);
if missed.is_empty() {
DataResult::new_success(object)
} else {
DataResult::new_partial_error(
format!(
"Some keys are not strings{}",
pretty_missed.map_or_else(|_| String::new(), |r| format!(": {r}"))
),
format!("Some keys are not valid: {missed:?}"),
object,
)
}
@@ -375,10 +371,9 @@ impl StructBuilder for JsonStructBuilder {
impl StringStructBuilder for JsonStructBuilder {
fn append(&self, key: &str, value: Self::Value, mut builder: Self::Result) -> Self::Result {
builder
.as_object_mut()
.unwrap()
.insert(key.to_string(), value);
if let Some(obj) = builder.as_object_mut() {
obj.insert(key.to_string(), value);
}
builder
}
}
+3
View File
@@ -1,3 +1,6 @@
#![deny(clippy::unwrap_used)]
#![cfg_attr(test, allow(clippy::unwrap_used, clippy::expect_used, clippy::panic))]
mod data_result;
mod dynamic_ops;
pub mod json_ops;