Skip to content

Commit 222b108

Browse files
committed
Fix various clippy lints
Signed-off-by: Colin Walters <[email protected]>
1 parent cbfbd3f commit 222b108

File tree

3 files changed

+11
-14
lines changed

3 files changed

+11
-14
lines changed

.github/workflows/ci.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ concurrency:
1717
env:
1818
CARGO_TERM_COLOR: always
1919
# Pinned toolchain for linting
20-
ACTIONS_LINTS_TOOLCHAIN: 1.76.0
20+
ACTIONS_LINTS_TOOLCHAIN: 1.86.0
2121

2222
jobs:
2323
tests-stable:

src/floatformat.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ pub(crate) fn number_to_json(ieee_f64: f64) -> Result<String, NumberSerializatio
4949
// Special case: NaN and Infinity are invalid in JSON.
5050
// The JCS specification mandates that implementations must reject them.
5151
if (ieee_u64 & INVALID_PATTERN) == INVALID_PATTERN {
52-
return Err(NumberSerializationError::Unserializable.into());
52+
return Err(NumberSerializationError::Unserializable);
5353
}
5454

5555
// Special case: Eliminate "-0" as mandated by the ES6/JCS specifications.
@@ -68,7 +68,7 @@ pub(crate) fn number_to_json(ieee_f64: f64) -> Result<String, NumberSerializatio
6868

6969
// ES6 defines a specific range where numbers should be rendered in fixed-point
7070
// format ('f'), and scientific notation ('e') otherwise.
71-
let es6_formatted = if num >= 1e-6 && num < 1e21 {
71+
let es6_formatted = if (1e-6..1e21).contains(&num) {
7272
// For numbers within this range, use fixed-point notation.
7373
// Rust's default `to_string` for floats is suitable as it doesn't produce
7474
// unnecessary trailing zeros (e.g., 25.0 becomes "25").
@@ -85,7 +85,7 @@ pub(crate) fn number_to_json(ieee_f64: f64) -> Result<String, NumberSerializatio
8585
if scientific
8686
.chars()
8787
.nth(next_char_pos)
88-
.map_or(false, |c| c.is_ascii_digit())
88+
.is_some_and(|c| c.is_ascii_digit())
8989
{
9090
scientific.insert(next_char_pos, '+');
9191
}

src/lib.rs

Lines changed: 7 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ enum WriterTarget<'w, W> {
9393
Buffer(&'w mut Vec<u8>),
9494
}
9595

96-
impl<'w, W: Write> Write for WriterTarget<'w, W> {
96+
impl<W: Write> Write for WriterTarget<'_, W> {
9797
fn write(&mut self, buf: &[u8]) -> Result<usize> {
9898
match self {
9999
WriterTarget::Underlying(w) => w.write(buf),
@@ -222,7 +222,7 @@ impl Formatter for CanonicalFormatter {
222222
if !v.key_done {
223223
return Ok(());
224224
}
225-
return CompactFormatter.begin_string(&mut v.next_value);
225+
CompactFormatter.begin_string(&mut v.next_value)
226226
}
227227

228228
fn end_string<W: Write + ?Sized>(&mut self, writer: &mut W) -> Result<()> {
@@ -232,7 +232,7 @@ impl Formatter for CanonicalFormatter {
232232
if !v.key_done {
233233
return Ok(());
234234
}
235-
return CompactFormatter.end_string(&mut v.next_value);
235+
CompactFormatter.end_string(&mut v.next_value)
236236
}
237237

238238
fn write_string_fragment<W: Write + ?Sized>(
@@ -268,7 +268,7 @@ impl Formatter for CanonicalFormatter {
268268
};
269269
writer.write_all(v)
270270
} else {
271-
return CompactFormatter.write_char_escape(&mut writer, char_escape);
271+
CompactFormatter.write_char_escape(&mut writer, char_escape)
272272
}
273273
}
274274

@@ -367,7 +367,7 @@ mod tests {
367367
fn test_object_key() {
368368
let cases = [("\n", "1"), ("\r", "<script>"), ("ö", "דּ")];
369369
for case in cases {
370-
assert_eq!(case.0.cmp(&case.1), Ordering::Less);
370+
assert_eq!(case.0.cmp(case.1), Ordering::Less);
371371
}
372372
let mut v = cases
373373
.iter()
@@ -541,9 +541,8 @@ mod tests {
541541
prop_oneof![
542542
// Take the inner strategy and make the two recursive cases.
543543
prop::collection::vec(inner.clone(), 0..10).prop_map(Value::Array),
544-
prop::collection::hash_map(S, inner, 0..10).prop_map(|v| {
545-
v.into_iter().map(|(k, v)| (k, Value::from(v))).collect()
546-
}),
544+
prop::collection::hash_map(S, inner, 0..10)
545+
.prop_map(|v| { v.into_iter().collect() }),
547546
]
548547
},
549548
)
@@ -552,7 +551,6 @@ mod tests {
552551
proptest! {
553552
#[test]
554553
fn roundtrip_rfc8785(v in arbitrary_json()) {
555-
let v: serde_json::Value = v.into();
556554
let buf = encode!(&v).unwrap();
557555
let v2: serde_json::Value = serde_json::from_slice(&buf)
558556
.map_err(|e| format!("Failed to parse {v:?} -> {}: {e}", String::from_utf8_lossy(&buf))).unwrap();
@@ -658,7 +656,6 @@ mod tests {
658656
fn crosscheck_olpc_cjson(v in arbitrary_json()) {
659657
use olpc_cjson::CanonicalFormatter;
660658

661-
let v: serde_json::Value = v.into();
662659
let mut olpc_cjson_serialized = Vec::new();
663660
let mut ser = serde_json::Serializer::with_formatter(&mut olpc_cjson_serialized, CanonicalFormatter::new());
664661
prop_assume!(v.serialize(&mut ser).is_ok());

0 commit comments

Comments
 (0)