diff --git a/pbjson-build/src/escape.rs b/pbjson-build/src/escape.rs index 554ac85..08a55e0 100644 --- a/pbjson-build/src/escape.rs +++ b/pbjson-build/src/escape.rs @@ -1,4 +1,4 @@ -///! Contains code to escape strings to avoid collisions with reserved Rust keywords +//! Contains code to escape strings to avoid collisions with reserved Rust keywords pub fn escape_ident(mut ident: String) -> String { // Copied from prost-build::ident diff --git a/pbjson-build/src/generator/message.rs b/pbjson-build/src/generator/message.rs index c7cb46e..2d0b277 100644 --- a/pbjson-build/src/generator/message.rs +++ b/pbjson-build/src/generator/message.rs @@ -374,6 +374,11 @@ fn write_serialize_scalar_variable( ) } _ => { + writeln!( + writer, + "{}#[allow(clippy::needless_borrow)]", + Indent(indent) + )?; writeln!( writer, "{}struct_ser.serialize_field(\"{}\", {}(&{}).as_str())?;", diff --git a/pbjson-test/build.rs b/pbjson-test/build.rs index 02bd410..b8907a7 100644 --- a/pbjson-test/build.rs +++ b/pbjson-test/build.rs @@ -28,7 +28,7 @@ fn main() -> Result<()> { .compile_well_known_types() .extern_path(".google.protobuf", "::pbjson_types") .extern_path(".test.external", "crate") - .bytes(&[".test"]) + .bytes([".test"]) .protoc_arg("--experimental_allow_proto3_optional"); if cfg!(feature = "btree") { diff --git a/pbjson-test/src/lib.rs b/pbjson-test/src/lib.rs index a2f604a..ad65a96 100644 --- a/pbjson-test/src/lib.rs +++ b/pbjson-test/src/lib.rs @@ -547,7 +547,11 @@ mod tests { decoded.optional_string = None; verify_decode(&decoded, "{}"); - let date = chrono::Utc.ymd(2072, 3, 1).and_hms_milli(5, 2, 5, 30); + let date = chrono::Utc + .with_ymd_and_hms(2072, 3, 1, 5, 2, 5) + .unwrap() + .checked_add_signed(chrono::Duration::milliseconds(30)) + .unwrap(); decoded.timestamp = Some(Timestamp { seconds: date.timestamp(), nanos: date.timestamp_subsec_nanos() as i32, diff --git a/pbjson-types/build.rs b/pbjson-types/build.rs index 99bebcc..9ef2b31 100644 --- a/pbjson-types/build.rs +++ b/pbjson-types/build.rs @@ -16,8 +16,8 @@ fn main() -> Result<()> { config .file_descriptor_set_path(&descriptor_path) .compile_well_known_types() - .disable_comments(&["."]) - .bytes(&[".google"]) + .disable_comments(["."]) + .bytes([".google"]) .skip_protoc_run(); let empty: &[&str] = &[]; diff --git a/pbjson-types/descriptors.bin b/pbjson-types/descriptors.bin index ad65b4f..b7fe631 100644 Binary files a/pbjson-types/descriptors.bin and b/pbjson-types/descriptors.bin differ diff --git a/pbjson-types/src/duration.rs b/pbjson-types/src/duration.rs index bc2801d..d776ca2 100644 --- a/pbjson-types/src/duration.rs +++ b/pbjson-types/src/duration.rs @@ -43,7 +43,7 @@ impl Serialize for Duration { if self.nanos != 0 { s.push('.'); - let f = match split_nanos(self.nanos.abs() as u32) { + let f = match split_nanos(self.nanos.unsigned_abs()) { (millis, 0, 0) => format!("{:03}", millis), (millis, micros, 0) => format!("{:03}{:03}", millis, micros), (millis, micros, nanos) => format!("{:03}{:03}{:03}", millis, micros, nanos), diff --git a/pbjson-types/src/timestamp.rs b/pbjson-types/src/timestamp.rs index 7f2d22f..1722a9a 100644 --- a/pbjson-types/src/timestamp.rs +++ b/pbjson-types/src/timestamp.rs @@ -4,11 +4,17 @@ use serde::de::Visitor; use serde::Serialize; impl TryFrom for chrono::DateTime { - type Error = std::num::TryFromIntError; + type Error = &'static str; fn try_from(value: Timestamp) -> Result { let Timestamp { seconds, nanos } = value; - let dt = NaiveDateTime::from_timestamp(seconds, nanos.try_into()?); + let dt = NaiveDateTime::from_timestamp_opt( + seconds, + nanos + .try_into() + .map_err(|_| "out of range integral type conversion attempted")?, + ) + .ok_or("invalid or out-of-range datetime")?; Ok(Self::from_utc(dt, Utc)) } } @@ -69,9 +75,10 @@ mod tests { #[test] fn test_date() { - let datetime = FixedOffset::east(5 * 3600) - .ymd(2016, 11, 8) - .and_hms(21, 7, 9); + let datetime = FixedOffset::east_opt(5 * 3600) + .expect("time zone offset should be valid") + .with_ymd_and_hms(2016, 11, 8, 21, 7, 9) + .unwrap(); let encoded = datetime.to_rfc3339(); assert_eq!(&encoded, "2016-11-08T21:07:09+05:00"); diff --git a/rust-toolchain.toml b/rust-toolchain.toml index 4e832fc..7b7e745 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] -channel = "1.61" -components = [ "rustfmt", "clippy" ] +channel = "1.71" +components = ["rustfmt", "clippy"]