Skip to content

Commit

Permalink
style: run cargo fmt --all
Browse files Browse the repository at this point in the history
  • Loading branch information
plusvic committed Sep 4, 2024
1 parent 35d421f commit dd08537
Show file tree
Hide file tree
Showing 24 changed files with 90 additions and 95 deletions.
4 changes: 1 addition & 3 deletions ci-gen/src/ghwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,14 @@ 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]
UbuntuLatest,
MacosLatest,
}


impl fmt::Display for Env {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down
4 changes: 1 addition & 3 deletions ci-gen/src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,16 +61,14 @@ pub struct YamlWriter {
minus: MinusState,
}

#[derive(Eq, PartialEq)]
#[derive(Default)]
#[derive(Eq, PartialEq, Default)]
enum MinusState {
#[default]
No,
Yes,
Already,
}


impl YamlWriter {
pub fn write_line(&mut self, line: &str) {
if line.is_empty() {
Expand Down
4 changes: 1 addition & 3 deletions protobuf-codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")]
Expand Down
10 changes: 7 additions & 3 deletions protobuf-codegen/src/gen/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
8 changes: 3 additions & 5 deletions protobuf-codegen/src/gen/code_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,8 @@ impl<'a> CodeWriter<'a> {
Self::with_impl::<Infallible, _>(|w| {
f(w);
Ok(())
}).unwrap_or_else(|e| match e {})
})
.unwrap_or_else(|e| match e {})
}

pub(crate) fn with<F>(f: F) -> anyhow::Result<String>
Expand Down Expand Up @@ -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::<Vec<_>>();
let lines = doc.iter().flat_map(|doc| doc.lines()).collect::<Vec<_>>();

// Skip comments with code blocks to avoid rustdoc trying to compile them.
if !lines.iter().any(|line| line.starts_with(" ")) {
Expand Down
3 changes: 2 additions & 1 deletion protobuf-codegen/src/gen/oneof.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
15 changes: 6 additions & 9 deletions protobuf-codegen/src/gen/scope.rs
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,8 @@ impl<'a> FileScope<'a> {
name: &ProtobufRelPathRef,
) -> Option<MessageOrEnumWithScope<'a>> {
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(
Expand Down Expand Up @@ -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()
}

Expand Down Expand Up @@ -481,9 +478,9 @@ impl<'a> FieldWithContext<'a> {

pub fn oneof(&self) -> Option<OneofWithContext<'a>> {
self.field.containing_oneof().map(|oneof| OneofWithContext {
message: self.message.clone(),
oneof,
})
message: self.message.clone(),
oneof,
})
}
}

Expand Down
4 changes: 3 additions & 1 deletion protobuf-json-mapping/src/rfc_3339.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
49 changes: 26 additions & 23 deletions protobuf-parse/src/pure/convert/option_resolver.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -651,8 +653,7 @@ impl<'a> OptionResoler<'a> {
option_name_for_diag: &str,
) -> anyhow::Result<UnknownValue> {
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")
}

Expand All @@ -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(());
}
Expand Down
13 changes: 3 additions & 10 deletions protobuf-parse/src/pure/model.rs
Original file line number Diff line number Diff line change
Expand Up @@ -45,16 +45,12 @@ impl<T> Deref for WithLoc<T> {

impl<T> WithLoc<T> {
pub fn with_loc(loc: Loc) -> impl FnOnce(T) -> WithLoc<T> {
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]
Expand All @@ -63,7 +59,6 @@ pub(crate) enum Syntax {
Proto3,
}


/// A field rule
#[derive(Debug, Clone, Copy, Eq, PartialEq, Hash)]
pub(crate) enum Rule {
Expand Down Expand Up @@ -525,16 +520,14 @@ 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,
Public,
Weak,
}


/// Import statement
#[derive(Debug, Default, Clone)]
pub(crate) struct Import {
Expand Down
11 changes: 5 additions & 6 deletions protobuf-parse/src/pure/parser.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1292,8 +1292,8 @@ mod test {
P: FnOnce(&mut Parser) -> anyhow::Result<R>,
{
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()
Expand All @@ -1307,10 +1307,9 @@ mod test {
P: FnOnce(&mut Parser) -> anyhow::Result<Option<R>>,
{
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
}
Expand Down
4 changes: 1 addition & 3 deletions protobuf-parse/src/which_parser.rs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
/// 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]
Pure,
/// Parse `.proto` files using `protoc --descriptor_set_out=...` command.
Protoc,
}

3 changes: 2 additions & 1 deletion protobuf-support/src/lexer/tokenizer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -306,7 +306,8 @@ mod test {
P: FnOnce(&mut Tokenizer) -> TokenizerResult<R>,
{
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()));
Expand Down
4 changes: 3 additions & 1 deletion protobuf/src/coded_input_stream/buf_read_iter.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}

Expand Down
3 changes: 1 addition & 2 deletions protobuf/src/coded_input_stream/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()?;
Expand Down
6 changes: 4 additions & 2 deletions protobuf/src/reflect/file/index.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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());
}
}
Expand Down
4 changes: 3 additions & 1 deletion protobuf/src/reflect/map/generated.rs
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,9 @@ impl<'a, K: ProtobufValue, V: ProtobufValue, I: Iterator<Item = (&'a K, &'a V)>>
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 {
Expand Down
6 changes: 5 additions & 1 deletion protobuf/src/unknown.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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))
}
}
}

Expand Down
5 changes: 1 addition & 4 deletions test-crates/perftest/vs-cxx/perftest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
4 changes: 2 additions & 2 deletions test-crates/protobuf-codegen-identical-test/tests/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,3 @@

use super::test_oneof_nonexhaustive_pb::*;

#[test]
Expand Down
Loading

0 comments on commit dd08537

Please sign in to comment.