Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix CI builds #104

Merged
merged 7 commits into from
Aug 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion pbjson-build/src/escape.rs
Original file line number Diff line number Diff line change
@@ -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
Expand Down
5 changes: 5 additions & 0 deletions pbjson-build/src/generator/message.rs
Original file line number Diff line number Diff line change
Expand Up @@ -374,6 +374,11 @@ fn write_serialize_scalar_variable<W: Write>(
)
}
_ => {
writeln!(
writer,
"{}#[allow(clippy::needless_borrow)]",
Indent(indent)
)?;
writeln!(
writer,
"{}struct_ser.serialize_field(\"{}\", {}(&{}).as_str())?;",
Expand Down
2 changes: 1 addition & 1 deletion pbjson-test/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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") {
Expand Down
6 changes: 5 additions & 1 deletion pbjson-test/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
4 changes: 2 additions & 2 deletions pbjson-types/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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] = &[];
Expand Down
Binary file modified pbjson-types/descriptors.bin
Binary file not shown.
2 changes: 1 addition & 1 deletion pbjson-types/src/duration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand Down
17 changes: 12 additions & 5 deletions pbjson-types/src/timestamp.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,17 @@ use serde::de::Visitor;
use serde::Serialize;

impl TryFrom<Timestamp> for chrono::DateTime<Utc> {
type Error = std::num::TryFromIntError;
type Error = &'static str;
fn try_from(value: Timestamp) -> Result<Self, Self::Error> {
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))
}
}
Expand Down Expand Up @@ -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");

Expand Down
4 changes: 2 additions & 2 deletions rust-toolchain.toml
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
[toolchain]
channel = "1.61"
components = [ "rustfmt", "clippy" ]
channel = "1.71"
components = ["rustfmt", "clippy"]