From a11f5f2bc4756035e5a04e01ad486d8a99779527 Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Fri, 15 Nov 2024 18:47:02 -0800 Subject: [PATCH] Resolve unnecessary_map_or clippy lints warning: this `map_or` is redundant --> src/value/partial_eq.rs:5:5 | 5 | value.as_i64().map_or(false, |i| i == other) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(value.as_i64() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or = note: `-W clippy::unnecessary-map-or` implied by `-W clippy::all` = help: to override `-W clippy::all` add `#[allow(clippy::unnecessary_map_or)]` warning: this `map_or` is redundant --> src/value/partial_eq.rs:9:5 | 9 | value.as_u64().map_or(false, |i| i == other) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(value.as_u64() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or warning: this `map_or` is redundant --> src/value/partial_eq.rs:14:29 | 14 | Value::Number(n) => n.as_f32().map_or(false, |i| i == other), | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(n.as_f32() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or warning: this `map_or` is redundant --> src/value/partial_eq.rs:20:5 | 20 | value.as_f64().map_or(false, |i| i == other) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(value.as_f64() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or warning: this `map_or` is redundant --> src/value/partial_eq.rs:24:5 | 24 | value.as_bool().map_or(false, |i| i == other) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(value.as_bool() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or warning: this `map_or` is redundant --> src/value/partial_eq.rs:28:5 | 28 | value.as_str().map_or(false, |i| i == other) | ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ help: use a standard comparison instead: `(value.as_str() == Some(other))` | = help: for further information visit https://rust-lang.github.io/rust-clippy/master/index.html#unnecessary_map_or --- src/value/partial_eq.rs | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/value/partial_eq.rs b/src/value/partial_eq.rs index 46c1dbc33..8626eed7f 100644 --- a/src/value/partial_eq.rs +++ b/src/value/partial_eq.rs @@ -2,30 +2,30 @@ use super::Value; use alloc::string::String; fn eq_i64(value: &Value, other: i64) -> bool { - value.as_i64().map_or(false, |i| i == other) + value.as_i64() == Some(other) } fn eq_u64(value: &Value, other: u64) -> bool { - value.as_u64().map_or(false, |i| i == other) + value.as_u64() == Some(other) } fn eq_f32(value: &Value, other: f32) -> bool { match value { - Value::Number(n) => n.as_f32().map_or(false, |i| i == other), + Value::Number(n) => n.as_f32() == Some(other), _ => false, } } fn eq_f64(value: &Value, other: f64) -> bool { - value.as_f64().map_or(false, |i| i == other) + value.as_f64() == Some(other) } fn eq_bool(value: &Value, other: bool) -> bool { - value.as_bool().map_or(false, |i| i == other) + value.as_bool() == Some(other) } fn eq_str(value: &Value, other: &str) -> bool { - value.as_str().map_or(false, |i| i == other) + value.as_str() == Some(other) } impl PartialEq for Value {