Skip to content

Commit

Permalink
Update lints
Browse files Browse the repository at this point in the history
  • Loading branch information
jhpratt committed Feb 11, 2024
1 parent f11f9b2 commit 9a4480f
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 18 deletions.
3 changes: 1 addition & 2 deletions .github/workflows/build.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -257,8 +257,7 @@ jobs:
run: |
cargo clippy \
--all-features \
--benches \
--tests \
--all-targets \
--target x86_64-unknown-linux-gnu \
--target aarch64-apple-darwin \
--target x86_64-pc-windows-gnu \
Expand Down
1 change: 0 additions & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,6 @@ unused-import-braces = "warn"
unused-lifetimes = "warn"
unused-qualifications = "warn"
# unused-results = "warn"
unused-tuple-struct-fields = "warn"
variant-size-differences = "warn"

[workspace.lints.clippy]
Expand Down
21 changes: 12 additions & 9 deletions tests/serde/timestamps.rs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ fn serialize_timestamp() {
}

#[test]
fn serialize_timestamp_milliseconds() {
fn serialize_timestamp_milliseconds() -> serde_json::Result<()> {
let value_milliseconds = TestMilliseconds {
dt: datetime!(2000-01-01 00:00:00.999 UTC),
};
Expand All @@ -78,14 +78,15 @@ fn serialize_timestamp_milliseconds() {
);
// serde_test does not support I128, see: https://github.com/serde-rs/test/issues/18
let milliseconds_str = r#"{"dt":946684800999}"#;
let deserialized_milliseconds: TestMilliseconds = serde_json::from_str(milliseconds_str).unwrap();
let serialized_milliseconds = serde_json::to_string(&value_milliseconds).unwrap();
let deserialized_milliseconds: TestMilliseconds = serde_json::from_str(milliseconds_str)?;
let serialized_milliseconds = serde_json::to_string(&value_milliseconds)?;
assert_eq!(value_milliseconds.dt, deserialized_milliseconds.dt);
assert_eq!(serialized_milliseconds, milliseconds_str);
Ok(())
}

#[test]
fn serialize_timestamp_microseconds() {
fn serialize_timestamp_microseconds() -> serde_json::Result<()> {
let value_microseconds = TestMicroseconds {
dt: datetime!(2000-01-01 00:00:00.999_999 UTC),
};
Expand All @@ -103,14 +104,15 @@ fn serialize_timestamp_microseconds() {
);
// serde_test does not support I128, see: https://github.com/serde-rs/test/issues/18
let microseconds_str = r#"{"dt":946684800999999}"#;
let deserialized_microseconds: TestMicroseconds = serde_json::from_str(microseconds_str).unwrap();
let serialized_microseconds = serde_json::to_string(&value_microseconds).unwrap();
let deserialized_microseconds: TestMicroseconds = serde_json::from_str(microseconds_str)?;
let serialized_microseconds = serde_json::to_string(&value_microseconds)?;
assert_eq!(value_microseconds.dt, deserialized_microseconds.dt);
assert_eq!(serialized_microseconds, microseconds_str);
Ok(())
}

#[test]
fn serialize_timestamp_nanoseconds() {
fn serialize_timestamp_nanoseconds() -> serde_json::Result<()> {
let value_nanoseconds = TestNanoseconds {
dt: datetime!(2000-01-01 00:00:00.999_999_999 UTC),
};
Expand All @@ -128,8 +130,9 @@ fn serialize_timestamp_nanoseconds() {
);
// serde_test does not support I128, see: https://github.com/serde-rs/test/issues/18
let nanoseconds_str = r#"{"dt":946684800999999999}"#;
let deserialized_nanoseconds: TestNanoseconds = serde_json::from_str(nanoseconds_str).unwrap();
let serialized_nanoseconds = serde_json::to_string(&value_nanoseconds).unwrap();
let deserialized_nanoseconds: TestNanoseconds = serde_json::from_str(nanoseconds_str)?;
let serialized_nanoseconds = serde_json::to_string(&value_nanoseconds)?;
assert_eq!(value_nanoseconds.dt, deserialized_nanoseconds.dt);
assert_eq!(serialized_nanoseconds, nanoseconds_str);
Ok(())
}
1 change: 0 additions & 1 deletion time/src/format_description/parse/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,6 @@ impl From<Error> for crate::error::InvalidFormatDescription {
struct Unused<T>(core::marker::PhantomData<T>);

/// Indicate that a value is currently unused.
#[allow(clippy::missing_const_for_fn)] // false positive
fn unused<T>(_: T) -> Unused<T> {
Unused(core::marker::PhantomData)
}
11 changes: 6 additions & 5 deletions time/src/parsing/iso8601.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
// Basic: [year]["W"][week][dayk]
// Extended: [year]["-"]["W"][week]["-"][dayk]
/// Parse a date in the basic or extended format. Reduced precision is permitted.
#[allow(clippy::needless_pass_by_ref_mut)] // rust-lang/rust-clippy#11620
pub(crate) fn parse_date<'a>(
parsed: &'a mut Parsed,
extended_kind: &'a mut ExtendedKind,
Expand All @@ -37,7 +36,7 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
None => ExtendedKind::Basic, // no separator before mandatory month/ordinal/week
};

let mut ret_error = match (|| {
let parsed_month_day = (|| {
let ParsedItem(mut input, month) = month(input).ok_or(InvalidComponent("month"))?;
if extended_kind.is_extended() {
input = ascii_char::<b'-'>(input)
Expand All @@ -46,7 +45,8 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
}
let ParsedItem(input, day) = day(input).ok_or(InvalidComponent("day"))?;
Ok(ParsedItem(input, (month, day)))
})() {
})();
let mut ret_error = match parsed_month_day {
Ok(ParsedItem(input, (month, day))) => {
*parsed = parsed
.with_year(year)
Expand All @@ -70,7 +70,7 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
return Ok(input);
}

match (|| {
let parsed_week_weekday = (|| {
let input = ascii_char::<b'W'>(input)
.ok_or((false, InvalidLiteral))?
.into_inner();
Expand All @@ -84,7 +84,8 @@ impl<const CONFIG: EncodedConfig> Iso8601<CONFIG> {
let ParsedItem(input, weekday) =
dayk(input).ok_or((true, InvalidComponent("weekday")))?;
Ok(ParsedItem(input, (week, weekday)))
})() {
})();
match parsed_week_weekday {
Ok(ParsedItem(input, (week, weekday))) => {
*parsed = parsed
.with_iso_year(year)
Expand Down

0 comments on commit 9a4480f

Please sign in to comment.