From 88d0e6b7896eb2b11f664a95fa96500ef0d8dbe8 Mon Sep 17 00:00:00 2001 From: Luke Street Date: Sun, 1 Jun 2025 16:42:00 -0600 Subject: [PATCH] cargo clippy --fix --- src/analysis/cfa.rs | 8 +++--- src/analysis/mod.rs | 3 +-- src/analysis/pass.rs | 2 +- src/analysis/slices.rs | 2 +- src/analysis/tracker.rs | 4 +-- src/cmd/ar.rs | 10 +++---- src/cmd/dol.rs | 40 ++++++++++++++-------------- src/cmd/dwarf.rs | 21 +++++++-------- src/cmd/elf.rs | 12 ++++----- src/cmd/map.rs | 2 +- src/cmd/nlzss.rs | 2 +- src/cmd/rel.rs | 4 +-- src/cmd/rso.rs | 2 +- src/cmd/shasum.rs | 5 ++-- src/cmd/vfs.rs | 42 ++++++++++++++--------------- src/cmd/yay0.rs | 6 ++--- src/cmd/yaz0.rs | 6 ++--- src/obj/symbols.rs | 4 +-- src/util/alf.rs | 2 +- src/util/asm.rs | 18 ++++++------- src/util/bin2c.rs | 4 +-- src/util/comment.rs | 12 ++++----- src/util/config.rs | 14 +++++----- src/util/diff.rs | 2 +- src/util/dol.rs | 6 ++--- src/util/dwarf.rs | 58 ++++++++++++++++++++--------------------- src/util/elf.rs | 2 +- src/util/file.rs | 2 +- src/util/lcf.rs | 6 ++--- src/util/rarc.rs | 2 +- src/util/rel.rs | 6 ++--- src/util/rso.rs | 8 +++--- src/util/split.rs | 4 +-- src/vfs/disc.rs | 2 +- src/vfs/mod.rs | 37 +++++++++++++------------- src/vfs/wad.rs | 8 +++--- 36 files changed, 181 insertions(+), 187 deletions(-) diff --git a/src/analysis/cfa.rs b/src/analysis/cfa.rs index 0646cba..1911864 100644 --- a/src/analysis/cfa.rs +++ b/src/analysis/cfa.rs @@ -191,7 +191,7 @@ impl AnalyzerState { }; obj.add_symbol( ObjSymbol { - name: format!("jumptable_{}", address_str), + name: format!("jumptable_{address_str}"), address: addr.address as u64, section: Some(addr.section), size: size as u64, @@ -275,7 +275,7 @@ impl AnalyzerState { let (section_index, _) = obj .sections .at_address(entry) - .context(format!("Entry point {:#010X} outside of any section", entry))?; + .context(format!("Entry point {entry:#010X} outside of any section"))?; self.process_function_at(obj, SectionAddress::new(section_index, entry))?; } // Locate bounds for referenced functions until none are left @@ -530,7 +530,7 @@ pub fn locate_sda_bases(obj: &mut ObjInfo) -> Result { let (section_index, _) = obj .sections .at_address(entry as u32) - .context(format!("Entry point {:#010X} outside of any section", entry))?; + .context(format!("Entry point {entry:#010X} outside of any section"))?; let entry_addr = SectionAddress::new(section_index, entry as u32); let mut executor = Executor::new(obj); @@ -589,7 +589,7 @@ pub fn locate_bss_memsets(obj: &mut ObjInfo) -> Result> { let (section_index, _) = obj .sections .at_address(entry as u32) - .context(format!("Entry point {:#010X} outside of any section", entry))?; + .context(format!("Entry point {entry:#010X} outside of any section"))?; let entry_addr = SectionAddress::new(section_index, entry as u32); let mut executor = Executor::new(obj); diff --git a/src/analysis/mod.rs b/src/analysis/mod.rs index 2ea8c9a..00616b5 100644 --- a/src/analysis/mod.rs +++ b/src/analysis/mod.rs @@ -183,8 +183,7 @@ fn get_jump_table_entries( let (section_index, _) = obj.sections.at_address(entry_addr).with_context(|| { format!( - "Invalid jump table entry {:#010X} at {:#010X}", - entry_addr, cur_addr + "Invalid jump table entry {entry_addr:#010X} at {cur_addr:#010X}" ) })?; entries.push(SectionAddress::new(section_index, entry_addr)); diff --git a/src/analysis/pass.rs b/src/analysis/pass.rs index 6c53bfb..e67d4de 100644 --- a/src/analysis/pass.rs +++ b/src/analysis/pass.rs @@ -101,7 +101,7 @@ impl AnalysisPass for FindSaveRestSleds { for i in reg_start..reg_end { let addr = start + (i - reg_start) * step_size; state.known_symbols.entry(addr).or_default().push(ObjSymbol { - name: format!("{}{}", label, i), + name: format!("{label}{i}"), address: addr.address as u64, section: Some(start.section), size_known: true, diff --git a/src/analysis/slices.rs b/src/analysis/slices.rs index 68824a8..70685ed 100644 --- a/src/analysis/slices.rs +++ b/src/analysis/slices.rs @@ -227,7 +227,7 @@ impl FunctionSlices { })?; } self.check_epilogue(section, ins_addr, ins) - .with_context(|| format!("While processing {:#010X}: {:#?}", function_start, self))?; + .with_context(|| format!("While processing {function_start:#010X}: {self:#?}"))?; if !self.has_conditional_blr && is_conditional_blr(ins) { self.has_conditional_blr = true; } diff --git a/src/analysis/tracker.rs b/src/analysis/tracker.rs index e73bfbb..3226565 100644 --- a/src/analysis/tracker.rs +++ b/src/analysis/tracker.rs @@ -576,7 +576,7 @@ impl Tracker { let relocation_target = relocation_target_for(obj, from, None).ok().flatten(); if !matches!(relocation_target, None | Some(RelocationTarget::External)) { // VM should have already handled this - panic!("Relocation already exists for {:#010X} (from {:#010X})", addr, from); + panic!("Relocation already exists for {addr:#010X} (from {from:#010X})"); } } // Remainder of this function is for executable objects only @@ -668,7 +668,7 @@ impl Tracker { 0 }; let new_name = - if module_id == 0 { name.to_string() } else { format!("{}:{}", name, module_id) }; + if module_id == 0 { name.to_string() } else { format!("{name}:{module_id}") }; log::debug!("Renaming {} to {}", section.name, new_name); section.name = new_name; } diff --git a/src/cmd/ar.rs b/src/cmd/ar.rs index 351d65a..42565de 100644 --- a/src/cmd/ar.rs +++ b/src/cmd/ar.rs @@ -127,16 +127,16 @@ fn extract(args: ExtractArgs) -> Result<()> { } std::fs::create_dir_all(&out_dir)?; if !args.quiet { - println!("Extracting {} to {}", path, out_dir); + println!("Extracting {path} to {out_dir}"); } let mut file = open_file(path, false)?; let mut archive = ar::Archive::new(file.map()?); while let Some(entry) = archive.next_entry() { - let mut entry = entry.with_context(|| format!("Processing entry in {}", path))?; + let mut entry = entry.with_context(|| format!("Processing entry in {path}"))?; let file_name = std::str::from_utf8(entry.header().identifier())?; if !args.quiet && args.verbose { - println!("\t{}", file_name); + println!("\t{file_name}"); } let mut file_path = out_dir.clone(); for segment in file_name.split(&['/', '\\']) { @@ -146,7 +146,7 @@ fn extract(args: ExtractArgs) -> Result<()> { std::fs::create_dir_all(parent)?; } let mut file = File::create(&file_path) - .with_context(|| format!("Failed to create file {}", file_path))?; + .with_context(|| format!("Failed to create file {file_path}"))?; std::io::copy(&mut entry, &mut file)?; file.flush()?; @@ -154,7 +154,7 @@ fn extract(args: ExtractArgs) -> Result<()> { } } if !args.quiet { - println!("Extracted {} files", num_files); + println!("Extracted {num_files} files"); } Ok(()) } diff --git a/src/cmd/dol.rs b/src/cmd/dol.rs index 9614d66..eccd7ec 100644 --- a/src/cmd/dol.rs +++ b/src/cmd/dol.rs @@ -536,7 +536,7 @@ pub fn info(args: InfoArgs) -> Result<()> { println!("{}:", obj.name); if let Some(entry) = obj.entry { - println!("Entry point: {:#010X}", entry); + println!("Entry point: {entry:#010X}"); } println!("\nSections:"); println!("\t{: >10} | {: <10} | {: <10} | {: <10}", "Name", "Address", "Size", "File Off"); @@ -955,7 +955,7 @@ fn split_write_obj( DirBuilder::new() .recursive(true) .create(out_dir) - .with_context(|| format!("Failed to create out dir '{}'", out_dir))?; + .with_context(|| format!("Failed to create out dir '{out_dir}'"))?; let obj_dir = out_dir.join("obj"); let entry = if module.obj.kind == ObjKind::Executable { module.obj.entry.and_then(|e| { @@ -1056,9 +1056,8 @@ fn split_write_obj( // Generate ldscript.lcf let ldscript_template = if let Some(template_path) = &module.config.ldscript_template { let template_path = template_path.with_encoding(); - let template = fs::read_to_string(&template_path).with_context(|| { - format!("Failed to read linker script template '{}'", template_path) - })?; + let template = fs::read_to_string(&template_path) + .with_context(|| format!("Failed to read linker script template '{template_path}'"))?; module.dep.push(template_path); Some(template) } else { @@ -1076,8 +1075,7 @@ fn split_write_obj( let out_path = asm_dir.join(asm_path_for_unit(&unit.name)); let mut w = buf_writer(&out_path)?; - write_asm(&mut w, split_obj) - .with_context(|| format!("Failed to write {}", out_path))?; + write_asm(&mut w, split_obj).with_context(|| format!("Failed to write {out_path}"))?; w.flush()?; } } @@ -1094,7 +1092,7 @@ fn write_if_changed(path: &Utf8NativePath, contents: &[u8]) -> Result<()> { return Ok(()); } } - fs::write(path, contents).with_context(|| format!("Failed to write file '{}'", path))?; + fs::write(path, contents).with_context(|| format!("Failed to write file '{path}'"))?; Ok(()) } @@ -2166,7 +2164,7 @@ impl ObjectBase { } base.join(path.with_encoding()) } - ObjectBase::Vfs(base, _) => Utf8NativePathBuf::from(format!("{}:{}", base, path)), + ObjectBase::Vfs(base, _) => Utf8NativePathBuf::from(format!("{base}:{path}")), } } @@ -2183,7 +2181,7 @@ impl ObjectBase { } ObjectBase::Vfs(vfs_path, vfs) => { open_file_with_fs(vfs.clone(), &path.with_encoding(), true) - .with_context(|| format!("Using disc image {}", vfs_path)) + .with_context(|| format!("Using disc image {vfs_path}")) } } } @@ -2201,18 +2199,18 @@ pub fn find_object_base(config: &ProjectConfig) -> Result { if let Some(base) = &config.object_base { let base = base.with_encoding(); // Search for disc images in the object base directory - for result in fs::read_dir(&base).with_context(|| format!("Reading directory {}", base))? { - let entry = result.with_context(|| format!("Reading entry in directory {}", base))?; + for result in fs::read_dir(&base).with_context(|| format!("Reading directory {base}"))? { + let entry = result.with_context(|| format!("Reading entry in directory {base}"))?; let Ok(path) = check_path_buf(entry.path()) else { log::warn!("Path is not valid UTF-8: {:?}", entry.path()); continue; }; let file_type = - entry.file_type().with_context(|| format!("Getting file type for {}", path))?; + entry.file_type().with_context(|| format!("Getting file type for {path}"))?; let is_file = if file_type.is_symlink() { // Also traverse symlinks to files fs::metadata(&path) - .with_context(|| format!("Getting metadata for {}", path))? + .with_context(|| format!("Getting metadata for {path}"))? .is_file() } else { file_type.is_file() @@ -2220,7 +2218,7 @@ pub fn find_object_base(config: &ProjectConfig) -> Result { if is_file { let mut file = open_file(&path, false)?; let format = detect(file.as_mut()) - .with_context(|| format!("Detecting file type for {}", path))?; + .with_context(|| format!("Detecting file type for {path}"))?; match format { FileFormat::Archive(ArchiveKind::Disc(format)) => { let fs = open_fs(file, ArchiveKind::Disc(format))?; @@ -2249,7 +2247,7 @@ fn extract_objects(config: &ProjectConfig, object_base: &ObjectBase) -> Result Result Result Result Result<()> { // TODO make a basename method let name = name.trim_start_matches("D:").replace('\\', "/"); let name = name.rsplit_once('/').map(|(_, b)| b).unwrap_or(&name); - let file_path = out_path.join(format!("{}.txt", name)); + let file_path = out_path.join(format!("{name}.txt")); let mut file = buf_writer(&file_path)?; dump_debug_section(&args, &mut file, &obj_file, debug_section)?; file.flush()?; } else if args.no_color { - println!("\n// File {}:", name); + println!("\n// File {name}:"); dump_debug_section(&args, &mut stdout(), &obj_file, debug_section)?; } else { let mut writer = HighlightWriter::new(syntax_set.clone(), syntax.clone(), theme); - writeln!(writer, "\n// File {}:", name)?; + writeln!(writer, "\n// File {name}:")?; dump_debug_section(&args, &mut writer, &obj_file, debug_section)?; } } @@ -209,26 +209,25 @@ where } writeln!(w, "\n/*\n Compile unit: {}", unit.name)?; if let Some(producer) = unit.producer { - writeln!(w, " Producer: {}", producer)?; + writeln!(w, " Producer: {producer}")?; } if let Some(comp_dir) = unit.comp_dir { - writeln!(w, " Compile directory: {}", comp_dir)?; + writeln!(w, " Compile directory: {comp_dir}")?; } if let Some(language) = unit.language { - writeln!(w, " Language: {}", language)?; + writeln!(w, " Language: {language}")?; } if let (Some(start), Some(end)) = (unit.start_address, unit.end_address) { - writeln!(w, " Code range: {:#010X} -> {:#010X}", start, end)?; + writeln!(w, " Code range: {start:#010X} -> {end:#010X}")?; } if let Some(gcc_srcfile_name_offset) = unit.gcc_srcfile_name_offset { writeln!( w, - " GCC Source File Name Offset: {:#010X}", - gcc_srcfile_name_offset + " GCC Source File Name Offset: {gcc_srcfile_name_offset:#010X}" )?; } if let Some(gcc_srcinfo_offset) = unit.gcc_srcinfo_offset { - writeln!(w, " GCC Source Info Offset: {:#010X}", gcc_srcinfo_offset)?; + writeln!(w, " GCC Source Info Offset: {gcc_srcinfo_offset:#010X}")?; } writeln!(w, "*/")?; @@ -269,7 +268,7 @@ where continue; } match tag_type_string(&info, &typedefs, &tag_type, child.is_erased) { - Ok(s) => writeln!(w, "{}", s)?, + Ok(s) => writeln!(w, "{s}")?, Err(e) => { log::error!( "Failed to emit tag {:X} (unit {}): {}", diff --git a/src/cmd/elf.rs b/src/cmd/elf.rs index d1903fd..65ed99e 100644 --- a/src/cmd/elf.rs +++ b/src/cmd/elf.rs @@ -146,14 +146,14 @@ fn disasm(args: DisasmArgs) -> Result<()> { let mut files_out = buf_writer(&args.out.join("link_order.txt"))?; for (unit, split_obj) in obj.link_order.iter().zip(&split_objs) { let out_name = file_stem_from_unit(&unit.name); - let out_path = asm_dir.join(format!("{}.s", out_name)); + let out_path = asm_dir.join(format!("{out_name}.s")); log::info!("Writing {}", out_path); let mut w = buf_writer(&out_path)?; write_asm(&mut w, split_obj)?; w.flush()?; - writeln!(files_out, "{}.o", out_name)?; + writeln!(files_out, "{out_name}.o")?; } files_out.flush()?; } @@ -402,7 +402,7 @@ fn signatures(args: SignaturesArgs) -> Result<()> { Ok(Some(signature)) => signature, Ok(None) => continue, Err(e) => { - eprintln!("Failed: {:?}", e); + eprintln!("Failed: {e:?}"); continue; } }; @@ -545,13 +545,13 @@ fn info(args: InfoArgs) -> Result<()> { .context("While reading .note.split section")?; println!("\nSplit metadata (.note.split):"); if let Some(generator) = &meta.generator { - println!("\tGenerator: {}", generator); + println!("\tGenerator: {generator}"); } if let Some(module_name) = &meta.module_name { - println!("\tModule name: {}", module_name); + println!("\tModule name: {module_name}"); } if let Some(module_id) = meta.module_id { - println!("\tModule ID: {}", module_id); + println!("\tModule ID: {module_id}"); } if let Some(virtual_addresses) = &meta.virtual_addresses { println!("\tVirtual addresses:"); diff --git a/src/cmd/map.rs b/src/cmd/map.rs index 8d89230..43ee2c8 100644 --- a/src/cmd/map.rs +++ b/src/cmd/map.rs @@ -175,7 +175,7 @@ fn symbol(args: SymbolArgs) -> Result<()> { if let Some(vec) = entries.unit_references.get_vec(&symbol_ref) { println!("\nGenerated in TUs:"); for x in vec { - println!(">>> {}", x); + println!(">>> {x}"); } } println!("\n"); diff --git a/src/cmd/nlzss.rs b/src/cmd/nlzss.rs index c53b9f4..906b0d2 100644 --- a/src/cmd/nlzss.rs +++ b/src/cmd/nlzss.rs @@ -59,7 +59,7 @@ fn decompress(args: DecompressArgs) -> Result<()> { path.as_path().to_cow() }; fs::write(out_path.as_ref(), data) - .with_context(|| format!("Failed to write '{}'", out_path))?; + .with_context(|| format!("Failed to write '{out_path}'"))?; } Ok(()) } diff --git a/src/cmd/rel.rs b/src/cmd/rel.rs index e7536fc..8e1cb09 100644 --- a/src/cmd/rel.rs +++ b/src/cmd/rel.rs @@ -316,7 +316,7 @@ fn make(args: MakeArgs) -> Result<()> { .unwrap_or(idx as u32); load_obj(file.map()?) .map(|o| LoadedModule { module_id, file: o, path: path.clone() }) - .with_context(|| format!("Failed to load '{}'", path)) + .with_context(|| format!("Failed to load '{path}'")) }) .collect::>>()?; @@ -395,7 +395,7 @@ fn make(args: MakeArgs) -> Result<()> { let rel_path = module_info.path.with_extension("rel"); let mut w = buf_writer(&rel_path)?; write_rel(&mut w, &info, &module_info.file, relocations) - .with_context(|| format!("Failed to write '{}'", rel_path))?; + .with_context(|| format!("Failed to write '{rel_path}'"))?; w.flush()?; } diff --git a/src/cmd/rso.rs b/src/cmd/rso.rs index cebe223..d8952ec 100644 --- a/src/cmd/rso.rs +++ b/src/cmd/rso.rs @@ -143,7 +143,7 @@ fn make_rso( let si = sym .section_index() - .with_context(|| format!("Failed to find symbol `{}` section index", name))?; + .with_context(|| format!("Failed to find symbol `{name}` section index"))?; let addr = sym.address(); *index = si.0 as u8; diff --git a/src/cmd/shasum.rs b/src/cmd/shasum.rs index fd3fb66..120cd90 100644 --- a/src/cmd/shasum.rs +++ b/src/cmd/shasum.rs @@ -45,14 +45,13 @@ pub fn run(args: Args) -> Result<()> { check(&args, file.as_mut())?; } if let Some(out_path) = &args.output { - touch(out_path) - .with_context(|| format!("Failed to touch output file '{}'", out_path))?; + touch(out_path).with_context(|| format!("Failed to touch output file '{out_path}'"))?; } } else { let mut w: Box = if let Some(out_path) = &args.output { Box::new( buf_writer(out_path) - .with_context(|| format!("Failed to open output file '{}'", out_path))?, + .with_context(|| format!("Failed to open output file '{out_path}'"))?, ) } else { Box::new(stdout()) diff --git a/src/cmd/vfs.rs b/src/cmd/vfs.rs index c3ac34b..1a990e6 100644 --- a/src/cmd/vfs.rs +++ b/src/cmd/vfs.rs @@ -85,7 +85,7 @@ fn file_info( metadata: &VfsMetadata, ) -> anyhow::Result> { let format = - detect(file).with_context(|| format!("Failed to detect file format for {}", filename))?; + detect(file).with_context(|| format!("Failed to detect file format for {filename}"))?; let mut info: Columns<5> = [ Size::from_bytes(metadata.len).to_string(), filename.to_string(), @@ -97,9 +97,9 @@ fn file_info( let mut decompressed = decompress_file(file, kind)?; let metadata = decompressed .metadata() - .with_context(|| format!("Failed to fetch metadata for {}", filename))?; + .with_context(|| format!("Failed to fetch metadata for {filename}"))?; let format = detect(decompressed.as_mut()) - .with_context(|| format!("Failed to detect file format for {}", filename))?; + .with_context(|| format!("Failed to detect file format for {filename}"))?; info[3] = format!("Decompressed: {}", Size::from_bytes(metadata.len)); info[4] = format.to_string(); } @@ -112,11 +112,11 @@ pub fn ls(args: LsArgs) -> anyhow::Result<()> { OpenResult::File(mut file, path) => { let filename = path.file_name().ok_or_else(|| anyhow!("Path has no filename"))?; if args.short { - println!("{}", filename); + println!("{filename}"); } else { let metadata = file .metadata() - .with_context(|| format!("Failed to fetch metadata for {}", path))?; + .with_context(|| format!("Failed to fetch metadata for {path}"))?; files.push(file_info(filename, file.as_mut(), &metadata)?); } } @@ -131,10 +131,10 @@ pub fn ls(args: LsArgs) -> anyhow::Result<()> { for (i, column) in entry.iter().enumerate() { if widths[i] > 0 { if written > 0 { - print!("{}", SEPARATOR); + print!("{SEPARATOR}"); } written += 1; - print!("{}", column); + print!("{column}"); let remain = widths[i].saturating_sub(column.width_cjk()); if remain > 0 { print!("{:width$}", "", width = remain); @@ -161,25 +161,25 @@ fn ls_directory( let display_path = base_filename.join(&filename); let metadata = fs .metadata(&entry_path) - .with_context(|| format!("Failed to fetch metadata for {}", entry_path))?; + .with_context(|| format!("Failed to fetch metadata for {entry_path}"))?; match metadata.file_type { VfsFileType::File => { let mut file = fs .open(&entry_path) - .with_context(|| format!("Failed to open file {}", entry_path))?; + .with_context(|| format!("Failed to open file {entry_path}"))?; if args.short { - println!("{}", display_path); + println!("{display_path}"); } else { files.push(file_info(display_path.as_str(), file.as_mut(), &metadata)?); } } VfsFileType::Directory => { if args.short { - println!("{}/", display_path); + println!("{display_path}/"); } else { files.push([ " ".to_string(), - format!("{}/", display_path), + format!("{display_path}/"), "Directory".to_string(), String::new(), String::new(), @@ -206,7 +206,7 @@ pub fn cp(mut args: CpArgs) -> anyhow::Result<()> { OpenResult::File(file, path) => { let dest = if dest_is_dir { fs::create_dir_all(&dest) - .with_context(|| format!("Failed to create directory {}", dest))?; + .with_context(|| format!("Failed to create directory {dest}"))?; let filename = path.file_name().ok_or_else(|| anyhow!("Path has no filename"))?; dest.join(filename) @@ -234,12 +234,12 @@ fn cp_file( if let FileFormat::Compressed(kind) = detect(file.as_mut())? { if auto_decompress { file = decompress_file(file.as_mut(), kind) - .with_context(|| format!("Failed to decompress file {}", dest))?; + .with_context(|| format!("Failed to decompress file {dest}"))?; compression = Some(kind); } } let metadata = - file.metadata().with_context(|| format!("Failed to fetch metadata for {}", dest))?; + file.metadata().with_context(|| format!("Failed to fetch metadata for {dest}"))?; if !quiet { if let Some(kind) = compression { println!( @@ -254,10 +254,10 @@ fn cp_file( } } let mut dest_file = - File::create(dest).with_context(|| format!("Failed to create file {}", dest))?; + File::create(dest).with_context(|| format!("Failed to create file {dest}"))?; buf_copy(file.as_mut(), &mut dest_file) - .with_context(|| format!("Failed to copy file {}", dest))?; - dest_file.flush().with_context(|| format!("Failed to flush file {}", dest))?; + .with_context(|| format!("Failed to copy file {dest}"))?; + dest_file.flush().with_context(|| format!("Failed to flush file {dest}"))?; Ok(()) } @@ -268,18 +268,18 @@ fn cp_recursive( auto_decompress: bool, quiet: bool, ) -> anyhow::Result<()> { - fs::create_dir_all(dest).with_context(|| format!("Failed to create directory {}", dest))?; + fs::create_dir_all(dest).with_context(|| format!("Failed to create directory {dest}"))?; let entries = fs.read_dir(path)?; for filename in entries { let entry_path = path.join(&filename); let metadata = fs .metadata(&entry_path) - .with_context(|| format!("Failed to fetch metadata for {}", entry_path))?; + .with_context(|| format!("Failed to fetch metadata for {entry_path}"))?; match metadata.file_type { VfsFileType::File => { let file = fs .open(&entry_path) - .with_context(|| format!("Failed to open file {}", entry_path))?; + .with_context(|| format!("Failed to open file {entry_path}"))?; cp_file(file, &entry_path, &dest.join(filename), auto_decompress, quiet)?; } VfsFileType::Directory => { diff --git a/src/cmd/yay0.rs b/src/cmd/yay0.rs index 22cf9d2..91baeaf 100644 --- a/src/cmd/yay0.rs +++ b/src/cmd/yay0.rs @@ -80,7 +80,7 @@ fn compress(args: CompressArgs) -> Result<()> { path.as_path().to_cow() }; fs::write(out_path.as_ref(), data) - .with_context(|| format!("Failed to write '{}'", out_path))?; + .with_context(|| format!("Failed to write '{out_path}'"))?; } Ok(()) } @@ -92,7 +92,7 @@ fn decompress(args: DecompressArgs) -> Result<()> { let data = { let mut file = open_file(&path, true)?; decompress_yay0(file.map()?) - .with_context(|| format!("Failed to decompress '{}' using Yay0", path))? + .with_context(|| format!("Failed to decompress '{path}' using Yay0"))? }; let out_path = if let Some(output) = &args.output { if single_file { @@ -104,7 +104,7 @@ fn decompress(args: DecompressArgs) -> Result<()> { path.as_path().to_cow() }; fs::write(out_path.as_ref(), data) - .with_context(|| format!("Failed to write '{}'", out_path))?; + .with_context(|| format!("Failed to write '{out_path}'"))?; } Ok(()) } diff --git a/src/cmd/yaz0.rs b/src/cmd/yaz0.rs index 107f542..b86904d 100644 --- a/src/cmd/yaz0.rs +++ b/src/cmd/yaz0.rs @@ -80,7 +80,7 @@ fn compress(args: CompressArgs) -> Result<()> { path.as_path().to_cow() }; fs::write(out_path.as_ref(), data) - .with_context(|| format!("Failed to write '{}'", out_path))?; + .with_context(|| format!("Failed to write '{out_path}'"))?; } Ok(()) } @@ -92,7 +92,7 @@ fn decompress(args: DecompressArgs) -> Result<()> { let data = { let mut file = open_file(&path, false)?; decompress_yaz0(file.map()?) - .with_context(|| format!("Failed to decompress '{}' using Yaz0", path))? + .with_context(|| format!("Failed to decompress '{path}' using Yaz0"))? }; let out_path = if let Some(output) = &args.output { if single_file { @@ -104,7 +104,7 @@ fn decompress(args: DecompressArgs) -> Result<()> { path.as_path().to_cow() }; fs::write(out_path.as_ref(), data) - .with_context(|| format!("Failed to write '{}'", out_path))?; + .with_context(|| format!("Failed to write '{out_path}'"))?; } Ok(()) } diff --git a/src/obj/symbols.rs b/src/obj/symbols.rs index 56659b3..0bd0b89 100644 --- a/src/obj/symbols.rs +++ b/src/obj/symbols.rs @@ -403,7 +403,7 @@ impl ObjSymbols { pub fn iter_ordered(&self) -> impl DoubleEndedIterator { self.symbols_by_section .iter() - .flat_map(|v| v.iter().map(|(_, v)| v)) + .flat_map(|v| v.values()) .flat_map(move |v| v.iter().map(move |u| (*u, &self.symbols[*u as usize]))) } @@ -450,7 +450,7 @@ impl ObjSymbols { self.symbols_by_section .get(section_idx as usize) .into_iter() - .flat_map(|v| v.iter().map(|(_, v)| v)) + .flat_map(|v| v.values()) .flat_map(move |v| v.iter().map(move |u| (*u, &self.symbols[*u as usize]))) } diff --git a/src/util/alf.rs b/src/util/alf.rs index dbac286..35ad2bd 100644 --- a/src/util/alf.rs +++ b/src/util/alf.rs @@ -161,7 +161,7 @@ impl FromReader for AlfSymbolKind { match u32::from_reader(reader, e)? { 0 => Ok(Self::Function), 1 => Ok(Self::Object), - v => Err(Error::new(ErrorKind::InvalidData, format!("invalid ALF symbol kind: {}", v))), + v => Err(Error::new(ErrorKind::InvalidData, format!("invalid ALF symbol kind: {v}"))), } } } diff --git a/src/util/asm.rs b/src/util/asm.rs index 3fe73c5..a10bcca 100644 --- a/src/util/asm.rs +++ b/src/util/asm.rs @@ -442,12 +442,12 @@ where match parse_extab(symbols, entry, section) { Ok(s) => { for line in s.trim_end().lines() { - writeln!(w, " * {}", line)?; + writeln!(w, " * {line}")?; } } Err(e) => { log::warn!("Failed to decode extab entry {}: {}", symbol.name, e); - writeln!(w, " * Failed to decode extab entry: {}", e)?; + writeln!(w, " * Failed to decode extab entry: {e}")?; } } writeln!(w, " */")?; @@ -505,7 +505,7 @@ where } current_symbol_kind = find_symbol_kind(current_symbol_kind, symbols, vec)?; current_data_kind = find_data_kind(current_data_kind, symbols, vec) - .with_context(|| format!("At address {:#010X}", sym_addr))?; + .with_context(|| format!("At address {sym_addr:#010X}"))?; entry = entry_iter.next(); } else if current_address > sym_addr { let dbg_symbols = vec.iter().map(|e| &symbols[e.index as usize]).collect_vec(); @@ -660,8 +660,8 @@ where W: Write + ?Sized { '\x0D' => write!(w, "\\r")?, '\\' => write!(w, "\\\\")?, '"' => write!(w, "\\\"")?, - c if c.is_ascii_graphic() || c.is_ascii_whitespace() => write!(w, "{}", c)?, - _ => write!(w, "\\{:03o}", b)?, + c if c.is_ascii_graphic() || c.is_ascii_whitespace() => write!(w, "{c}")?, + _ => write!(w, "\\{b:03o}")?, } } writeln!(w, "\"")?; @@ -684,13 +684,13 @@ where W: Write + ?Sized { for c in cow.chars() { match c { '#' => write!(w, "\\#")?, - _ => write!(w, "{}", c)?, + _ => write!(w, "{c}")?, } } write!(w, "\n\t.byte ")?; for (i, &b) in data.iter().enumerate() { - write!(w, "0x{:02X}", b)?; + write!(w, "0x{b:02X}")?; if i + 1 != data.len() { write!(w, ", ")?; } @@ -721,7 +721,7 @@ where W: Write + ?Sized { '\x0D' => write!(w, "\\r")?, '\\' => write!(w, "\\\\")?, '"' => write!(w, "\\\"")?, - c if c.is_ascii_graphic() || c.is_ascii_whitespace() => write!(w, "{}", c)?, + c if c.is_ascii_graphic() || c.is_ascii_whitespace() => write!(w, "{c}")?, _ => write!(w, "\\{:#X}", c as u32)?, } } @@ -793,7 +793,7 @@ where W: Write + ?Sized { }; for chunk in remain.chunks(chunk_size) { if data_kind == ObjDataKind::Byte || matches!(chunk.len(), 1 | 3 | 5..=7) { - let bytes = chunk.iter().map(|c| format!("{:#04X}", c)).collect::>(); + let bytes = chunk.iter().map(|c| format!("{c:#04X}")).collect::>(); writeln!(w, "\t.byte {}", bytes.join(", "))?; } else { match chunk.len() { diff --git a/src/util/bin2c.rs b/src/util/bin2c.rs index ce5cea7..9e66808 100644 --- a/src/util/bin2c.rs +++ b/src/util/bin2c.rs @@ -95,7 +95,7 @@ fn bin2c_symbol( } else { output.push(' '); } - output.push_str(&format!("0x{:02X},", byte)); + output.push_str(&format!("0x{byte:02X},")); } output.push_str("\n};\n"); output @@ -111,7 +111,7 @@ fn bin2c_raw(data: &[u8]) -> String { output.push(' '); } } - output.push_str(&format!("0x{:02X},", byte)); + output.push_str(&format!("0x{byte:02X},")); } output.push('\n'); output diff --git a/src/util/comment.rs b/src/util/comment.rs index 7be6312..a48ba5a 100644 --- a/src/util/comment.rs +++ b/src/util/comment.rs @@ -58,7 +58,7 @@ impl FromReader for MWComment { if magic != MAGIC { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Invalid .comment section magic: {:?}", magic), + format!("Invalid .comment section magic: {magic:?}"), )); } // 0xB @@ -78,7 +78,7 @@ impl FromReader for MWComment { value => { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Invalid value for pool_data: {}", value), + format!("Invalid value for pool_data: {value}"), )) } }; @@ -93,7 +93,7 @@ impl FromReader for MWComment { v => { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Expected header size {:#X}, got {:#X}", HEADER_SIZE, v), + format!("Expected header size {HEADER_SIZE:#X}, got {v:#X}"), )) } } @@ -102,7 +102,7 @@ impl FromReader for MWComment { if flags & !7 != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Unexpected flag value {:#X}", flags), + format!("Unexpected flag value {flags:#X}"), )); } if flags & 1 == 1 { @@ -221,14 +221,14 @@ impl FromReader for CommentSym { if value != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Unexpected value after active_flags (1): {:#X}", value), + format!("Unexpected value after active_flags (1): {value:#X}"), )); } let value = u8::from_reader(reader, e)?; if value != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Unexpected value after active_flags (2): {:#X}", value), + format!("Unexpected value after active_flags (2): {value:#X}"), )); } Ok(out) diff --git a/src/util/config.rs b/src/util/config.rs index 743a8ee..32a3df6 100644 --- a/src/util/config.rs +++ b/src/util/config.rs @@ -282,11 +282,11 @@ where W: Write + ?Sized { write!(w, " data:{kind}")?; } if let Some(hash) = symbol.name_hash { - write!(w, " hash:{:#010X}", hash)?; + write!(w, " hash:{hash:#010X}")?; } if let Some(hash) = symbol.demangled_name_hash { if symbol.name_hash != symbol.demangled_name_hash { - write!(w, " dhash:{:#010X}", hash)?; + write!(w, " dhash:{hash:#010X}")?; } } if symbol.flags.is_hidden() { @@ -439,10 +439,10 @@ where W: Write + ?Sized { for unit in obj.link_order.iter().filter(|unit| all || !unit.autogenerated) { write!(w, "\n{}:", unit.name)?; if let Some(comment_version) = unit.comment_version { - write!(w, " comment:{}", comment_version)?; + write!(w, " comment:{comment_version}")?; } if let Some(order) = unit.order { - write!(w, " order:{}", order)?; + write!(w, " order:{order}")?; } writeln!(w)?; let mut split_iter = obj.sections.all_splits().peekable(); @@ -458,14 +458,14 @@ where W: Write + ?Sized { write!(w, "\t{:<11} start:{:#010X} end:{:#010X}", section.name, addr, end)?; if let Some(align) = split.align { if align != default_section_align(section) as u32 { - write!(w, " align:{}", align)?; + write!(w, " align:{align}")?; } } if split.common { write!(w, " common")?; } if let Some(name) = &split.rename { - write!(w, " rename:{}", name)?; + write!(w, " rename:{name}")?; } if split.skip { write!(w, " skip")?; @@ -783,7 +783,7 @@ pub mod signed_hex_serde { if *value < 0 { serializer.serialize_str(&format!("-{:#X}", -value)) } else { - serializer.serialize_str(&format!("{:#X}", value)) + serializer.serialize_str(&format!("{value:#X}")) } } diff --git a/src/util/diff.rs b/src/util/diff.rs index cd1fec6..cc5c2b1 100644 --- a/src/util/diff.rs +++ b/src/util/diff.rs @@ -209,7 +209,7 @@ fn print_line(ins_diff: &ObjInsDiff, base_addr: u64) -> Vec { pad_to = 5; } DiffText::Address(addr) => { - label_text = format!("{:x}:", addr); + label_text = format!("{addr:x}:"); pad_to = 5; } DiffText::Opcode(mnemonic, _op) => { diff --git a/src/util/dol.rs b/src/util/dol.rs index a6511c7..7fd9d86 100644 --- a/src/util/dol.rs +++ b/src/util/dol.rs @@ -398,7 +398,7 @@ pub fn process_dol(buf: &[u8], name: &str) -> Result { idx => match dol_section.kind { DolSectionKind::Text => (format!(".text{idx}"), ObjSectionKind::Code, false), DolSectionKind::Data => (format!(".data{idx}"), ObjSectionKind::Data, false), - DolSectionKind::Bss => (format!(".bss{}", idx), ObjSectionKind::Bss, false), + DolSectionKind::Bss => (format!(".bss{idx}"), ObjSectionKind::Bss, false), }, }; @@ -453,7 +453,7 @@ pub fn process_dol(buf: &[u8], name: &str) -> Result { ); sections.push(ObjSection { - name: format!(".bss{}", idx), + name: format!(".bss{idx}"), kind: ObjSectionKind::Bss, address: addr as u64, size: size as u64, @@ -699,7 +699,7 @@ pub fn process_dol(buf: &[u8], name: &str) -> Result { }; obj.add_symbol( ObjSymbol { - name: format!("@etb_{:08X}", addr), + name: format!("@etb_{addr:08X}"), address: addr as u64, section: Some(extab_section_index), size: size as u64, diff --git a/src/util/dwarf.rs b/src/util/dwarf.rs index 9896f1d..69d6b85 100644 --- a/src/util/dwarf.rs +++ b/src/util/dwarf.rs @@ -1145,8 +1145,8 @@ fn structure_type_string( struct_def_string(info, typedefs, t)? } else if include_keyword { match t.kind { - StructureKind::Struct => format!("struct {}", name), - StructureKind::Class => format!("class {}", name), + StructureKind::Struct => format!("struct {name}"), + StructureKind::Class => format!("class {name}"), } } else { name.clone() @@ -1178,7 +1178,7 @@ fn enumeration_type_string( if name.starts_with('@') { enum_def_string(t)? } else if include_keyword { - format!("enum {}", name) + format!("enum {name}") } else { name.clone() } @@ -1203,7 +1203,7 @@ fn union_type_string( if name.starts_with('@') { union_def_string(info, typedefs, t)? } else if include_keyword { - format!("union {}", name) + format!("union {name}") } else { name.clone() } @@ -1306,7 +1306,7 @@ pub fn subroutine_type_string( write!(parameters, "{}{}", ts.prefix, ts.suffix)?; } if let Some(location) = ¶meter.location { - write!(parameters, " /* {} */", location)?; + write!(parameters, " /* {location} */")?; } } if t.var_args { @@ -1322,7 +1322,7 @@ pub fn subroutine_type_string( let base_name = tag .string_attribute(AttributeKind::Name) .ok_or_else(|| anyhow!("member_of tag {} has no name attribute", member_of))?; - out.member = format!("{}::", base_name); + out.member = format!("{base_name}::"); } Ok(out) } @@ -1337,7 +1337,7 @@ pub fn subroutine_def_string( if is_erased { out.push_str("// Erased\n"); } else if let (Some(start), Some(end)) = (t.start_address, t.end_address) { - writeln!(out, "// Range: {:#X} -> {:#X}", start, end)?; + writeln!(out, "// Range: {start:#X} -> {end:#X}")?; } let rt = type_string(info, typedefs, &t.return_type, true)?; if t.local { @@ -1361,15 +1361,15 @@ pub fn subroutine_def_string( let base_name = tag .string_attribute(AttributeKind::Name) .ok_or_else(|| anyhow!("member_of tag {} has no name attribute", member_of))?; - write!(out, "{}::", base_name)?; + write!(out, "{base_name}::")?; // Handle constructors and destructors if let Some(name) = t.name.as_ref() { if name == "__dt" { - write!(out, "~{}", base_name)?; + write!(out, "~{base_name}")?; name_written = true; } else if name == "__ct" { - write!(out, "{}", base_name)?; + write!(out, "{base_name}")?; name_written = true; } } @@ -1398,7 +1398,7 @@ pub fn subroutine_def_string( write!(parameters, "{}{}", ts.prefix, ts.suffix)?; } if let Some(location) = ¶meter.location { - write!(parameters, " /* {} */", location)?; + write!(parameters, " /* {location} */")?; } } if t.var_args { @@ -1420,7 +1420,7 @@ pub fn subroutine_def_string( ts.suffix )?; if let Some(location) = &variable.location { - write!(var_out, " // {}", location)?; + write!(var_out, " // {location}")?; } writeln!(var_out)?; } @@ -1435,7 +1435,7 @@ pub fn subroutine_def_string( .get(&reference) .ok_or_else(|| anyhow!("Failed to locate reference tag {}", reference))?; if tag.kind == TagKind::Padding { - writeln!(out, " // -> ??? ({})", reference)?; + writeln!(out, " // -> ??? ({reference})")?; continue; } let variable = process_variable_tag(info, tag)?; @@ -1477,13 +1477,13 @@ fn subroutine_block_string( ) -> Result { let mut out = String::new(); if let Some(name) = &block.name { - write!(out, "{}: ", name)?; + write!(out, "{name}: ")?; } else { out.push_str("/* anonymous block */ "); } out.push_str("{\n"); if let (Some(start), Some(end)) = (block.start_address, block.end_address) { - writeln!(out, " // Range: {:#X} -> {:#X}", start, end)?; + writeln!(out, " // Range: {start:#X} -> {end:#X}")?; } let mut var_out = String::new(); for variable in &block.variables { @@ -1496,7 +1496,7 @@ fn subroutine_block_string( ts.suffix )?; if let Some(location) = &variable.location { - write!(var_out, " // {}", location)?; + write!(var_out, " // {location}")?; } writeln!(var_out)?; } @@ -1635,9 +1635,9 @@ pub fn struct_def_string( }; if let Some(name) = t.name.as_ref() { if name.starts_with('@') { - write!(out, " /* {} */", name)?; + write!(out, " /* {name} */")?; } else { - write!(out, " {}", name)?; + write!(out, " {name}")?; } } let mut wrote_base = false; @@ -1665,7 +1665,7 @@ pub fn struct_def_string( } out.push_str(" {\n"); if let Some(byte_size) = t.byte_size { - writeln!(out, " // total size: {:#X}", byte_size)?; + writeln!(out, " // total size: {byte_size:#X}")?; } let mut vis = match t.kind { StructureKind::Struct => Visibility::Public, @@ -1751,9 +1751,9 @@ pub fn enum_def_string(t: &EnumerationType) -> Result { let mut out = match t.name.as_ref() { Some(name) => { if name.starts_with('@') { - format!("enum /* {} */ {{\n", name) + format!("enum /* {name} */ {{\n") } else { - format!("enum {} {{\n", name) + format!("enum {name} {{\n") } } None => "enum {\n".to_string(), @@ -1769,9 +1769,9 @@ pub fn union_def_string(info: &DwarfInfo, typedefs: &TypedefMap, t: &UnionType) let mut out = match t.name.as_ref() { Some(name) => { if name.starts_with('@') { - format!("union /* {} */ {{\n", name) + format!("union /* {name} */ {{\n") } else { - format!("union {} {{\n", name) + format!("union {name} {{\n") } } None => "union {\n".to_string(), @@ -2029,7 +2029,7 @@ fn process_array_tag(info: &DwarfInfo, tag: &Tag) -> Result { (AttributeKind::SubscrData, AttributeValue::Block(data)) => { subscr_data = Some(process_array_subscript_data(data, info.e, tag.is_erased).with_context( - || format!("Failed to process SubscrData for tag: {:?}", tag), + || format!("Failed to process SubscrData for tag: {tag:?}"), )?) } (AttributeKind::Ordering, val) => match val { @@ -2615,13 +2615,13 @@ pub fn process_type(attr: &Attribute, e: Endian) -> Result { match (attr.kind, &attr.value) { (AttributeKind::FundType, &AttributeValue::Data2(type_id)) => { let fund_type = FundType::parse_int(type_id) - .with_context(|| format!("Invalid fundamental type ID '{:04X}'", type_id))?; + .with_context(|| format!("Invalid fundamental type ID '{type_id:04X}'"))?; Ok(Type { kind: TypeKind::Fundamental(fund_type), modifiers: vec![] }) } (AttributeKind::ModFundType, AttributeValue::Block(ops)) => { let type_id = u16::from_bytes(ops[ops.len() - 2..].try_into()?, e); let fund_type = FundType::parse_int(type_id) - .with_context(|| format!("Invalid fundamental type ID '{:04X}'", type_id))?; + .with_context(|| format!("Invalid fundamental type ID '{type_id:04X}'"))?; let modifiers = process_modifiers(&ops[..ops.len() - 2])?; Ok(Type { kind: TypeKind::Fundamental(fund_type), modifiers }) } @@ -2762,7 +2762,7 @@ pub fn tag_type_string( match ud { UserDefinedType::Structure(_) | UserDefinedType::Enumeration(_) - | UserDefinedType::Union(_) => Ok(format!("{};", ud_str)), + | UserDefinedType::Union(_) => Ok(format!("{ud_str};")), _ => Ok(ud_str), } } @@ -2789,9 +2789,9 @@ fn variable_string( out.push(';'); if include_extra { let size = variable.kind.size(info)?; - out.push_str(&format!(" // size: {:#X}", size)); + out.push_str(&format!(" // size: {size:#X}")); if let Some(addr) = variable.address { - out.push_str(&format!(", address: {:#X}", addr)); + out.push_str(&format!(", address: {addr:#X}")); } } Ok(out) diff --git a/src/util/elf.rs b/src/util/elf.rs index fff1041..846d48e 100644 --- a/src/util/elf.rs +++ b/src/util/elf.rs @@ -164,7 +164,7 @@ pub fn process_elf(path: &Utf8NativePath) -> Result { hash_map::Entry::Vacant(e) => e.insert(0), }; *index += 1; - let new_name = format!("{}_{}", file_name, index); + let new_name = format!("{file_name}_{index}"); // log::info!("Renaming {} to {}", file_name, new_name); file_name.clone_from(&new_name); match section_starts.entry(new_name.clone()) { diff --git a/src/util/file.rs b/src/util/file.rs index 8ad6cd4..8734a76 100644 --- a/src/util/file.rs +++ b/src/util/file.rs @@ -26,7 +26,7 @@ pub fn buf_writer(path: &Utf8NativePath) -> Result> { if let Some(parent) = path.parent() { DirBuilder::new().recursive(true).create(parent)?; } - let file = File::create(path).with_context(|| format!("Failed to create file '{}'", path))?; + let file = File::create(path).with_context(|| format!("Failed to create file '{path}'"))?; Ok(BufWriter::new(file)) } diff --git a/src/util/lcf.rs b/src/util/lcf.rs index da570f4..35bd9e4 100644 --- a/src/util/lcf.rs +++ b/src/util/lcf.rs @@ -47,11 +47,11 @@ pub fn generate_ldscript( let out = template .unwrap_or(LCF_TEMPLATE) - .replace("$ORIGIN", &format!("{:#X}", origin)) + .replace("$ORIGIN", &format!("{origin:#X}")) .replace("$SECTIONS", §ion_defs) .replace("$LAST_SECTION_SYMBOL", &last_section_symbol) .replace("$LAST_SECTION_NAME", &last_section_name) - .replace("$STACKSIZE", &format!("{:#X}", stack_size)) + .replace("$STACKSIZE", &format!("{stack_size:#X}")) .replace("$FORCEACTIVE", &force_active.join("\n ")) .replace("$ARENAHI", &format!("{:#X}", obj.arena_hi.unwrap_or(0x81700000))); Ok(out) @@ -74,7 +74,7 @@ pub fn generate_ldscript_partial( // Some RELs have no entry point (`.text` was stripped) so mwld requires at least an empty // `.init` section to be present in the linker script, for some reason. if obj.entry.is_none() { - section_defs = format!(".init :{{}}\n {}", section_defs); + section_defs = format!(".init :{{}}\n {section_defs}"); } let mut force_files = Vec::with_capacity(obj.link_order.len()); diff --git a/src/util/rarc.rs b/src/util/rarc.rs index 7a79f12..3750dec 100644 --- a/src/util/rarc.rs +++ b/src/util/rarc.rs @@ -209,7 +209,7 @@ impl<'a> RarcView<'a> { ) })?; let c_string = CStr::from_bytes_until_nul(name_buf) - .map_err(|_| format!("RARC: name at offset {} not null-terminated", offset))?; + .map_err(|_| format!("RARC: name at offset {offset} not null-terminated"))?; Ok(c_string.to_string_lossy()) } diff --git a/src/util/rel.rs b/src/util/rel.rs index 33b8e76..7d83dc7 100644 --- a/src/util/rel.rs +++ b/src/util/rel.rs @@ -364,7 +364,7 @@ where reader.seek(SeekFrom::Start(header.section_info_offset as u64))?; for idx in 0..header.num_sections { let section = RelSectionHeader::from_reader(reader, Endian::Big) - .with_context(|| format!("Failed to read REL section header {}", idx))?; + .with_context(|| format!("Failed to read REL section header {idx}"))?; sections.push(section); } Ok(sections) @@ -390,7 +390,7 @@ where R: Read + Seek + ?Sized { reader.seek(SeekFrom::Start(offset as u64))?; let mut data = vec![0u8; size as usize]; reader.read_exact(&mut data).with_context(|| { - format!("Failed to read REL section {} data with size {:#X}", idx, size) + format!("Failed to read REL section {idx} data with size {size:#X}") })?; reader.seek(SeekFrom::Start(position))?; data @@ -405,7 +405,7 @@ where R: Read + Seek + ?Sized { text_section = Some(idx as u8); (".text".to_string(), ObjSectionKind::Code, true) } else { - (format!(".section{}", idx), ObjSectionKind::Data, false) + (format!(".section{idx}"), ObjSectionKind::Data, false) }; sections.push(ObjSection { name, diff --git a/src/util/rso.rs b/src/util/rso.rs index 863e95f..94fc338 100644 --- a/src/util/rso.rs +++ b/src/util/rso.rs @@ -147,14 +147,14 @@ impl FromReader for RsoHeader { if next != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Expected 'next' to be 0, got {:#X}", next), + format!("Expected 'next' to be 0, got {next:#X}"), )); } let prev = u32::from_reader(reader, e)?; if prev != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Expected 'prev' to be 0, got {:#X}", prev), + format!("Expected 'prev' to be 0, got {prev:#X}"), )); } let num_sections = u32::from_reader(reader, e)?; @@ -170,7 +170,7 @@ impl FromReader for RsoHeader { if bss_section != 0 { return Err(io::Error::new( io::ErrorKind::InvalidData, - format!("Expected 'bssSection' to be 0, got {:#X}", bss_section), + format!("Expected 'bssSection' to be 0, got {bss_section:#X}"), )); } let prolog_offset = u32::from_reader(reader, e)?; @@ -440,7 +440,7 @@ where R: Read + Seek + ?Sized { // println!("Section {} offset {:#X} size {:#X}", idx, offset, size); sections.push(ObjSection { - name: format!(".section{}", idx), + name: format!(".section{idx}"), kind: if offset == 0 { ObjSectionKind::Bss } else if section.exec() { diff --git a/src/util/split.rs b/src/util/split.rs index 70c791e..a831e9e 100644 --- a/src/util/split.rs +++ b/src/util/split.rs @@ -655,7 +655,7 @@ fn add_padding_symbols(obj: &mut ObjInfo) -> Result<()> { next_address ); let name = if obj.module_id == 0 { - format!("lbl_{:08X}", symbol_end) + format!("lbl_{symbol_end:08X}") } else { format!( "lbl_{}_{}_{:X}", @@ -1465,7 +1465,7 @@ fn auto_unit_name( if unit_exists(&unit_name, obj, new_splits) { let mut i = 1; loop { - let new_unit_name = format!("{}_{}", unit_name, i); + let new_unit_name = format!("{unit_name}_{i}"); if !unit_exists(&new_unit_name, obj, new_splits) { unit_name = new_unit_name; break; diff --git a/src/vfs/disc.rs b/src/vfs/disc.rs index fec18c1..20d39f1 100644 --- a/src/vfs/disc.rs +++ b/src/vfs/disc.rs @@ -333,7 +333,7 @@ impl VfsFile for DiscFile { pub fn nod_to_io_error(e: nod::Error) -> io::Error { match e { - nod::Error::Io(msg, e) => io::Error::new(e.kind(), format!("{}: {}", msg, e)), + nod::Error::Io(msg, e) => io::Error::new(e.kind(), format!("{msg}: {e}")), e => io::Error::new(io::ErrorKind::InvalidData, e), } } diff --git a/src/vfs/mod.rs b/src/vfs/mod.rs index 55c85c8..42834db 100644 --- a/src/vfs/mod.rs +++ b/src/vfs/mod.rs @@ -108,8 +108,8 @@ impl Display for VfsError { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { match self { VfsError::NotFound => write!(f, "File or directory not found"), - VfsError::IoError(e) => write!(f, "{}", e), - VfsError::Other(e) => write!(f, "{}", e), + VfsError::IoError(e) => write!(f, "{e}"), + VfsError::Other(e) => write!(f, "{e}"), VfsError::NotADirectory => write!(f, "Path is a file, not a directory"), VfsError::IsADirectory => write!(f, "Path is a directory, not a file"), } @@ -129,8 +129,8 @@ impl Display for FileFormat { fn fmt(&self, f: &mut Formatter) -> std::fmt::Result { match self { FileFormat::Regular => write!(f, "File"), - FileFormat::Compressed(kind) => write!(f, "Compressed: {}", kind), - FileFormat::Archive(kind) => write!(f, "Archive: {}", kind), + FileFormat::Compressed(kind) => write!(f, "Compressed: {kind}"), + FileFormat::Archive(kind) => write!(f, "Archive: {kind}"), } } } @@ -165,7 +165,7 @@ impl Display for ArchiveKind { match self { ArchiveKind::Rarc => write!(f, "RARC"), ArchiveKind::U8 => write!(f, "U8"), - ArchiveKind::Disc(format) => write!(f, "Disc ({})", format), + ArchiveKind::Disc(format) => write!(f, "Disc ({format})"), ArchiveKind::Wad => write!(f, "WAD"), } } @@ -228,13 +228,13 @@ pub fn open_path_with_fs( let file_type = match fs.metadata(segment) { Ok(metadata) => metadata.file_type, Err(VfsError::NotFound) => return Err(anyhow!("{} not found", current_path)), - Err(e) => return Err(e).context(format!("Failed to open {}", current_path)), + Err(e) => return Err(e).context(format!("Failed to open {current_path}")), }; match file_type { VfsFileType::File => { file = Some( fs.open(segment) - .with_context(|| format!("Failed to open {}", current_path))?, + .with_context(|| format!("Failed to open {current_path}"))?, ); } VfsFileType::Directory => { @@ -248,7 +248,7 @@ pub fn open_path_with_fs( } let mut current_file = file.take().unwrap(); let format = detect(current_file.as_mut()) - .with_context(|| format!("Failed to detect file type for {}", current_path))?; + .with_context(|| format!("Failed to detect file type for {current_path}"))?; if let Some(&next) = split.peek() { match next { "nlzss" => { @@ -256,7 +256,7 @@ pub fn open_path_with_fs( file = Some( decompress_file(current_file.as_mut(), CompressionKind::Nlzss) .with_context(|| { - format!("Failed to decompress {} with NLZSS", current_path) + format!("Failed to decompress {current_path} with NLZSS") })?, ); } @@ -265,7 +265,7 @@ pub fn open_path_with_fs( file = Some( decompress_file(current_file.as_mut(), CompressionKind::Yay0) .with_context(|| { - format!("Failed to decompress {} with Yay0", current_path) + format!("Failed to decompress {current_path} with Yay0") })?, ); } @@ -274,7 +274,7 @@ pub fn open_path_with_fs( file = Some( decompress_file(current_file.as_mut(), CompressionKind::Yaz0) .with_context(|| { - format!("Failed to decompress {} with Yaz0", current_path) + format!("Failed to decompress {current_path} with Yaz0") })?, ); } @@ -283,16 +283,15 @@ pub fn open_path_with_fs( return Err(anyhow!("{} is not an archive", current_path)) } FileFormat::Compressed(kind) => { - file = - Some(decompress_file(current_file.as_mut(), kind).with_context( - || format!("Failed to decompress {}", current_path), - )?); + file = Some( + decompress_file(current_file.as_mut(), kind) + .with_context(|| format!("Failed to decompress {current_path}"))?, + ); // Continue the loop to detect the new format } FileFormat::Archive(kind) => { - fs = open_fs(current_file, kind).with_context(|| { - format!("Failed to open container {}", current_path) - })?; + fs = open_fs(current_file, kind) + .with_context(|| format!("Failed to open container {current_path}"))?; // Continue the loop to open the next segment } }, @@ -302,7 +301,7 @@ pub fn open_path_with_fs( return match format { FileFormat::Compressed(kind) if auto_decompress => Ok(OpenResult::File( decompress_file(current_file.as_mut(), kind) - .with_context(|| format!("Failed to decompress {}", current_path))?, + .with_context(|| format!("Failed to decompress {current_path}"))?, segment.to_path_buf(), )), _ => Ok(OpenResult::File(current_file, segment.to_path_buf())), diff --git a/src/vfs/wad.rs b/src/vfs/wad.rs index e106874..f657f70 100644 --- a/src/vfs/wad.rs +++ b/src/vfs/wad.rs @@ -118,11 +118,11 @@ impl Vfs for WadFs { } let title_id = hex::encode(self.wad.ticket().title_id); let mut entries = Vec::new(); - entries.push(format!("{}.tik", title_id)); - entries.push(format!("{}.tmd", title_id)); - entries.push(format!("{}.cert", title_id)); + entries.push(format!("{title_id}.tik")); + entries.push(format!("{title_id}.tmd")); + entries.push(format!("{title_id}.cert")); if self.wad.header.footer_size.get() > 0 { - entries.push(format!("{}.trailer", title_id)); + entries.push(format!("{title_id}.trailer")); } for content in self.wad.contents() { entries.push(format!("{:08x}.app", content.content_index.get()));