THRIFT-5306: Rust code and generated code no longer has clippy warnings (Rust 1.40)

Client: rs

NOTE: Also properly update the min/max supported Rust versions
diff --git a/lib/rs/src/protocol/binary.rs b/lib/rs/src/protocol/binary.rs
index 0ef65e5..22b496c 100644
--- a/lib/rs/src/protocol/binary.rs
+++ b/lib/rs/src/protocol/binary.rs
@@ -26,7 +26,7 @@
 use crate::transport::{TReadTransport, TWriteTransport};
 use crate::{ProtocolError, ProtocolErrorKind};
 
-const BINARY_PROTOCOL_VERSION_1: u32 = 0x80010000;
+const BINARY_PROTOCOL_VERSION_1: u32 = 0x8001_0000;
 
 /// Read messages encoded in the Thrift simple binary encoding.
 ///
@@ -69,8 +69,8 @@
     /// version number in the protocol header.
     pub fn new(transport: T, strict: bool) -> TBinaryInputProtocol<T> {
         TBinaryInputProtocol {
-            strict: strict,
-            transport: transport,
+            strict,
+            transport,
         }
     }
 }
@@ -79,7 +79,7 @@
 where
     T: TReadTransport,
 {
-    #[cfg_attr(feature = "cargo-clippy", allow(collapsible_if))]
+    #[allow(clippy::collapsible_if)]
     fn read_message_begin(&mut self) -> crate::Result<TMessageIdentifier> {
         let mut first_bytes = vec![0; 4];
         self.transport.read_exact(&mut first_bytes[..])?;
@@ -295,8 +295,8 @@
     /// protocol version number in the protocol header.
     pub fn new(transport: T, strict: bool) -> TBinaryOutputProtocol<T> {
         TBinaryOutputProtocol {
-            strict: strict,
-            transport: transport,
+            strict,
+            transport,
         }
     }
 }
@@ -520,7 +520,7 @@
         let ident = TMessageIdentifier::new("test", TMessageType::Call, 1);
         assert!(o_prot.write_message_begin(&ident).is_ok());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 16] = [
             0x80,
             0x01,
@@ -550,7 +550,7 @@
         let ident = TMessageIdentifier::new("test", TMessageType::Call, 1);
         assert!(o_prot.write_message_begin(&ident).is_ok());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 13] = [
             0x00,
             0x00,
@@ -577,7 +577,7 @@
         let ident = TMessageIdentifier::new("test", TMessageType::Reply, 10);
         assert!(o_prot.write_message_begin(&ident).is_ok());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 16] = [
             0x80,
             0x01,
@@ -607,7 +607,7 @@
         let ident = TMessageIdentifier::new("test", TMessageType::Reply, 10);
         assert!(o_prot.write_message_begin(&ident).is_ok());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 13] = [
             0x00,
             0x00,
@@ -892,7 +892,7 @@
     fn must_round_trip_bytes() {
         let (mut i_prot, mut o_prot) = test_objects(true);
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let bytes: [u8; 25] = [
             0x20,
             0xFD,
diff --git a/lib/rs/src/protocol/compact.rs b/lib/rs/src/protocol/compact.rs
index f33c020..6fa364f 100644
--- a/lib/rs/src/protocol/compact.rs
+++ b/lib/rs/src/protocol/compact.rs
@@ -76,7 +76,7 @@
             last_read_field_id: 0,
             read_field_id_stack: Vec::new(),
             pending_read_bool_value: None,
-            transport: transport,
+            transport,
         }
     }
 
@@ -193,7 +193,7 @@
 
                 Ok(TFieldIdentifier {
                     name: None,
-                    field_type: field_type,
+                    field_type,
                     id: Some(self.last_read_field_id),
                 })
             }
@@ -371,7 +371,7 @@
             last_write_field_id: 0,
             write_field_id_stack: Vec::new(),
             pending_write_bool_field_identifier: None,
-            transport: transport,
+            transport,
         }
     }
 
