Let-else reformatting (#23)

* Use let-else in App::post_rendering

* Use let-else in diff::reloc_eq

* Use let-else in diff::diff_objs

* Use let-else in views::data_diff::data_diff_ui

* Use let-else in views::function_diff::function_diff_ui

* Use let-else in views::function_diff::asm_row_ui

* Use let-else in views::jobs::jobs_ui

* Update rust-version in Cargo.toml
This commit is contained in:
Nick Condron 2023-01-16 16:51:40 -05:00 committed by GitHub
parent c7b6ec83d7
commit 20dcc50695
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
6 changed files with 346 additions and 364 deletions

View File

@ -2,7 +2,7 @@
name = "objdiff" name = "objdiff"
version = "0.2.3" version = "0.2.3"
edition = "2021" edition = "2021"
rust-version = "1.62" rust-version = "1.65"
authors = ["Luke Street <luke@street.dev>"] authors = ["Luke Street <luke@street.dev>"]
license = "MIT OR Apache-2.0" license = "MIT OR Apache-2.0"
repository = "https://github.com/encounter/objdiff" repository = "https://github.com/encounter/objdiff"

View File

@ -398,7 +398,9 @@ impl eframe::App for App {
fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &eframe::Frame) { fn post_rendering(&mut self, _window_size_px: [u32; 2], _frame: &eframe::Frame) {
for job in &mut self.view_state.jobs { for job in &mut self.view_state.jobs {
if let Some(handle) = &job.handle { let Some(handle) = &job.handle else {
continue;
};
if !handle.is_finished() { if !handle.is_finished() {
continue; continue;
} }
@ -416,14 +418,8 @@ impl eframe::App for App {
} }
JobResult::BinDiff(state) => { JobResult::BinDiff(state) => {
self.view_state.build = Some(Box::new(ObjDiffResult { self.view_state.build = Some(Box::new(ObjDiffResult {
first_status: BuildStatus { first_status: BuildStatus { success: true, log: "".to_string() },
success: true, second_status: BuildStatus { success: true, log: "".to_string() },
log: "".to_string(),
},
second_status: BuildStatus {
success: true,
log: "".to_string(),
},
first_obj: Some(state.first_obj), first_obj: Some(state.first_obj),
second_obj: Some(state.second_obj), second_obj: Some(state.second_obj),
time: OffsetDateTime::now_utc(), time: OffsetDateTime::now_utc(),
@ -464,7 +460,6 @@ impl eframe::App for App {
} }
} }
} }
}
if self.view_state.jobs.iter().any(|v| v.should_remove) { if self.view_state.jobs.iter().any(|v| v.should_remove) {
let mut i = 0; let mut i = 0;
while i < self.view_state.jobs.len() { while i < self.view_state.jobs.len() {

View File

@ -211,10 +211,13 @@ fn address_eq(left: &ObjSymbol, right: &ObjSymbol) -> bool {
} }
fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bool { fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bool {
if let (Some(left), Some(right)) = (left_reloc, right_reloc) { let (Some(left), Some(right)) = (left_reloc, right_reloc) else {
return false;
};
if left.kind != right.kind { if left.kind != right.kind {
return false; return false;
} }
let name_matches = left.target.name == right.target.name; let name_matches = left.target.name == right.target.name;
match (&left.target_section, &right.target_section) { match (&left.target_section, &right.target_section) {
(Some(sl), Some(sr)) => { (Some(sl), Some(sr)) => {
@ -228,9 +231,6 @@ fn reloc_eq(left_reloc: Option<&ObjReloc>, right_reloc: Option<&ObjReloc>) -> bo
} }
(None, None) => name_matches, (None, None) => name_matches,
} }
} else {
false
}
} }
fn arg_eq( fn arg_eq(
@ -363,7 +363,9 @@ fn find_symbol<'a>(symbols: &'a mut [ObjSymbol], name: &str) -> Option<&'a mut O
pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> { pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffConfig) -> Result<()> {
for left_section in &mut left.sections { for left_section in &mut left.sections {
if let Some(right_section) = find_section(right, &left_section.name) { let Some(right_section) = find_section(right, &left_section.name) else {
continue;
};
if left_section.kind == ObjSectionKind::Code { if left_section.kind == ObjSectionKind::Code {
for left_symbol in &mut left_section.symbols { for left_symbol in &mut left_section.symbols {
if let Some(right_symbol) = if let Some(right_symbol) =
@ -406,7 +408,6 @@ pub fn diff_objs(left: &mut ObjInfo, right: &mut ObjInfo, _diff_config: &DiffCon
diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?; diff_bss_symbols(&mut left_section.symbols, &mut right_section.symbols)?;
} }
} }
}
diff_bss_symbols(&mut left.common, &mut right.common)?; diff_bss_symbols(&mut left.common, &mut right.common)?;
Ok(()) Ok(())
} }

View File

@ -165,8 +165,9 @@ fn data_table_ui(
pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool { pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
let mut rebuild = false; let mut rebuild = false;
if let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
{ return rebuild;
};
StripBuilder::new(ui) StripBuilder::new(ui)
.size(Size::exact(20.0)) .size(Size::exact(20.0))
.size(Size::exact(40.0)) .size(Size::exact(40.0))
@ -190,11 +191,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.style_mut().override_text_style = ui.style_mut().override_text_style =
Some(egui::TextStyle::Monospace); Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
.jobs
.iter()
.any(|job| job.job_type == Job::ObjDiff)
{
ui.label("Building..."); ui.label("Building...");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
@ -218,8 +215,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
builder.sizes(Size::remainder(), 2).horizontal(|mut strip| { builder.sizes(Size::remainder(), 2).horizontal(|mut strip| {
strip.cell(|ui| { strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name); ui.colored_label(Color32::WHITE, &selected_symbol.symbol_name);
ui.label("Diff target:"); ui.label("Diff target:");
@ -228,8 +224,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
}); });
strip.cell(|ui| { strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.label(""); ui.label("");
ui.label("Diff base:"); ui.label("Diff base:");
@ -239,9 +234,7 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
}); });
}); });
strip.cell(|ui| { strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) = if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
(&result.first_obj, &result.second_obj)
{
let table = TableBuilder::new(ui) let table = TableBuilder::new(ui)
.striped(false) .striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min)) .cell_layout(egui::Layout::left_to_right(egui::Align::Min))
@ -258,6 +251,5 @@ pub fn data_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
} }
}); });
}); });
}
rebuild rebuild
} }

