Skip to content

Commit

Permalink
Resolve unnecessary_map_or clippy lints
Browse files Browse the repository at this point in the history
    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
  • Loading branch information
dtolnay committed Nov 16, 2024
1 parent 07f280a commit a11f5f2
Showing 1 changed file with 6 additions and 6 deletions.
12 changes: 6 additions & 6 deletions src/value/partial_eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<str> for Value {
Expand Down

0 comments on commit a11f5f2

Please sign in to comment.