clippy lint corrections

This commit is contained in:
Noah Swerhun 2024-03-25 16:41:54 -05:00
parent ba574d53e1
commit ba48d09072
4 changed files with 15 additions and 16 deletions

View file

@ -21,7 +21,7 @@ pub fn create_compile_commands_content(
let pwd = pwd.canonicalize().unwrap();
let pwd = pwd.to_str().unwrap();
if target.sources.len() == 0 {
if target.sources.is_empty() {
return Err(Error {
kind: ErrorKind::NoSources,
message: format!(
@ -32,7 +32,7 @@ pub fn create_compile_commands_content(
}
for (i, source) in target.sources.iter().enumerate() {
let new_file = source.replace("/", "-");
let new_file = source.replace('/', "-");
let obj_name = format!("{}/{}/obj/{}.o", config.build_dir, name, new_file);
ret.push_str(&format!(
@ -62,6 +62,6 @@ pub fn write_compile_commands(filename: &str, content: &[u8]) -> std::io::Result
.open(filename)?;
let mut writer = BufWriter::new(file);
writer.write(content)?;
writer.write_all(content)?;
Ok(())
}

View file

@ -55,7 +55,7 @@ build {0}: regen_ninjafile {1} || $builddir/compile_commands.json
}
fn gen_ninja_target(name: &str, target: &Target) -> Result<String> {
if target.sources.len() == 0 {
if target.sources.is_empty() {
return Err(Error {
kind: ErrorKind::NoSources,
message: format!("target `{}` has no sources", name),
@ -124,7 +124,7 @@ build $builddir/{name}/dep: mkdir
let mut object_list: Vec<String> = Vec::new();
for source in &target.sources {
let new_file = source.replace("/", "-");
let new_file = source.replace('/', "-");
let obj_name = format!("$builddir/{}/obj/{}.o", name, new_file);
let dep_name = format!("$builddir/{}/dep/{}.o.d", name, new_file);
ret.push_str(&format!(
@ -157,7 +157,7 @@ pub fn create_ninja_file_content(
args: &Args,
) -> Result<String> {
let mut ret = String::new();
ret.push_str(&gen_ninja_header(&config, &args)?);
ret.push_str(&gen_ninja_header(config, args)?);
for (name, target) in &target_list.0 {
let content = gen_ninja_target(name, target);
match content {
@ -182,6 +182,6 @@ pub fn write_ninja_file(filename: &str, content: &[u8]) -> std::io::Result<()> {
.open(filename)?;
let mut writer = BufWriter::new(file);
writer.write(content)?;
writer.write_all(content)?;
Ok(())
}

View file

@ -55,19 +55,18 @@ fn main() {
let mut target_list: TargetList = TargetList(HashMap::new());
for order in &inheritance_order {
for name in order.into_iter().rev() {
if let Some(_) = target_list.0.get(name as &str) {
for name in order.iter().rev() {
if target_list.0.get(name as &str).is_some() {
continue;
}
let opts = target_option_list.0.get(name as &str).unwrap();
let deser = deser_target_list.get(name as &str).unwrap();
let parent: Option<&Target>;
if opts.inherit && (name != opts.inherit_from) {
parent = Some(target_list.0.get(opts.inherit_from as &str).unwrap());
let parent: Option<&Target> = if opts.inherit && (name != opts.inherit_from) {
Some(target_list.0.get(opts.inherit_from as &str).unwrap())
} else {
parent = None;
}
None
};
target_list.0.insert(name, Target::new(opts, deser, parent));
}

View file

@ -75,7 +75,7 @@ impl<'a> TargetOptionList<'a> {
match self.0.get(dep) {
Some(v) => {
dep_chain.insert(name, dep);
if let Some(_) = dep_chain.get(dep) {
if dep_chain.get(dep).is_some() {
return Err(Error {
kind: ErrorKind::DependencyCycle,
message: format!(
@ -122,7 +122,7 @@ impl<'a> TargetOptionList<'a> {
match self.0.get(inherit) {
Some(v) => {
dep_chain.insert(name, inherit);
if let Some(_) = dep_chain.get(inherit) {
if dep_chain.get(inherit).is_some() {
return Err(Error {
kind: ErrorKind::InheritanceCycle,
message: format!(