From f325ddfb83b8bcc9aa1a67d9383e0a4dd28a35d7 Mon Sep 17 00:00:00 2001 From: Jiayu Liu Date: Sun, 29 Sep 2024 00:13:50 +0800 Subject: [PATCH] THRIFT-5819: use latest rustc version for rustlib Client: rust This upgrades the version of rust in the rust-toolchain file, docs and dockerfiles. Doing so requires a few changes to the source, mainly to fix or silence new warnings. Submitted on behalf of a third-party: Jiayu Liu Derived from the following PR: https://github.com/apache/thrift/pull/3045 --- .github/workflows/build.yml | 2 +- LANGUAGES.md | 2 +- build/docker/README.md | 2 +- build/docker/ubuntu-focal/Dockerfile | 2 +- build/docker/ubuntu-jammy/Dockerfile | 2 +- compiler/cpp/src/thrift/generate/t_rs_generator.cc | 4 ++-- lib/rs/src/lib.rs | 2 +- lib/rs/src/protocol/compact.rs | 4 +--- lib/rs/src/protocol/stored.rs | 4 ++++ lib/rs/src/transport/framed.rs | 2 +- rust-toolchain | 2 +- test/rs/src/bin/test_client.rs | 5 +---- 12 files changed, 16 insertions(+), 17 deletions(-) diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml index 1e953b6ebba..a097c87a6b7 100644 --- a/.github/workflows/build.yml +++ b/.github/workflows/build.yml @@ -400,7 +400,7 @@ jobs: needs: compiler runs-on: ubuntu-24.04 env: - TOOLCHAIN_VERSION: 1.65.0 + TOOLCHAIN_VERSION: 1.83.0 steps: - uses: actions/checkout@v4 diff --git a/LANGUAGES.md b/LANGUAGES.md index 26ee55576fb..598edb2c538 100644 --- a/LANGUAGES.md +++ b/LANGUAGES.md @@ -319,7 +319,7 @@ Thrift's core protocol is TBinary, supported by all languages except for JavaScr Rust 0.11.0 Yes -1.65.01.xx.x +1.83.01.xx.x YesYes Yes diff --git a/build/docker/README.md b/build/docker/README.md index 6b535df1b8a..1f67d1d7331 100644 --- a/build/docker/README.md +++ b/build/docker/README.md @@ -196,6 +196,6 @@ Last updated: March 5, 2024 | python2 | 2.7.18 | | | | python3 | 3.8.10 | 3.10.12 | | | ruby | 2.7.0p0 | 3.0.2p107 | | -| rust | 1.65.0 | 1.65.0 | | +| rust | 1.83.0 | 1.83.0 | | | smalltalk | | | Not in CI | | swift | 5.7 | 5.7 | | diff --git a/build/docker/ubuntu-focal/Dockerfile b/build/docker/ubuntu-focal/Dockerfile index 02f84c673d5..52ea5a4d79b 100644 --- a/build/docker/ubuntu-focal/Dockerfile +++ b/build/docker/ubuntu-focal/Dockerfile @@ -273,7 +273,7 @@ RUN apt-get install -y --no-install-recommends \ USER ${user} RUN `# Rust dependencies` \ - curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.65.0 -y + curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.83.0 -y ENV PATH /home/${user}/.cargo/bin:$PATH USER root diff --git a/build/docker/ubuntu-jammy/Dockerfile b/build/docker/ubuntu-jammy/Dockerfile index a37b7c61ff6..b35111c9695 100644 --- a/build/docker/ubuntu-jammy/Dockerfile +++ b/build/docker/ubuntu-jammy/Dockerfile @@ -272,7 +272,7 @@ RUN apt-get install -y --no-install-recommends \ USER ${user} RUN `# Rust dependencies` \ - curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.65.0 -y + curl https://sh.rustup.rs -sSf | sh -s -- --default-toolchain 1.83.0 -y ENV PATH /home/${user}/.cargo/bin:$PATH USER root diff --git a/compiler/cpp/src/thrift/generate/t_rs_generator.cc b/compiler/cpp/src/thrift/generate/t_rs_generator.cc index 780c8fd2914..e336077e15f 100644 --- a/compiler/cpp/src/thrift/generate/t_rs_generator.cc +++ b/compiler/cpp/src/thrift/generate/t_rs_generator.cc @@ -749,8 +749,8 @@ void t_rs_generator::render_const_value(t_type* ttype, } else if (ttype->is_enum()) { f_gen_ << "{" << '\n'; indent_up(); - f_gen_ << indent() << to_rust_type(ttype) << "::try_from(" << tvalue->get_integer() - << ").expect(\"expecting valid const value\")" << '\n'; + f_gen_ << indent() << to_rust_type(ttype) << "::from(" << tvalue->get_integer() + << ")" << '\n'; indent_down(); f_gen_ << indent() << "}"; } else if (ttype->is_struct() || ttype->is_xception()) { diff --git a/lib/rs/src/lib.rs b/lib/rs/src/lib.rs index 84c1f9b71a7..2f6018810b3 100644 --- a/lib/rs/src/lib.rs +++ b/lib/rs/src/lib.rs @@ -53,7 +53,7 @@ //! [tutorial]: https://github.com/apache/thrift/tree/master/tutorial/rs #![crate_type = "lib"] -#![doc(test(attr(allow(unused_variables), deny(warnings))))] +#![doc(test(attr(allow(unused_variables, dead_code), deny(warnings))))] #![deny(bare_trait_objects)] // NOTE: this macro has to be defined before any modules. See: diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs index c0c43722ed8..8ed4e0635e4 100644 --- a/lib/rs/src/protocol/compact.rs +++ b/lib/rs/src/protocol/compact.rs @@ -681,8 +681,6 @@ fn u8_to_type(b: u8) -> crate::Result { #[cfg(test)] mod tests { - use std::i32; - use crate::protocol::{ TFieldIdentifier, TInputProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier, TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType, @@ -2818,7 +2816,7 @@ mod tests { copy_write_buffer_to_read_buffer!(o_prot); let read_double = i_prot.read_double().unwrap(); - assert!(read_double - double < std::f64::EPSILON); + assert!((read_double - double).abs() < f64::EPSILON); } #[test] diff --git a/lib/rs/src/protocol/stored.rs b/lib/rs/src/protocol/stored.rs index f4bdfb19780..04d3277faf3 100644 --- a/lib/rs/src/protocol/stored.rs +++ b/lib/rs/src/protocol/stored.rs @@ -83,6 +83,8 @@ pub struct TStoredInputProtocol<'a> { message_ident: Option, } +// Erroneous suggestion by clippy +#[allow(clippy::needless_lifetimes)] impl<'a> TStoredInputProtocol<'a> { /// Create a `TStoredInputProtocol` that delegates all calls other than /// `TInputProtocol::read_message_begin(...)` to a `wrapped` @@ -100,6 +102,8 @@ impl<'a> TStoredInputProtocol<'a> { } } +// Erroneous suggestion by clippy +#[allow(clippy::needless_lifetimes)] impl<'a> TInputProtocol for TStoredInputProtocol<'a> { fn read_message_begin(&mut self) -> crate::Result { self.message_ident.take().ok_or_else(|| { diff --git a/lib/rs/src/transport/framed.rs b/lib/rs/src/transport/framed.rs index c30ccd9ed62..d8a7448725f 100644 --- a/lib/rs/src/transport/framed.rs +++ b/lib/rs/src/transport/framed.rs @@ -97,7 +97,7 @@ where self.buf.resize(buf_capacity, 0); self.chan.read_exact(&mut self.buf[..message_size])?; - self.cap = message_size as usize; + self.cap = message_size; self.pos = 0; } diff --git a/rust-toolchain b/rust-toolchain index 902c74186fb..6b4de0a42b0 100644 --- a/rust-toolchain +++ b/rust-toolchain @@ -1 +1 @@ -1.65.0 +1.83.0 diff --git a/test/rs/src/bin/test_client.rs b/test/rs/src/bin/test_client.rs index fd3a18550b9..801ccc4b504 100644 --- a/test/rs/src/bin/test_client.rs +++ b/test/rs/src/bin/test_client.rs @@ -252,10 +252,7 @@ fn make_thrift_calls( info!("testi64"); // try!(verify_expected_result(thrift_test_client.test_i64(-8651829879438294565), // -8651829879438294565)); - verify_expected_result( - thrift_test_client.test_i64(i64::min_value()), - i64::min_value(), - )?; + verify_expected_result(thrift_test_client.test_i64(i64::MIN), i64::MIN)?; info!("testDouble"); verify_expected_result(