@@ -673,7 +673,7 @@
             431
         )));
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 8] = [
             0x82, /* protocol ID */
             0x21, /* message type | protocol version */
@@ -695,10 +695,10 @@
         assert_success!(o_prot.write_message_begin(&TMessageIdentifier::new(
             "bar",
             TMessageType::Reply,
-            991828
+            991_828
         )));
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 9] = [
             0x82, /* protocol ID */
             0x41, /* message type | protocol version */
@@ -743,7 +743,7 @@
     fn must_round_trip_message_begin() {
         let (mut i_prot, mut o_prot) = test_objects();
 
-        let ident = TMessageIdentifier::new("service_call", TMessageType::Call, 1283948);
+        let ident = TMessageIdentifier::new("service_call", TMessageType::Call, 1_283_948);
 
         assert_success!(o_prot.write_message_begin(&ident));
 
@@ -787,7 +787,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 5] = [
             0x03, /* field type */
             0x00, /* first field id */
@@ -902,7 +902,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 4] = [
             0x15, /* field delta (1) | field type */
             0x1A, /* field delta (1) | field type */
@@ -1015,7 +1015,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 8] = [
             0x05, /* field type */
             0x00, /* first field id */
@@ -1139,7 +1139,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 10] = [
             0x16, /* field delta (1) | field type */
             0x85, /* field delta (8) | field type */
@@ -1156,6 +1156,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_struct_with_mix_of_long_and_delta_fields() {
         let (mut i_prot, mut o_prot) = test_objects();
@@ -1304,7 +1305,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 7] = [
             0x16, /* field delta (1) | field type */
             0x85, /* field delta (8) | field type */
@@ -1318,6 +1319,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_nested_structs_0() {
         // last field of the containing struct is a delta
@@ -1477,7 +1479,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 7] = [
             0x16, /* field delta (1) | field type */
             0x85, /* field delta (8) | field type */
@@ -1491,6 +1493,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_nested_structs_1() {
         // last field of the containing struct is a delta
@@ -1650,7 +1653,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 7] = [
             0x16, /* field delta (1) | field type */
             0x08, /* field type */
@@ -1664,6 +1667,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_nested_structs_2() {
         let (mut i_prot, mut o_prot) = test_objects();
@@ -1820,7 +1824,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 8] = [
             0x16, /* field delta (1) | field type */
             0x08, /* field type */
@@ -1835,6 +1839,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_nested_structs_3() {
         // last field of the containing struct is a full write
@@ -1986,7 +1991,7 @@
         assert_success!(o_prot.write_field_stop());
         assert_success!(o_prot.write_struct_end());
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 7] = [
             0x11, /* field delta (1) | true */
             0x82, /* field delta (8) | false */
@@ -2000,6 +2005,7 @@
         assert_eq_written_bytes!(o_prot, expected);
     }
 
+    #[allow(clippy::cognitive_complexity)]
     #[test]
     fn must_round_trip_bool_field() {
         let (mut i_prot, mut o_prot) = test_objects();
@@ -2245,7 +2251,7 @@
     fn must_round_trip_large_sized_set_begin() {
         let (mut i_prot, mut o_prot) = test_objects();
 
-        let ident = TSetIdentifier::new(TType::Map, 3928429);
+        let ident = TSetIdentifier::new(TType::Map, 3_928_429);
 
         assert_success!(o_prot.write_set_begin(&ident));
 
@@ -2312,7 +2318,7 @@
     fn must_round_trip_map_begin() {
         let (mut i_prot, mut o_prot) = test_objects();
 
-        let ident = TMapIdentifier::new(TType::Map, TType::List, 1928349);
+        let ident = TMapIdentifier::new(TType::Map, TType::List, 1_928_349);
 
         assert_success!(o_prot.write_map_begin(&ident));
 
@@ -2403,11 +2409,13 @@
     fn must_read_write_double() {
         let (mut i_prot, mut o_prot) = test_objects();
 
-        let double = 3.141592653589793238462643;
+        #[allow(clippy::approx_constant)]
+        let double = 3.141_592_653_589_793;
         o_prot.write_double(double).unwrap();
         copy_write_buffer_to_read_buffer!(o_prot);
 
-        assert_eq!(i_prot.read_double().unwrap(), double);
+        let read_double = i_prot.read_double().unwrap();
+        assert!(read_double - double < std::f64::EPSILON);
     }
 
     #[test]
@@ -2415,11 +2423,11 @@
         let (_, mut o_prot) = test_objects();
         let expected = [24, 45, 68, 84, 251, 33, 9, 64];
 
-        let double = 3.141592653589793238462643;
+        #[allow(clippy::approx_constant)]
+        let double = 3.141_592_653_589_793;
         o_prot.write_double(double).unwrap();
 
         assert_eq_written_bytes!(o_prot, expected);
-
     }
 
     fn assert_no_write<F>(mut write_fn: F)
diff --git a/lib/rs/src/protocol/mod.rs b/lib/rs/src/protocol/mod.rs
index b0e9118..f9c1f72 100644
--- a/lib/rs/src/protocol/mod.rs
+++ b/lib/rs/src/protocol/mod.rs
@@ -610,8 +610,8 @@
     ) -> TMessageIdentifier {
         TMessageIdentifier {
             name: name.into(),
-            message_type: message_type,
-            sequence_number: sequence_number,
+            message_type,
+            sequence_number,
         }
     }
 }
@@ -660,7 +660,7 @@
     {
         TFieldIdentifier {
             name: name.into().map(|n| n.into()),
-            field_type: field_type,
+            field_type,
             id: id.into(),
         }
     }
@@ -680,8 +680,8 @@
     /// `element_type`.
     pub fn new(element_type: TType, size: i32) -> TListIdentifier {
         TListIdentifier {
-            element_type: element_type,
-            size: size,
+            element_type,
+            size,
         }
     }
 }
@@ -700,8 +700,8 @@
     /// `element_type`.
     pub fn new(element_type: TType, size: i32) -> TSetIdentifier {
         TSetIdentifier {
-            element_type: element_type,
-            size: size,
+            element_type,
+            size,
         }
     }
 }
@@ -728,7 +728,7 @@
         TMapIdentifier {
             key_type: key_type.into(),
             value_type: value_type.into(),
-            size: size,
+            size,
         }
     }
 }
@@ -747,7 +747,7 @@
 }
 
 impl Display for TMessageType {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
         match *self {
             TMessageType::Call => write!(f, "Call"),
             TMessageType::Reply => write!(f, "Reply"),
@@ -822,7 +822,7 @@
 }
 
 impl Display for TType {
-    fn fmt(&self, f: &mut Formatter) -> fmt::Result {
+    fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
         match *self {
             TType::Stop => write!(f, "STOP"),
             TType::Void => write!(f, "void"),
diff --git a/lib/rs/src/protocol/multiplexed.rs b/lib/rs/src/protocol/multiplexed.rs
index 9c3ba7c..83498fb 100644
--- a/lib/rs/src/protocol/multiplexed.rs
+++ b/lib/rs/src/protocol/multiplexed.rs
@@ -203,7 +203,7 @@
         let ident = TMessageIdentifier::new("bar", TMessageType::Call, 2);
         assert_success!(o_prot.write_message_begin(&ident));
 
-        #[cfg_attr(rustfmt, rustfmt::skip)]
+        #[rustfmt::skip]
         let expected: [u8; 19] = [
             0x80,
             0x01, /* protocol identifier */
diff --git a/lib/rs/src/protocol/stored.rs b/lib/rs/src/protocol/stored.rs
index c5e02fe..179ae07 100644
--- a/lib/rs/src/protocol/stored.rs
+++ b/lib/rs/src/protocol/stored.rs
@@ -92,7 +92,7 @@
     pub fn new(
         wrapped: &mut dyn TInputProtocol,
         message_ident: TMessageIdentifier,
-    ) -> TStoredInputProtocol {
+    ) -> TStoredInputProtocol<'_> {
         TStoredInputProtocol {
             inner: wrapped,
             message_ident: message_ident.into(),