diff --git a/ci-gen/src/ghwf.rs b/ci-gen/src/ghwf.rs index 30dc1d517..cbcd1a506 100644 --- a/ci-gen/src/ghwf.rs +++ b/ci-gen/src/ghwf.rs @@ -3,8 +3,7 @@ use std::fmt; use crate::yaml::Yaml; #[allow(dead_code)] -#[derive(Copy, Clone, Eq, PartialEq)] -#[derive(Default)] +#[derive(Copy, Clone, Eq, PartialEq, Default)] pub enum Env { WindowsLatest, #[default] @@ -12,7 +11,6 @@ pub enum Env { MacosLatest, } - impl fmt::Display for Env { fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { match self { diff --git a/ci-gen/src/yaml.rs b/ci-gen/src/yaml.rs index 1446a9da6..4002c5157 100644 --- a/ci-gen/src/yaml.rs +++ b/ci-gen/src/yaml.rs @@ -61,8 +61,7 @@ pub struct YamlWriter { minus: MinusState, } -#[derive(Eq, PartialEq)] -#[derive(Default)] +#[derive(Eq, PartialEq, Default)] enum MinusState { #[default] No, @@ -70,7 +69,6 @@ enum MinusState { Already, } - impl YamlWriter { pub fn write_line(&mut self, line: &str) { if line.is_empty() { diff --git a/protobuf-codegen/src/codegen/mod.rs b/protobuf-codegen/src/codegen/mod.rs index c1ee69464..eb9b3ac39 100644 --- a/protobuf-codegen/src/codegen/mod.rs +++ b/protobuf-codegen/src/codegen/mod.rs @@ -14,15 +14,13 @@ use crate::customize::CustomizeCallbackHolder; use crate::gen_and_write::gen_and_write; use crate::Customize; -#[derive(Debug)] -#[derive(Default)] +#[derive(Debug, Default)] enum WhichParser { #[default] Pure, Protoc, } - #[derive(Debug, thiserror::Error)] enum CodegenError { #[error("out_dir is not specified")] diff --git a/protobuf-codegen/src/gen/all.rs b/protobuf-codegen/src/gen/all.rs index b9738c8ec..28720add3 100644 --- a/protobuf-codegen/src/gen/all.rs +++ b/protobuf-codegen/src/gen/all.rs @@ -42,9 +42,13 @@ pub(crate) fn gen_all( }; for file_name in files_to_generate { - let file = files_map.get(file_name.as_path()).unwrap_or_else(|| panic!("file not found in file descriptors: {:?}, files: {:?}", - file_name, - files_map.keys())); + let file = files_map.get(file_name.as_path()).unwrap_or_else(|| { + panic!( + "file not found in file descriptors: {:?}, files: {:?}", + file_name, + files_map.keys() + ) + }); let gen_file_result = gen_file(file, &files_map, &root_scope, &customize, parser)?; results.push(gen_file_result.compiler_plugin_result); mods.push(gen_file_result.mod_name); diff --git a/protobuf-codegen/src/gen/code_writer.rs b/protobuf-codegen/src/gen/code_writer.rs index 05243ae7d..043bbc100 100644 --- a/protobuf-codegen/src/gen/code_writer.rs +++ b/protobuf-codegen/src/gen/code_writer.rs @@ -26,7 +26,8 @@ impl<'a> CodeWriter<'a> { Self::with_impl::(|w| { f(w); Ok(()) - }).unwrap_or_else(|e| match e {}) + }) + .unwrap_or_else(|e| match e {}) } pub(crate) fn with(f: F) -> anyhow::Result @@ -334,10 +335,7 @@ impl<'a> CodeWriter<'a> { .and_then(|ls| ls.iter().find(|l| l.path == path)) .map(|l| l.leading_comments()); - let lines = doc - .iter() - .flat_map(|doc| doc.lines()) - .collect::>(); + let lines = doc.iter().flat_map(|doc| doc.lines()).collect::>(); // Skip comments with code blocks to avoid rustdoc trying to compile them. if !lines.iter().any(|line| line.starts_with(" ")) { diff --git a/protobuf-codegen/src/gen/oneof.rs b/protobuf-codegen/src/gen/oneof.rs index 4de50579e..a96a2a0fa 100644 --- a/protobuf-codegen/src/gen/oneof.rs +++ b/protobuf-codegen/src/gen/oneof.rs @@ -205,7 +205,8 @@ impl<'a> OneofGen<'a> { let field = self .message .fields - .iter().find(|f| f.proto_field.name() == v.field.name()) + .iter() + .find(|f| f.proto_field.name() == v.field.name()) .unwrap_or_else(|| panic!("field not found by name: {}", v.field.name())); match field.proto_type { field_descriptor_proto::Type::TYPE_GROUP => None, diff --git a/protobuf-codegen/src/gen/scope.rs b/protobuf-codegen/src/gen/scope.rs index 1677bcde4..cc8e8177f 100644 --- a/protobuf-codegen/src/gen/scope.rs +++ b/protobuf-codegen/src/gen/scope.rs @@ -94,7 +94,8 @@ impl<'a> FileScope<'a> { name: &ProtobufRelPathRef, ) -> Option> { self.find_messages_and_enums() - .into_iter().find(|e| e.protobuf_name_to_package().as_ref() == name) + .into_iter() + .find(|e| e.protobuf_name_to_package().as_ref() == name) } fn find_message_or_enum_abs( @@ -206,11 +207,7 @@ impl<'a> Scope<'a> { self.messages() .into_iter() .map(MessageOrEnumWithScope::Message) - .chain( - self.enums() - .into_iter() - .map(MessageOrEnumWithScope::Enum), - ) + .chain(self.enums().into_iter().map(MessageOrEnumWithScope::Enum)) .collect() } @@ -481,9 +478,9 @@ impl<'a> FieldWithContext<'a> { pub fn oneof(&self) -> Option> { self.field.containing_oneof().map(|oneof| OneofWithContext { - message: self.message.clone(), - oneof, - }) + message: self.message.clone(), + oneof, + }) } } diff --git a/protobuf-json-mapping/src/rfc_3339.rs b/protobuf-json-mapping/src/rfc_3339.rs index a8507d726..eed2e3e83 100644 --- a/protobuf-json-mapping/src/rfc_3339.rs +++ b/protobuf-json-mapping/src/rfc_3339.rs @@ -12,7 +12,9 @@ fn is_leap_year(year: i64) -> bool { false } else if year % 100 != 0 { true - } else { year % 400 == 0 } + } else { + year % 400 == 0 + } } fn days_in_year(year: i64) -> u32 { diff --git a/protobuf-parse/src/pure/convert/option_resolver.rs b/protobuf-parse/src/pure/convert/option_resolver.rs index 4069bb03c..6e09a03c1 100644 --- a/protobuf-parse/src/pure/convert/option_resolver.rs +++ b/protobuf-parse/src/pure/convert/option_resolver.rs @@ -605,26 +605,28 @@ impl<'a> OptionResoler<'a> { TypeResolved::Bytes => return Ok(UnknownValue::LengthDelimited(s.decode_bytes()?)), _ => {} }, - model::ProtobufConstant::Ident(ident) => if let TypeResolved::Enum(e) = &field_type { - let e = self - .resolver - .find_enum_by_abs_name(e) - .map_err(OptionResolverError::OtherError)?; - let n = match e - .values - .iter() - .find(|v| v.name == format!("{}", ident)) - .map(|v| v.number) - { - Some(n) => n, - None => { - return Err( - OptionResolverError::UnknownEnumValue(ident.to_string()).into() - ) - } - }; - return Ok(UnknownValue::int32(n)); - }, + model::ProtobufConstant::Ident(ident) => { + if let TypeResolved::Enum(e) = &field_type { + let e = self + .resolver + .find_enum_by_abs_name(e) + .map_err(OptionResolverError::OtherError)?; + let n = match e + .values + .iter() + .find(|v| v.name == format!("{}", ident)) + .map(|v| v.number) + { + Some(n) => n, + None => { + return Err( + OptionResolverError::UnknownEnumValue(ident.to_string()).into() + ) + } + }; + return Ok(UnknownValue::int32(n)); + } + } model::ProtobufConstant::Message(mo) => { return self.option_value_message_to_unknown_value( field_type, @@ -651,8 +653,7 @@ impl<'a> OptionResoler<'a> { option_name_for_diag: &str, ) -> anyhow::Result { let field_type = self.resolver.field_type(scope, name, field_type)?; - self - .option_value_to_unknown_value(&field_type, value, option_name_for_diag) + self.option_value_to_unknown_value(&field_type, value, option_name_for_diag) .context("parsing custom option value") } @@ -666,7 +667,9 @@ impl<'a> OptionResoler<'a> { where M: MessageFull, { - if M::descriptor().full_name() == "google.protobuf.FieldOptions" && (option.get() == "default" || option.get() == "json_name") { + if M::descriptor().full_name() == "google.protobuf.FieldOptions" + && (option.get() == "default" || option.get() == "json_name") + { // some options are written to non-options message and handled outside return Ok(()); } diff --git a/protobuf-parse/src/pure/model.rs b/protobuf-parse/src/pure/model.rs index 179c80b5d..9fe5acdc9 100644 --- a/protobuf-parse/src/pure/model.rs +++ b/protobuf-parse/src/pure/model.rs @@ -45,16 +45,12 @@ impl Deref for WithLoc { impl WithLoc { pub fn with_loc(loc: Loc) -> impl FnOnce(T) -> WithLoc { - move |t| WithLoc { - t, - loc, - } + move |t| WithLoc { t, loc } } } /// Protobuf syntax. -#[derive(Debug, Clone, Copy, Eq, PartialEq)] -#[derive(Default)] +#[derive(Debug, Clone, Copy, Eq, PartialEq, Default)] pub(crate) enum Syntax { /// Protobuf syntax [2](https://developers.google.com/protocol-buffers/docs/proto) (default) #[default] @@ -63,7 +59,6 @@ pub(crate) enum Syntax { Proto3, } - /// A field rule #[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)] pub(crate) enum Rule { @@ -525,8 +520,7 @@ pub(crate) struct ProtobufOption { } /// Visibility of import statement -#[derive(Debug, Clone, Eq, PartialEq)] -#[derive(Default)] +#[derive(Debug, Clone, Eq, PartialEq, Default)] pub(crate) enum ImportVis { #[default] Default, @@ -534,7 +528,6 @@ pub(crate) enum ImportVis { Weak, } - /// Import statement #[derive(Debug, Default, Clone)] pub(crate) struct Import { diff --git a/protobuf-parse/src/pure/parser.rs b/protobuf-parse/src/pure/parser.rs index 56652306c..02fe92789 100644 --- a/protobuf-parse/src/pure/parser.rs +++ b/protobuf-parse/src/pure/parser.rs @@ -1292,8 +1292,8 @@ mod test { P: FnOnce(&mut Parser) -> anyhow::Result, { let mut parser = Parser::new(input); - let r = - parse_what(&mut parser).unwrap_or_else(|_| panic!("parse failed at {}", parser.tokenizer.loc())); + let r = parse_what(&mut parser) + .unwrap_or_else(|_| panic!("parse failed at {}", parser.tokenizer.loc())); let eof = parser .tokenizer .syntax_eof() @@ -1307,10 +1307,9 @@ mod test { P: FnOnce(&mut Parser) -> anyhow::Result>, { let mut parser = Parser::new(input); - let o = - parse_what(&mut parser).unwrap_or_else(|_| panic!("parse failed at {}", parser.tokenizer.loc())); - let r = o.unwrap_or_else(|| panic!("parser returned none at {}", - parser.tokenizer.loc())); + let o = parse_what(&mut parser) + .unwrap_or_else(|_| panic!("parse failed at {}", parser.tokenizer.loc())); + let r = o.unwrap_or_else(|| panic!("parser returned none at {}", parser.tokenizer.loc())); assert!(parser.tokenizer.syntax_eof().unwrap()); r } diff --git a/protobuf-parse/src/which_parser.rs b/protobuf-parse/src/which_parser.rs index 09364c2df..cee9a2244 100644 --- a/protobuf-parse/src/which_parser.rs +++ b/protobuf-parse/src/which_parser.rs @@ -1,6 +1,5 @@ /// Which parse to use to parse `.proto` files. -#[derive(Debug, Copy, Clone)] -#[derive(Default)] +#[derive(Debug, Copy, Clone, Default)] pub(crate) enum WhichParser { /// Pure Rust parser implemented by this crate. #[default] @@ -8,4 +7,3 @@ pub(crate) enum WhichParser { /// Parse `.proto` files using `protoc --descriptor_set_out=...` command. Protoc, } - diff --git a/protobuf-support/src/lexer/tokenizer.rs b/protobuf-support/src/lexer/tokenizer.rs index 6c5be3a33..057bc9547 100644 --- a/protobuf-support/src/lexer/tokenizer.rs +++ b/protobuf-support/src/lexer/tokenizer.rs @@ -306,7 +306,8 @@ mod test { P: FnOnce(&mut Tokenizer) -> TokenizerResult, { let mut tokenizer = Tokenizer::new(input, ParserLanguage::Proto); - let r = what(&mut tokenizer).unwrap_or_else(|_| panic!("parse failed at {}", tokenizer.loc())); + let r = + what(&mut tokenizer).unwrap_or_else(|_| panic!("parse failed at {}", tokenizer.loc())); let eof = tokenizer .syntax_eof() .unwrap_or_else(|_| panic!("check eof failed at {}", tokenizer.loc())); diff --git a/protobuf/src/coded_input_stream/buf_read_iter.rs b/protobuf/src/coded_input_stream/buf_read_iter.rs index dda46615d..d8217dbc4 100644 --- a/protobuf/src/coded_input_stream/buf_read_iter.rs +++ b/protobuf/src/coded_input_stream/buf_read_iter.rs @@ -51,7 +51,9 @@ pub(crate) struct BufReadIter<'a> { impl<'a> Drop for BufReadIter<'a> { fn drop(&mut self) { - if let InputSource::Read(ref mut buf_read) = self.input_source { buf_read.consume(self.buf.pos_within_buf()) } + if let InputSource::Read(ref mut buf_read) = self.input_source { + buf_read.consume(self.buf.pos_within_buf()) + } } } diff --git a/protobuf/src/coded_input_stream/mod.rs b/protobuf/src/coded_input_stream/mod.rs index 9f5ab3539..6f9b67053 100644 --- a/protobuf/src/coded_input_stream/mod.rs +++ b/protobuf/src/coded_input_stream/mod.rs @@ -528,8 +528,7 @@ impl<'a> CodedInputStream<'a> { WireType::Fixed32 => self.read_fixed32().map(UnknownValue::Fixed32), WireType::LengthDelimited => { let len = self.read_raw_varint32()?; - self.read_raw_bytes(len) - .map(UnknownValue::LengthDelimited) + self.read_raw_bytes(len).map(UnknownValue::LengthDelimited) } WireType::StartGroup => { self.skip_group()?; diff --git a/protobuf/src/reflect/file/index.rs b/protobuf/src/reflect/file/index.rs index 41c1cb21b..590c50183 100644 --- a/protobuf/src/reflect/file/index.rs +++ b/protobuf/src/reflect/file/index.rs @@ -393,9 +393,11 @@ impl FileDescriptorCommon { return Err(ReflectError::NonUniqueFieldName(f.name().to_owned()).into()); } - if field_index.json_name != f.name() && index_by_name_or_json_name + if field_index.json_name != f.name() + && index_by_name_or_json_name .insert(field_index.json_name.clone(), i) - .is_some() { + .is_some() + { return Err(ReflectError::NonUniqueFieldName(f.name().to_owned()).into()); } } diff --git a/protobuf/src/reflect/map/generated.rs b/protobuf/src/reflect/map/generated.rs index 71e05402d..e825016a1 100644 --- a/protobuf/src/reflect/map/generated.rs +++ b/protobuf/src/reflect/map/generated.rs @@ -108,7 +108,9 @@ impl<'a, K: ProtobufValue, V: ProtobufValue, I: Iterator> ReflectMapIterTrait<'a> for GeneratedMapIterImpl<'a, K, V, I> { fn next(&mut self) -> Option<(ReflectValueRef<'a>, ReflectValueRef<'a>)> { - self.iter.next().map(|(k, v)| (K::RuntimeType::as_ref(k), V::RuntimeType::as_ref(v))) + self.iter + .next() + .map(|(k, v)| (K::RuntimeType::as_ref(k), V::RuntimeType::as_ref(v))) } fn _key_type(&self) -> RuntimeType { diff --git a/protobuf/src/unknown.rs b/protobuf/src/unknown.rs index 3f9d0980b..545fc5075 100644 --- a/protobuf/src/unknown.rs +++ b/protobuf/src/unknown.rs @@ -167,7 +167,11 @@ impl UnknownValues { Some(UnknownValueRef::Fixed64(*last)) } else if let Some(last) = self.varint.last() { Some(UnknownValueRef::Varint(*last)) - } else { self.length_delimited.last().map(|last| UnknownValueRef::LengthDelimited(last)) } + } else { + self.length_delimited + .last() + .map(|last| UnknownValueRef::LengthDelimited(last)) + } } } diff --git a/test-crates/perftest/vs-cxx/perftest.rs b/test-crates/perftest/vs-cxx/perftest.rs index a463533b3..359f79ecc 100644 --- a/test-crates/perftest/vs-cxx/perftest.rs +++ b/test-crates/perftest/vs-cxx/perftest.rs @@ -110,10 +110,7 @@ fn main() { if args.len() > 3 { panic!("usage: {} [data_size] [test]", args[0]) } - let data_size = args - .get(1) - .map(|x| x.parse().unwrap()) - .unwrap_or(1000000); + let data_size = args.get(1).map(|x| x.parse().unwrap()).unwrap_or(1000000); let selected = args.get(2).cloned(); let mut runner = TestRunner { diff --git a/test-crates/protobuf-codegen-identical-test/tests/diff.rs b/test-crates/protobuf-codegen-identical-test/tests/diff.rs index 8946fa4da..b148e1020 100644 --- a/test-crates/protobuf-codegen-identical-test/tests/diff.rs +++ b/test-crates/protobuf-codegen-identical-test/tests/diff.rs @@ -329,8 +329,8 @@ where normalize_generated_file_in_place(Path::new(&protoc_rs)); normalize_generated_file_in_place(Path::new(&pure_rs)); - let protoc_rs_contents = - fs::read_to_string(&protoc_rs).unwrap_or_else(|_| panic!("while reading {}", protoc_rs)); + let protoc_rs_contents = fs::read_to_string(&protoc_rs) + .unwrap_or_else(|_| panic!("while reading {}", protoc_rs)); let pure_rs_contents = fs::read_to_string(&pure_rs).unwrap_or_else(|_| panic!("while reading {}", pure_rs)); diff --git a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs index 85053f8a5..be6592438 100644 --- a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs +++ b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_oneof_nonexhaustive.rs @@ -1,4 +1,3 @@ - use super::test_oneof_nonexhaustive_pb::*; #[test] diff --git a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_basic.rs b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_basic.rs index bb5172ed5..e2e733f4d 100644 --- a/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_basic.rs +++ b/test-crates/protobuf-codegen-protoc-test/src/common/v2/test_reflect_basic.rs @@ -46,12 +46,10 @@ fn test_singular_basic() { bool_field.set_singular_field(&mut message, ReflectValueBox::Bool(true)); assert!(bool_field.has_field(&message)); - assert!( - bool_field - .get_singular_field_or_default(&message) - .to_bool() - .unwrap() - ); + assert!(bool_field + .get_singular_field_or_default(&message) + .to_bool() + .unwrap()); } fn test_singular_field(message: &mut dyn MessageDyn, field: &FieldDescriptor) { diff --git a/test-crates/protobuf-test-common/src/build.rs b/test-crates/protobuf-test-common/src/build.rs index 70c622cd4..682b88a1a 100644 --- a/test-crates/protobuf-test-common/src/build.rs +++ b/test-crates/protobuf-test-common/src/build.rs @@ -77,7 +77,8 @@ fn clean_recursively(dir: &Path, patterns: &[&str]) { } else { for pattern in &patterns_compiled { if pattern.matches(file_name) { - fs::remove_file(&entry_path).unwrap_or_else(|_| panic!("remove_file {:?}", entry_path)); + fs::remove_file(&entry_path) + .unwrap_or_else(|_| panic!("remove_file {:?}", entry_path)); break; } } @@ -160,7 +161,8 @@ fn test_version_from_file_path(mut file_path: &Path) -> TestProtobufVersions { } fn test_version_from_file_content(file_path: &Path) -> ProtobufSyntax { - let content = fs::read_to_string(file_path).unwrap_or_else(|_| panic!("read_to_string {:?}", file_path)); + let content = + fs::read_to_string(file_path).unwrap_or_else(|_| panic!("read_to_string {:?}", file_path)); if content.contains("syntax = \"proto2\"") { ProtobufSyntax::V2 } else if content.contains("syntax = \"proto3\"") { diff --git a/test-crates/protobuf-test-common/src/json_tests.rs b/test-crates/protobuf-test-common/src/json_tests.rs index d6798813a..f71716d6c 100644 --- a/test-crates/protobuf-test-common/src/json_tests.rs +++ b/test-crates/protobuf-test-common/src/json_tests.rs @@ -31,8 +31,8 @@ pub fn test_json_message(m: &dyn MessageDyn) { let s = protobuf_json_mapping::print_to_string(m).expect("print_to_string"); let mut new = descriptor.new_instance(); - protobuf_json_mapping::merge_from_str(&mut *new, &s).unwrap_or_else(|_| panic!("failed to parse serialized: {}; from message: {:?}", - s, m)); + protobuf_json_mapping::merge_from_str(&mut *new, &s) + .unwrap_or_else(|_| panic!("failed to parse serialized: {}; from message: {:?}", s, m)); assert!( m.reflect_eq_dyn(&*new, &ReflectEqMode::nan_equal()), "{:?} should be == {:?}",