Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: apply fixes to all the codebase with cargo clippy --fix #739

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
37 changes: 16 additions & 21 deletions ci-gen/src/ghwf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,19 +3,14 @@ use std::fmt;
use crate::yaml::Yaml;

#[allow(dead_code)]
#[derive(Copy, Clone, Eq, PartialEq)]
#[derive(Copy, Clone, Eq, PartialEq, Default)]
pub enum Env {
WindowsLatest,
#[default]
UbuntuLatest,
MacosLatest,
}

impl Default for Env {
fn default() -> Self {
Env::UbuntuLatest
}
}

impl fmt::Display for Env {
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
match self {
Expand Down Expand Up @@ -60,7 +55,7 @@ impl Step {
name: name.to_owned(),
uses: Some(uses.to_owned()),
env: env
.into_iter()
.iter()
.map(|(k, v)| (String::from(*k), String::from(*v)))
.collect(),
with: Some(with),
Expand All @@ -85,16 +80,16 @@ impl Step {
}
}

impl Into<Yaml> for Step {
fn into(self) -> Yaml {
impl From<Step> for Yaml {
fn from(val: Step) -> Self {
let Step {
name,
uses,
with,
run,
shell,
env,
} = self;
} = val;
let mut entries = Vec::new();
entries.push(("name", Yaml::string(name)));
if let Some(uses) = uses {
Expand Down Expand Up @@ -134,23 +129,23 @@ impl Job {
}
}

impl Into<(String, Yaml)> for Job {
fn into(self) -> (String, Yaml) {
assert!(!self.id.is_empty());
impl From<Job> for (String, Yaml) {
fn from(val: Job) -> Self {
assert!(!val.id.is_empty());
let mut entries = vec![
("name", Yaml::string(self.name)),
("runs-on", Yaml::string(format!("{}", self.runs_on))),
("name", Yaml::string(val.name)),
("runs-on", Yaml::string(format!("{}", val.runs_on))),
];
if let Some(timeout_minutes) = self.timeout_minutes {
if let Some(timeout_minutes) = val.timeout_minutes {
entries.push((
"timeout-minutes",
Yaml::string(format!("{}", timeout_minutes)),
));
}
if !self.env.is_empty() {
entries.push(("env", Yaml::map(self.env)));
if !val.env.is_empty() {
entries.push(("env", Yaml::map(val.env)));
}
entries.push(("steps", Yaml::list(self.steps)));
(self.id, Yaml::map(entries))
entries.push(("steps", Yaml::list(val.steps)));
(val.id, Yaml::map(entries))
}
}
16 changes: 8 additions & 8 deletions ci-gen/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ enum Features {
impl Features {
fn flag(&self) -> String {
match self {
Features::Default => format!(""),
Features::Default => String::new(),
Features::Specific(f) => format!("--features={}", f.join(",")),
Features::All => format!("--all-features"),
Features::All => "--all-features".to_string(),
}
}

Expand All @@ -72,25 +72,25 @@ impl Features {

fn id(&self) -> String {
match self {
Features::Default => format!("default-features"),
Features::All => format!("all-features"),
Features::Default => "default-features".to_string(),
Features::All => "all-features".to_string(),
Features::Specific(s) => s.join("-"),
}
}

fn name(&self) -> String {
match self {
Features::Default => format!("default features"),
Features::All => format!("all features"),
Features::Default => "default features".to_string(),
Features::All => "all features".to_string(),
Features::Specific(s) => s.join(","),
}
}
}

fn self_check_job() -> Job {
Job {
id: format!("self-check"),
name: format!("CI self-check"),
id: "self-check".to_string(),
name: "CI self-check".to_string(),
runs_on: LINUX.ghwf,
steps: vec![
checkout_sources(),
Expand Down
13 changes: 4 additions & 9 deletions ci-gen/src/yaml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,23 +61,18 @@ pub struct YamlWriter {
minus: MinusState,
}

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

impl Default for MinusState {
fn default() -> Self {
MinusState::No
}
}

impl YamlWriter {
pub fn write_line(&mut self, line: &str) {
if line.is_empty() {
self.buffer.push_str("\n");
self.buffer.push('\n');
} else {
for _ in 0..self.indent {
self.buffer.push_str(" ");
Expand All @@ -95,7 +90,7 @@ impl YamlWriter {
}

self.buffer.push_str(line);
self.buffer.push_str("\n");
self.buffer.push('\n');
}
}

Expand Down
15 changes: 5 additions & 10 deletions protobuf-codegen/src/codegen/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,18 +14,13 @@ use crate::customize::CustomizeCallbackHolder;
use crate::gen_and_write::gen_and_write;
use crate::Customize;

#[derive(Debug)]
#[derive(Debug, Default)]
enum WhichParser {
#[default]
Pure,
Protoc,
}

impl Default for WhichParser {
fn default() -> WhichParser {
WhichParser::Pure
}
}

#[derive(Debug, thiserror::Error)]
enum CodegenError {
#[error("out_dir is not specified")]
Expand Down Expand Up @@ -221,9 +216,9 @@ impl Codegen {

if self.create_out_dir {
if out_dir.exists() {
fs::remove_dir_all(&out_dir)?;
fs::remove_dir_all(out_dir)?;
}
fs::create_dir(&out_dir)?;
fs::create_dir(out_dir)?;
}

let mut parser = Parser::new();
Expand Down Expand Up @@ -257,7 +252,7 @@ impl Codegen {
&parsed_and_typechecked.file_descriptors,
&parsed_and_typechecked.parser,
&parsed_and_typechecked.relative_paths,
&out_dir,
out_dir,
&self.customize,
&*self.customize_callback,
)
Expand Down
12 changes: 7 additions & 5 deletions protobuf-codegen/src/gen/all.rs
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,13 @@ pub(crate) fn gen_all(
};

for file_name in files_to_generate {
let file = files_map.get(file_name.as_path()).expect(&format!(
"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
16 changes: 8 additions & 8 deletions protobuf-codegen/src/gen/code_writer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,11 @@ impl<'a> CodeWriter<'a> {
}

pub(crate) fn with_no_error(f: impl FnOnce(&mut CodeWriter)) -> String {
Self::with_impl::<Infallible, _>(|w| Ok(f(w))).unwrap_or_else(|e| match e {})
Self::with_impl::<Infallible, _>(|w| {
f(w);
Ok(())
})
.unwrap_or_else(|e| match e {})
}

pub(crate) fn with<F>(f: F) -> anyhow::Result<String>
Expand All @@ -47,7 +51,7 @@ impl<'a> CodeWriter<'a> {

pub(crate) fn write_line<S: AsRef<str>>(&mut self, line: S) {
if line.as_ref().is_empty() {
self.writer.push_str("\n");
self.writer.push('\n');
} else {
let s: String = [self.indent.as_ref(), line.as_ref(), "\n"].concat();
self.writer.push_str(&s);
Expand Down Expand Up @@ -96,7 +100,7 @@ impl<'a> CodeWriter<'a> {
}

pub(crate) fn unimplemented(&mut self) {
self.write_line(format!("unimplemented!();"));
self.write_line("unimplemented!();");
}

pub(crate) fn indented<F>(&mut self, cb: F)
Expand Down Expand Up @@ -331,11 +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()
.map(|doc| doc.lines())
.flatten()
.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
6 changes: 3 additions & 3 deletions protobuf-codegen/src/gen/enums.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl<'a> EnumGen<'a> {
w.comment("Note: you cannot use pattern matching for enums with allow_alias option");
}
w.derive(&derive);
let ref type_name = self.type_name;
let type_name = &self.type_name;
write_protoc_insertion_point_for_enum(
w,
&self.customize.for_elem,
Expand Down Expand Up @@ -294,7 +294,7 @@ impl<'a> EnumGen<'a> {
}

fn write_impl_enum_full(&self, w: &mut CodeWriter) {
let ref type_name = self.type_name;
let type_name = &self.type_name;
w.impl_for_block(
&format!(
"{}::EnumFull",
Expand Down Expand Up @@ -351,7 +351,7 @@ impl<'a> EnumGen<'a> {
});
w.write_line("};");
}
w.write_line(&format!("Self::enum_descriptor().value_by_index(index)"));
w.write_line("Self::enum_descriptor().value_by_index(index)");
});
}

Expand Down
4 changes: 2 additions & 2 deletions protobuf-codegen/src/gen/field/accessor.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,9 +27,9 @@ impl AccessorFn {
s.push_str("::<_");
for p in &self.type_params {
s.push_str(", ");
s.push_str(&p);
s.push_str(p);
}
s.push_str(">");
s.push('>');
s
}
}
Expand Down
Loading
Loading