diff --git a/src/content_generation/compile_commands.rs b/src/content_generation/compile_commands.rs index 65b3383..076e6b3 100644 --- a/src/content_generation/compile_commands.rs +++ b/src/content_generation/compile_commands.rs @@ -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(()) } diff --git a/src/content_generation/ninja_file.rs b/src/content_generation/ninja_file.rs index 4c4229d..edd622e 100644 --- a/src/content_generation/ninja_file.rs +++ b/src/content_generation/ninja_file.rs @@ -55,7 +55,7 @@ build {0}: regen_ninjafile {1} || $builddir/compile_commands.json } fn gen_ninja_target(name: &str, target: &Target) -> Result { - 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 = 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 { 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(()) } diff --git a/src/main.rs b/src/main.rs index f6ed841..76c91ff 100644 --- a/src/main.rs +++ b/src/main.rs @@ -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)); } diff --git a/src/validation.rs b/src/validation.rs index 9a1755d..ab240d9 100644 --- a/src/validation.rs +++ b/src/validation.rs @@ -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!(