View File

@ -251,7 +251,11 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color); ui.painter().rect_filled(ui.available_rect_before_wrap(), 0.0, ui.visuals().faint_bg_color);
} }
let mut job = LayoutJob::default(); let mut job = LayoutJob::default();
if let Some(ins) = &ins_diff.ins { let Some(ins) = &ins_diff.ins else {
ui.label("");
return;
};
let base_color = match ins_diff.kind { let base_color = match ins_diff.kind {
ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => { ObjInsDiffKind::None | ObjInsDiffKind::OpMismatch | ObjInsDiffKind::ArgMismatch => {
Color32::GRAY Color32::GRAY
@ -288,9 +292,6 @@ fn asm_row_ui(ui: &mut egui::Ui, ins_diff: &ObjInsDiff, symbol: &ObjSymbol, conf
ui.add(Label::new(job).sense(Sense::click())) ui.add(Label::new(job).sense(Sense::click()))
.on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins)) .on_hover_ui_at_pointer(|ui| ins_hover_ui(ui, ins))
.context_menu(|ui| ins_context_menu(ui, ins)); .context_menu(|ui| ins_context_menu(ui, ins));
} else {
ui.label("");
}
} }
fn asm_table_ui( fn asm_table_ui(
@ -322,8 +323,9 @@ fn asm_table_ui(
pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool { pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
let mut rebuild = false; let mut rebuild = false;
if let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) let (Some(result), Some(selected_symbol)) = (&view_state.build, &view_state.selected_symbol) else {
{ return rebuild;
};
StripBuilder::new(ui) StripBuilder::new(ui)
.size(Size::exact(20.0)) .size(Size::exact(20.0))
.size(Size::exact(40.0)) .size(Size::exact(40.0))
@ -347,11 +349,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
ui.style_mut().override_text_style = ui.style_mut().override_text_style =
Some(egui::TextStyle::Monospace); Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if view_state if view_state.jobs.iter().any(|job| job.job_type == Job::ObjDiff) {
.jobs
.iter()
.any(|job| job.job_type == Job::ObjDiff)
{
ui.label("Building..."); ui.label("Building...");
} else { } else {
ui.label("Last built:"); ui.label("Last built:");
@ -376,8 +374,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
let demangled = demangle(&selected_symbol.symbol_name, &Default::default()); let demangled = demangle(&selected_symbol.symbol_name, &Default::default());
strip.cell(|ui| { strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
ui.colored_label( ui.colored_label(
Color32::WHITE, Color32::WHITE,
@ -389,8 +386,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
}); });
strip.cell(|ui| { strip.cell(|ui| {
ui.scope(|ui| { ui.scope(|ui| {
ui.style_mut().override_text_style = ui.style_mut().override_text_style = Some(egui::TextStyle::Monospace);
Some(egui::TextStyle::Monospace);
ui.style_mut().wrap = Some(false); ui.style_mut().wrap = Some(false);
if let Some(match_percent) = result if let Some(match_percent) = result
.second_obj .second_obj
@ -410,9 +406,7 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
}); });
}); });
strip.cell(|ui| { strip.cell(|ui| {
if let (Some(left_obj), Some(right_obj)) = if let (Some(left_obj), Some(right_obj)) = (&result.first_obj, &result.second_obj) {
(&result.first_obj, &result.second_obj)
{
let table = TableBuilder::new(ui) let table = TableBuilder::new(ui)
.striped(false) .striped(false)
.cell_layout(egui::Layout::left_to_right(egui::Align::Min)) .cell_layout(egui::Layout::left_to_right(egui::Align::Min))
@ -429,6 +423,5 @@ pub fn function_diff_ui(ui: &mut egui::Ui, view_state: &mut ViewState) -> bool {
} }
}); });
}); });
}
rebuild rebuild
} }

View File

@ -7,7 +7,9 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
let mut remove_job: Option<usize> = None; let mut remove_job: Option<usize> = None;
for (idx, job) in view_state.jobs.iter_mut().enumerate() { for (idx, job) in view_state.jobs.iter_mut().enumerate() {
if let Ok(status) = job.status.read() { let Ok(status) = job.status.read() else {
continue;
};
ui.group(|ui| { ui.group(|ui| {
ui.horizontal(|ui| { ui.horizontal(|ui| {
ui.label(&status.title); ui.label(&status.title);
@ -47,7 +49,6 @@ pub fn jobs_ui(ui: &mut egui::Ui, view_state: &mut ViewState) {
} }
}); });
} }
}
if let Some(idx) = remove_job { if let Some(idx) = remove_job {
view_state.jobs.remove(idx); view_state.jobs.remove(idx);