diff --git a/conformance/src/main.rs b/conformance/src/main.rs index db404c322..157d859ad 100644 --- a/conformance/src/main.rs +++ b/conformance/src/main.rs @@ -17,7 +17,7 @@ fn main() -> io::Result<()> { loop { bytes.resize(4, 0); - if io::stdin().read_exact(&mut *bytes).is_err() { + if io::stdin().read_exact(&mut bytes).is_err() { // No more test cases. return Ok(()); } @@ -25,7 +25,7 @@ fn main() -> io::Result<()> { let len = bytes.as_slice().get_u32_le() as usize; bytes.resize(len, 0); - io::stdin().read_exact(&mut *bytes)?; + io::stdin().read_exact(&mut bytes)?; let result = match ConformanceRequest::decode(&*bytes) { Ok(request) => handle_request(request), diff --git a/prost-build/src/lib.rs b/prost-build/src/lib.rs index 99f084963..e8f51d0fc 100644 --- a/prost-build/src/lib.rs +++ b/prost-build/src/lib.rs @@ -1081,8 +1081,8 @@ impl Config { #[cfg(feature = "format")] fn fmt_modules(&mut self, modules: &mut HashMap) { - for (_, buf) in modules { - let file = syn::parse_file(&buf).unwrap(); + for buf in modules.values_mut() { + let file = syn::parse_file(buf).unwrap(); let formatted = prettyplease::unparse(&file); *buf = formatted; } @@ -1523,6 +1523,6 @@ mod tests { let mut f = File::open(filepath).unwrap(); let mut content = String::new(); f.read_to_string(&mut content).unwrap(); - return content; + content } } diff --git a/prost-derive/src/field/map.rs b/prost-derive/src/field/map.rs index d67d8e6c2..6c70fb364 100644 --- a/prost-derive/src/field/map.rs +++ b/prost-derive/src/field/map.rs @@ -65,7 +65,7 @@ impl Field { .get_ident() .and_then(|i| MapTy::from_str(&i.to_string())) { - let (k, v): (String, String) = match &*attr { + let (k, v): (String, String) = match attr { Meta::NameValue(MetaNameValue { lit: Lit::Str(lit), .. }) => { diff --git a/prost-types/src/datetime.rs b/prost-types/src/datetime.rs index 954fa7610..f6c3cca1c 100644 --- a/prost-types/src/datetime.rs +++ b/prost-types/src/datetime.rs @@ -349,7 +349,7 @@ fn parse_digits(s: &str) -> (&str, &str) { fn parse_char(s: &str, c: u8) -> Option<&str> { debug_assert!(s.is_ascii()); - ensure!(*s.as_bytes().get(0)? == c); + ensure!(*s.as_bytes().first()? == c); Some(&s[1..]) } @@ -358,7 +358,7 @@ fn parse_char(s: &str, c: u8) -> Option<&str> { fn parse_char_ignore_case(s: &str, c: u8) -> Option<&str> { debug_assert!(s.is_ascii()); - ensure!(s.as_bytes().get(0)?.eq_ignore_ascii_case(&c)); + ensure!(s.as_bytes().first()?.eq_ignore_ascii_case(&c)); Some(&s[1..]) } diff --git a/prost-types/src/lib.rs b/prost-types/src/lib.rs index e8d8c9952..1d4a24c4f 100644 --- a/prost-types/src/lib.rs +++ b/prost-types/src/lib.rs @@ -142,6 +142,7 @@ impl fmt::Display for Duration { } /// A duration handling error. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Debug, PartialEq)] #[non_exhaustive] pub enum DurationError { @@ -315,6 +316,7 @@ impl From for Timestamp { } /// A timestamp handling error. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Debug, PartialEq)] #[non_exhaustive] pub enum TimestampError { diff --git a/protobuf/build.rs b/protobuf/build.rs index f296d9485..51495ff47 100644 --- a/protobuf/build.rs +++ b/protobuf/build.rs @@ -83,7 +83,7 @@ fn main() -> Result<()> { // compare based on the Rust PartialEq implementations is difficult, due to presence of NaN // values. prost_build::Config::new() - .btree_map(&["."]) + .btree_map(["."]) .compile_protos( &[ test_includes.join("test_messages_proto2.proto"), @@ -171,7 +171,7 @@ fn install_conformance_test_runner(src_dir: &Path, prefix_dir: &Path) -> Result< .arg(&format!("-DCMAKE_INSTALL_PREFIX={}", prefix_dir.display())) .arg("-Dprotobuf_BUILD_CONFORMANCE=ON") .arg("-Dprotobuf_BUILD_TESTS=OFF") - .current_dir(&src_dir) + .current_dir(src_dir) .status() .context("failed to execute CMake")?; assert!(rc.success(), "protobuf CMake failed"); @@ -182,7 +182,7 @@ fn install_conformance_test_runner(src_dir: &Path, prefix_dir: &Path) -> Result< .arg("-j") .arg(&num_jobs) .arg("install") - .current_dir(&src_dir) + .current_dir(src_dir) .status() .context("failed to execute ninja protobuf")?; ensure!(rc.success(), "failed to make protobuf"); diff --git a/src/encoding.rs b/src/encoding.rs index 60b55204a..e4d2aa274 100644 --- a/src/encoding.rs +++ b/src/encoding.rs @@ -264,7 +264,7 @@ pub fn encoded_len_varint(value: u64) -> usize { ((((value | 1).leading_zeros() ^ 63) * 9 + 73) / 64) as usize } -#[derive(Clone, Copy, Debug, PartialEq)] +#[derive(Clone, Copy, Debug, PartialEq, Eq)] #[repr(u8)] pub enum WireType { Varint = 0, @@ -575,7 +575,7 @@ macro_rules! varint { ); } varint!(bool, bool, - to_uint64(value) if *value { 1u64 } else { 0u64 }, + to_uint64(value) u64::from(*value), from_uint64(value) value != 0); varint!(i32, int32); varint!(i64, int64); @@ -1615,7 +1615,8 @@ mod test { assert_eq!(encoded_len_varint(value), encoded.len()); - let roundtrip_value = decode_varint(&mut encoded.clone()).expect("decoding failed"); + let roundtrip_value = + decode_varint(&mut <&[u8]>::clone(&encoded)).expect("decoding failed"); assert_eq!(value, roundtrip_value); let roundtrip_value = decode_varint_slow(&mut encoded).expect("slow decoding failed"); diff --git a/tests/src/bootstrap.rs b/tests/src/bootstrap.rs index 0bcfae160..d329cad58 100644 --- a/tests/src/bootstrap.rs +++ b/tests/src/bootstrap.rs @@ -27,7 +27,7 @@ fn bootstrap() { prost_build::Config::new() .compile_well_known_types() - .btree_map(&["."]) + .btree_map(["."]) .out_dir(tempdir.path()) .compile_protos( &[ diff --git a/tests/src/build.rs b/tests/src/build.rs index 5f66a5d4a..eb5fa1141 100644 --- a/tests/src/build.rs +++ b/tests/src/build.rs @@ -25,7 +25,7 @@ fn main() { // compare based on the Rust PartialEq implementations is difficult, due to presence of NaN // values. let mut config = prost_build::Config::new(); - config.btree_map(&["."]); + config.btree_map(["."]); // Tests for custom attributes config.type_attribute("Foo.Bar_Baz.Foo_barBaz", "#[derive(Eq, PartialOrd, Ord)]"); config.type_attribute( @@ -97,7 +97,7 @@ fn main() { { let mut config = prost_build::Config::new(); - config.disable_comments(&["."]); + config.disable_comments(["."]); config .compile_protos(&[src.join("invalid_doctest.proto")], includes) @@ -105,7 +105,7 @@ fn main() { } config - .bytes(&["."]) + .bytes(["."]) .compile_protos(&[src.join("well_known_types.proto")], includes) .unwrap(); @@ -115,7 +115,7 @@ fn main() { std::fs::create_dir_all(&out_path).unwrap(); prost_build::Config::new() - .bytes(&["."]) + .bytes(["."]) .out_dir(out_path) .include_file("wellknown_include.rs") .compile_protos(&[src.join("well_known_types.proto")], includes) diff --git a/tests/src/debug.rs b/tests/src/debug.rs index bfcc29569..aa6636b79 100644 --- a/tests/src/debug.rs +++ b/tests/src/debug.rs @@ -68,6 +68,7 @@ fn tuple_struct() { assert_eq!(format!("{:?}", NewType(42)), "NewType(42)"); } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, prost::Oneof)] pub enum OneofWithEnum { #[prost(int32, tag = "8")] diff --git a/tests/src/message_encoding.rs b/tests/src/message_encoding.rs index 9533f9f9c..47c1d6241 100644 --- a/tests/src/message_encoding.rs +++ b/tests/src/message_encoding.rs @@ -5,6 +5,7 @@ use prost::{Enumeration, Message, Oneof}; use crate::check_message; use crate::check_serialize_equivalent; +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct RepeatedFloats { #[prost(float, tag = "11")] @@ -31,6 +32,7 @@ fn check_scalar_types() { } /// A protobuf message which contains all scalar types. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct ScalarTypes { #[prost(int32, tag = "001")] @@ -231,6 +233,7 @@ fn check_tags_inferred() { check_serialize_equivalent(&tags_inferred, &tags_qualified); } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct TagsInferred { #[prost(bool)] @@ -253,6 +256,7 @@ pub struct TagsInferred { pub six: Basic, } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct TagsQualified { #[prost(tag = "1", bool)] @@ -276,6 +280,7 @@ pub struct TagsQualified { } /// A prost message with default value. +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct DefaultValues { #[prost(int32, tag = "1", default = "42")] @@ -318,7 +323,7 @@ fn check_default_values() { } /// A protobuf enum. -#[allow(clippy::upper_case_acronyms)] +#[allow(clippy::upper_case_acronyms, clippy::derive_partial_eq_without_eq)] #[derive(Clone, Copy, Debug, PartialEq, Enumeration)] pub enum BasicEnumeration { ZERO = 0, @@ -327,6 +332,7 @@ pub enum BasicEnumeration { THREE = 3, } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct Basic { #[prost(int32, tag = "1")] @@ -366,6 +372,7 @@ pub struct Basic { pub bytes_map: ::std::collections::HashMap>, } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Message)] pub struct Compound { #[prost(message, optional, tag = "1")] @@ -385,6 +392,7 @@ pub struct Compound { pub message_btree_map: prost::alloc::collections::BTreeMap, } +#[allow(clippy::derive_partial_eq_without_eq)] #[derive(Clone, PartialEq, Oneof)] pub enum BasicOneof { #[prost(int32, tag = "8")]