THRIFT-5819: use latest rustc version for rustlib (#3085)
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
Co-authored-by: Jiayu Liu <jiayu@hey.com>
diff --git a/.github/workflows/build.yml b/.github/workflows/build.yml
index 90eb7f3..abc3714 100644
--- a/.github/workflows/build.yml
+++ b/.github/workflows/build.yml
@@ -400,7 +400,7 @@
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 26ee555..598edb2 100644
--- a/LANGUAGES.md
+++ b/LANGUAGES.md
@@ -319,7 +319,7 @@
<td align=left><a href="https://github.com/apache/thrift/blob/master/lib/rs/README.md">Rust</a></td>
<!-- Since -----------------><td>0.11.0</td>
<!-- Build Systems ---------><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td>
-<!-- Language Levels -------><td>1.65.0</td><td>1.xx.x</td>
+<!-- Language Levels -------><td>1.83.0</td><td>1.xx.x</td>
<!-- Field types -----------><td><img src="/doc/images/cred.png" alt=""/></td>
<!-- Low-Level Transports --><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td>
<!-- Transport Wrappers ----><td><img src="/doc/images/cgrn.png" alt="Yes"/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cred.png" alt=""/></td><td><img src="/doc/images/cred.png" alt=""/></td>
diff --git a/build/docker/README.md b/build/docker/README.md
index 6b535df..1f67d1d 100644
--- a/build/docker/README.md
+++ b/build/docker/README.md
@@ -196,6 +196,6 @@
| 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 02f84c6..52ea5a4 100644
--- a/build/docker/ubuntu-focal/Dockerfile
+++ b/build/docker/ubuntu-focal/Dockerfile
@@ -273,7 +273,7 @@
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 a37b7c6..b35111c 100644
--- a/build/docker/ubuntu-jammy/Dockerfile
+++ b/build/docker/ubuntu-jammy/Dockerfile
@@ -272,7 +272,7 @@
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 780c8fd..e336077 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 @@
} 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 84c1f9b..2f60188 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 c0c4372..8ed4e06 100644
--- a/lib/rs/src/protocol/compact.rs
+++ b/lib/rs/src/protocol/compact.rs
@@ -681,8 +681,6 @@
#[cfg(test)]
mod tests {
- use std::i32;
-
use crate::protocol::{
TFieldIdentifier, TInputProtocol, TListIdentifier, TMapIdentifier, TMessageIdentifier,
TMessageType, TOutputProtocol, TSetIdentifier, TStructIdentifier, TType,
@@ -2818,7 +2816,7 @@
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 f4bdfb1..04d3277 100644
--- a/lib/rs/src/protocol/stored.rs
+++ b/lib/rs/src/protocol/stored.rs
@@ -83,6 +83,8 @@
message_ident: Option<TMessageIdentifier>,
}
+// 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 @@
}
}
+// Erroneous suggestion by clippy
+#[allow(clippy::needless_lifetimes)]
impl<'a> TInputProtocol for TStoredInputProtocol<'a> {
fn read_message_begin(&mut self) -> crate::Result<TMessageIdentifier> {
self.message_ident.take().ok_or_else(|| {
diff --git a/lib/rs/src/transport/framed.rs b/lib/rs/src/transport/framed.rs
index c30ccd9..d8a7448 100644
--- a/lib/rs/src/transport/framed.rs
+++ b/lib/rs/src/transport/framed.rs
@@ -97,7 +97,7 @@
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 902c741..6b4de0a 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 fd3a185..801ccc4 100644
--- a/test/rs/src/bin/test_client.rs
+++ b/test/rs/src/bin/test_client.rs
@@ -252,10 +252,7 @@
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(