Skip to content

Commit

Permalink
Cargo clippy & cargo deny fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
encounter committed Dec 6, 2022
1 parent 771a141 commit a0371dd
Show file tree
Hide file tree
Showing 12 changed files with 56 additions and 62 deletions.
3 changes: 2 additions & 1 deletion deny.toml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@ allow = [
"MPL-2.0",
"Unicode-DFS-2016",
"Zlib",
"0BSD",
]
# List of explictly disallowed licenses
# See https://spdx.org/licenses/ for list of possible licenses
Expand Down Expand Up @@ -203,7 +204,7 @@ allow-git = []

[sources.allow-org]
# 1 or more github.com organizations to allow git sources for
github = ["encounter", "terorie"]
github = ["encounter"]
# 1 or more gitlab.com organizations to allow git sources for
#gitlab = [""]
# 1 or more bitbucket.org organizations to allow git sources for
Expand Down
10 changes: 4 additions & 6 deletions src/app.rs
Original file line number Diff line number Diff line change
Expand Up @@ -333,10 +333,8 @@ impl eframe::App for App {
for (idx, color) in view_state.view_config.diff_colors.iter_mut().enumerate() {
ui.horizontal(|ui| {
ui.color_edit_button_srgba(color);
if num_colors > 1 {
if ui.small_button("-").clicked() {
remove_at = Some(idx);
}
if num_colors > 1 && ui.small_button("-").clicked() {
remove_at = Some(idx);
}
});
}
Expand Down Expand Up @@ -483,7 +481,7 @@ impl eframe::App for App {
if let Some(project_dir) = &config.project_dir {
match create_watcher(self.modified.clone(), project_dir) {
Ok(watcher) => self.watcher = Some(watcher),
Err(e) => eprintln!("Failed to create watcher: {}", e),
Err(e) => eprintln!("Failed to create watcher: {e}"),
}
config.project_dir_change = false;
self.modified.store(true, Ordering::Relaxed);
Expand Down Expand Up @@ -534,7 +532,7 @@ fn create_watcher(
}
}
}
Err(e) => println!("watch error: {:?}", e),
Err(e) => println!("watch error: {e:?}"),
})?;
watcher.watch(project_dir, RecursiveMode::Recursive)?;
Ok(watcher)
Expand Down
14 changes: 7 additions & 7 deletions src/diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,9 +14,9 @@ use crate::{

fn no_diff_code(
arch: ObjArchitecture,
data: &Vec<u8>,
data: &[u8],
symbol: &mut ObjSymbol,
relocs: &Vec<ObjReloc>,
relocs: &[ObjReloc],
) -> Result<()> {
let code =
&data[symbol.section_address as usize..(symbol.section_address + symbol.size) as usize];
Expand Down Expand Up @@ -241,7 +241,7 @@ fn arg_eq(
) -> bool {
return match left {
ObjInsArg::PpcArg(l) => match right {
ObjInsArg::PpcArg(r) => format!("{}", l) == format!("{}", r),
ObjInsArg::PpcArg(r) => format!("{l}") == format!("{r}"),
_ => false,
},
ObjInsArg::Reloc => {
Expand Down Expand Up @@ -312,10 +312,10 @@ fn compare_ins(
state.diff_count += 1;
}
let a_str = match a {
ObjInsArg::PpcArg(arg) => format!("{}", arg),
ObjInsArg::PpcArg(arg) => format!("{arg}"),
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
ObjInsArg::MipsArg(str) => str.clone(),
ObjInsArg::BranchOffset(arg) => format!("{}", arg),
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
};
let a_diff = if let Some(idx) = state.left_args_idx.get(&a_str) {
ObjInsArgDiff { idx: *idx }
Expand All @@ -326,10 +326,10 @@ fn compare_ins(
ObjInsArgDiff { idx }
};
let b_str = match b {
ObjInsArg::PpcArg(arg) => format!("{}", arg),
ObjInsArg::PpcArg(arg) => format!("{arg}"),
ObjInsArg::Reloc | ObjInsArg::RelocWithBase => String::new(),
ObjInsArg::MipsArg(str) => str.clone(),
ObjInsArg::BranchOffset(arg) => format!("{}", arg),
ObjInsArg::BranchOffset(arg) => format!("{arg}"),
};
let b_diff = if let Some(idx) = state.right_args_idx.get(&b_str) {
ObjInsArgDiff { idx: *idx }
Expand Down
10 changes: 5 additions & 5 deletions src/jobs/objdiff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ fn run_make(cwd: &Path, arg: &Path, config: &AppConfig) -> BuildStatus {
let stderr = from_utf8(&output.stderr).context("Failed to process stderr")?;
Ok(BuildStatus {
success: output.status.code().unwrap_or(-1) == 0,
log: format!("{}\n{}", stdout, stderr),
log: format!("{stdout}\n{stderr}"),
})
})() {
Ok(status) => status,
Expand Down Expand Up @@ -102,26 +102,26 @@ fn run_build(

let total = if config.build_target { 5 } else { 4 };
let first_status = if config.build_target {
update_status(status, format!("Building target {}", obj_path), 0, total, &cancel)?;
update_status(status, format!("Building target {obj_path}"), 0, total, &cancel)?;
run_make(project_dir, target_path_rel, &config)
} else {
BuildStatus { success: true, log: String::new() }
};

update_status(status, format!("Building base {}", obj_path), 1, total, &cancel)?;
update_status(status, format!("Building base {obj_path}"), 1, total, &cancel)?;
let second_status = run_make(project_dir, base_path_rel, &config);

let time = OffsetDateTime::now_utc();

let mut first_obj = if first_status.success {
update_status(status, format!("Loading target {}", obj_path), 2, total, &cancel)?;
update_status(status, format!("Loading target {obj_path}"), 2, total, &cancel)?;
Some(elf::read(&target_path)?)
} else {
None
};

let mut second_obj = if second_status.success {
update_status(status, format!("Loading base {}", obj_path), 3, total, &cancel)?;
update_status(status, format!("Loading base {obj_path}"), 3, total, &cancel)?;
Some(elf::read(&base_path)?)
} else {
None
Expand Down
4 changes: 2 additions & 2 deletions src/jobs/update.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>
.assets
.iter()
.find(|a| a.name == BIN_NAME)
.ok_or(anyhow::Error::msg(formatcp!("No release asset for {}", BIN_NAME)))?;
.ok_or_else(|| anyhow::Error::msg(formatcp!("No release asset for {}", BIN_NAME)))?;

update_status(status, "Downloading release".to_string(), 1, 3, &cancel)?;
let tmp_dir = tempfile::Builder::new().prefix("update").tempdir_in(current_dir()?)?;
Expand All @@ -46,7 +46,7 @@ fn run_update(status: &Status, cancel: Receiver<()>) -> Result<Box<UpdateResult>
{
use std::os::unix::fs::PermissionsExt;
let mut perms = fs::metadata(&target_file)?.permissions();
perms.set_mode(0755);
perms.set_mode(0o755);
fs::set_permissions(&target_file, perms)?;
}

Expand Down
2 changes: 1 addition & 1 deletion src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ fn main() {
let result = exec::Command::new(path)
.args(&std::env::args().collect::<Vec<String>>())
.exec();
eprintln!("Failed to relaunch: {:?}", result);
eprintln!("Failed to relaunch: {result:?}");
} else {
let result = std::process::Command::new(path)
.args(std::env::args())
Expand Down
13 changes: 5 additions & 8 deletions src/obj/elf.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,14 @@ fn to_obj_section_kind(kind: SectionKind) -> ObjSectionKind {
SectionKind::Text => ObjSectionKind::Code,
SectionKind::Data | SectionKind::ReadOnlyData => ObjSectionKind::Data,
SectionKind::UninitializedData => ObjSectionKind::Bss,
_ => panic!("Unhandled section kind {:?}", kind),
_ => panic!("Unhandled section kind {kind:?}"),
}
}

fn to_obj_symbol(obj_file: &File<'_>, symbol: &Symbol<'_, '_>, addend: i64) -> Result<ObjSymbol> {
let mut name = symbol.name().context("Failed to process symbol name")?;
if name.is_empty() {
println!("Found empty sym: {:?}", symbol);
println!("Found empty sym: {symbol:?}");
name = "?";
}
let mut flags = ObjSymbolFlagSet(ObjSymbolFlags::none());
Expand Down Expand Up @@ -220,8 +220,7 @@ fn relocations_by_section(
R_PPC_EMB_SDA21 => ObjRelocKind::PpcEmbSda21,
_ => {
return Err(anyhow::Error::msg(format!(
"Unhandled PPC relocation type: {}",
kind
"Unhandled PPC relocation type: {kind}"
)))
}
},
Expand All @@ -231,8 +230,7 @@ fn relocations_by_section(
R_MIPS_LO16 => ObjRelocKind::MipsLo16,
_ => {
return Err(anyhow::Error::msg(format!(
"Unhandled MIPS relocation type: {}",
kind
"Unhandled MIPS relocation type: {kind}"
)))
}
},
Expand Down Expand Up @@ -271,8 +269,7 @@ fn relocations_by_section(
let addend = reloc.addend();
if addend < 0 {
return Err(anyhow::Error::msg(format!(
"Negative addend in section reloc: {}",
addend
"Negative addend in section reloc: {addend}"
)));
}
addend as u32
Expand Down
9 changes: 3 additions & 6 deletions src/views/config.rs
Original file line number Diff line number Diff line change
Expand Up @@ -81,16 +81,13 @@ pub fn config_ui(ui: &mut egui::Ui, config: &Arc<RwLock<AppConfig>>, view_state:
if state.update_available {
ui.colored_label(Color32::LIGHT_GREEN, "Update available");
ui.horizontal(|ui| {
if state.found_binary {
if ui
if state.found_binary && ui
.button("Automatic")
.on_hover_text_at_pointer(
"Automatically download and replace the current build",
)
.clicked()
{
view_state.jobs.push(queue_update());
}
.clicked() {
view_state.jobs.push(queue_update());
}
if ui
.button("Manual")
Expand Down
4 changes: 2 additions & 2 deletions src/views/data_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
}
let mut job = LayoutJob::default();
write_text(
format!("{:08X}: ", address).as_str(),
format!("{address:08X}: ").as_str(),
Color32::GRAY,
&mut job,
config.code_font.clone(),
Expand All @@ -44,7 +44,7 @@ fn data_row_ui(ui: &mut egui::Ui, address: usize, diffs: &[ObjDataDiff], config:
} else {
let mut text = String::new();
for byte in &diff.data {
text.push_str(format!("{:02X} ", byte).as_str());
text.push_str(format!("{byte:02X} ").as_str());
cur_addr += 1;
if cur_addr % 8 == 0 {
text.push(' ');
Expand Down
42 changes: 21 additions & 21 deletions src/views/function_diff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -20,43 +20,43 @@ fn write_reloc_name(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_
let name = reloc.target.demangled_name.as_ref().unwrap_or(&reloc.target.name);
write_text(name, Color32::LIGHT_GRAY, job, font_id.clone());
if reloc.target.addend != 0 {
write_text(&format!("+{:X}", reloc.target.addend), color, job, font_id.clone());
write_text(&format!("+{:X}", reloc.target.addend), color, job, font_id);
}
}

fn write_reloc(reloc: &ObjReloc, color: Color32, job: &mut LayoutJob, font_id: FontId) {
match reloc.kind {
ObjRelocKind::PpcAddr16Lo => {
write_reloc_name(reloc, color, job, font_id.clone());
write_text("@l", color, job, font_id.clone());
write_text("@l", color, job, font_id);
}
ObjRelocKind::PpcAddr16Hi => {
write_reloc_name(reloc, color, job, font_id.clone());
write_text("@h", color, job, font_id.clone());
write_text("@h", color, job, font_id);
}
ObjRelocKind::PpcAddr16Ha => {
write_reloc_name(reloc, color, job, font_id.clone());
write_text("@ha", color, job, font_id.clone());
write_text("@ha", color, job, font_id);
}
ObjRelocKind::PpcEmbSda21 => {
write_reloc_name(reloc, color, job, font_id.clone());
write_text("@sda21", color, job, font_id.clone());
write_text("@sda21", color, job, font_id);
}
ObjRelocKind::MipsHi16 => {
write_text("%hi(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone());
write_text(")", color, job, font_id.clone());
write_text(")", color, job, font_id);
}
ObjRelocKind::MipsLo16 => {
write_text("%lo(", color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id.clone());
write_text(")", color, job, font_id.clone());
write_text(")", color, job, font_id);
}
ObjRelocKind::Absolute
| ObjRelocKind::PpcRel24
| ObjRelocKind::PpcRel14
| ObjRelocKind::Mips26 => {
write_reloc_name(reloc, color, job, font_id.clone());
write_reloc_name(reloc, color, job, font_id);
}
};
}
Expand Down Expand Up @@ -102,16 +102,16 @@ fn write_ins(
match arg {
ObjInsArg::PpcArg(arg) => match arg {
Argument::Offset(val) => {
write_text(&format!("{}", val), color, job, config.code_font.clone());
write_text(&format!("{val}"), color, job, config.code_font.clone());
write_text("(", base_color, job, config.code_font.clone());
writing_offset = true;
continue;
}
Argument::Uimm(_) | Argument::Simm(_) => {
write_text(&format!("{}", arg), color, job, config.code_font.clone());
write_text(&format!("{arg}"), color, job, config.code_font.clone());
}
_ => {
write_text(&format!("{}", arg), color, job, config.code_font.clone());
write_text(&format!("{arg}"), color, job, config.code_font.clone());
}
},
ObjInsArg::Reloc => {
Expand All @@ -133,7 +133,7 @@ fn write_ins(
}
ObjInsArg::BranchOffset(offset) => {
let addr = offset + ins.address as i32 - base_addr as i32;
write_text(&format!("{:x}", addr), color, job, config.code_font.clone());
write_text(&format!("{addr:x}"), color, job, config.code_font.clone());
}
}
if writing_offset {
Expand Down Expand Up @@ -171,7 +171,7 @@ fn ins_hover_ui(ui: &mut egui::Ui, ins: &ObjIns) {
ui.label(format!("Relocation type: {:?}", reloc.kind));
ui.colored_label(Color32::WHITE, format!("Name: {}", reloc.target.name));
if let Some(section) = &reloc.target_section {
ui.colored_label(Color32::WHITE, format!("Section: {}", section));
ui.colored_label(Color32::WHITE, format!("Section: {section}"));
ui.colored_label(Color32::WHITE, format!("Address: {:x}", reloc.target.address));
ui.colored_label(Color32::WHITE, format!("Size: {:x}", reloc.target.size));
} else {
Expand All @@ -192,8 +192,8 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
if let ObjInsArg::PpcArg(arg) = arg {
match arg {
Argument::Uimm(v) => {
if ui.button(format!("Copy \"{}\"", v)).clicked() {
ui.output().copied_text = format!("{}", v);
if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}");
ui.close_menu();
}
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
Expand All @@ -202,8 +202,8 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
}
}
Argument::Simm(v) => {
if ui.button(format!("Copy \"{}\"", v)).clicked() {
ui.output().copied_text = format!("{}", v);
if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}");
ui.close_menu();
}
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
Expand All @@ -212,8 +212,8 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
}
}
Argument::Offset(v) => {
if ui.button(format!("Copy \"{}\"", v)).clicked() {
ui.output().copied_text = format!("{}", v);
if ui.button(format!("Copy \"{v}\"")).clicked() {
ui.output().copied_text = format!("{v}");
ui.close_menu();
}
if ui.button(format!("Copy \"{}\"", v.0)).clicked() {
Expand All @@ -227,7 +227,7 @@ fn ins_context_menu(ui: &mut egui::Ui, ins: &ObjIns) {
}
if let Some(reloc) = &ins.reloc {
if let Some(name) = &reloc.target.demangled_name {
if ui.button(format!("Copy \"{}\"", name)).clicked() {
if ui.button(format!("Copy \"{name}\"")).clicked() {
ui.output().copied_text = name.clone();
ui.close_menu();
}
Expand Down Expand Up @@ -399,7 +399,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
{
ui.colored_label(
match_color_for_symbol(match_percent),
&format!("{:.0}%", match_percent),
&format!("{match_percent:.0}%"),
);
}
ui.label("Diff base:");
Expand Down
2 changes: 1 addition & 1 deletion src/views/jobs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
if job.handle.is_some() {
job.should_remove = true;
if let Err(e) = job.cancel.send(()) {
eprintln!("Failed to cancel job: {:?}", e);
eprintln!("Failed to cancel job: {e:?}");
}
} else {
remove_job = Some(idx);
Expand Down
Loading

0 comments on commit a0371dd

Please sign in to comment.