Skip to content

Commit

Permalink
chore: Fix clippy lint (#780)
Browse files Browse the repository at this point in the history
  • Loading branch information
tottoto committed Dec 13, 2022
1 parent a7aac76 commit 4e14adf
Show file tree
Hide file tree
Showing 11 changed files with 32 additions and 20 deletions.
4 changes: 2 additions & 2 deletions conformance/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,15 +17,15 @@ 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(());
}

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),
Expand Down
6 changes: 3 additions & 3 deletions prost-build/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1081,8 +1081,8 @@ impl Config {

#[cfg(feature = "format")]
fn fmt_modules(&mut self, modules: &mut HashMap<Module, String>) {
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;
}
Expand Down Expand Up @@ -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
}
}
2 changes: 1 addition & 1 deletion prost-derive/src/field/map.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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), ..
}) => {
Expand Down
4 changes: 2 additions & 2 deletions prost-types/src/datetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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..])
}

Expand All @@ -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..])
}

Expand Down
2 changes: 2 additions & 0 deletions prost-types/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -315,6 +316,7 @@ impl From<std::time::SystemTime> for Timestamp {
}

/// A timestamp handling error.
#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Debug, PartialEq)]
#[non_exhaustive]
pub enum TimestampError {
Expand Down
6 changes: 3 additions & 3 deletions protobuf/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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"),
Expand Down Expand Up @@ -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");
Expand All @@ -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");
Expand Down
7 changes: 4 additions & 3 deletions src/encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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");
Expand Down
2 changes: 1 addition & 1 deletion tests/src/bootstrap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ fn bootstrap() {

prost_build::Config::new()
.compile_well_known_types()
.btree_map(&["."])
.btree_map(["."])
.out_dir(tempdir.path())
.compile_protos(
&[
Expand Down
8 changes: 4 additions & 4 deletions tests/src/build.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down Expand Up @@ -97,15 +97,15 @@ fn main() {

{
let mut config = prost_build::Config::new();
config.disable_comments(&["."]);
config.disable_comments(["."]);

config
.compile_protos(&[src.join("invalid_doctest.proto")], includes)
.unwrap();
}

config
.bytes(&["."])
.bytes(["."])
.compile_protos(&[src.join("well_known_types.proto")], includes)
.unwrap();

Expand All @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
10 changes: 9 additions & 1 deletion tests/src/message_encoding.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand All @@ -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")]
Expand Down Expand Up @@ -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)]
Expand All @@ -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)]
Expand All @@ -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")]
Expand Down Expand Up @@ -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,
Expand All @@ -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")]
Expand Down Expand Up @@ -366,6 +372,7 @@ pub struct Basic {
pub bytes_map: ::std::collections::HashMap<String, Vec<u8>>,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, Message)]
pub struct Compound {
#[prost(message, optional, tag = "1")]
Expand All @@ -385,6 +392,7 @@ pub struct Compound {
pub message_btree_map: prost::alloc::collections::BTreeMap<i32, Basic>,
}

#[allow(clippy::derive_partial_eq_without_eq)]
#[derive(Clone, PartialEq, Oneof)]
pub enum BasicOneof {
#[prost(int32, tag = "8")]
Expand Down

0 comments on commit 4e14adf

Please sign in to comment.