Skip to content

Commit 1ca1c04

Browse files
committed
fmt
1 parent 35e2b35 commit 1ca1c04

File tree

21 files changed

+365
-174
lines changed

21 files changed

+365
-174
lines changed

objdiff-cli/src/argp_version.rs

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,14 @@ use std::ffi::OsStr;
77
use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions};
88

99
struct ArgsOrVersion<T>(T)
10-
where T: FromArgs;
10+
where
11+
T: FromArgs;
1112

1213
impl<T> TopLevelCommand for ArgsOrVersion<T> where T: FromArgs {}
1314

1415
impl<T> FromArgs for ArgsOrVersion<T>
15-
where T: FromArgs
16+
where
17+
T: FromArgs,
1618
{
1719
fn _from_args(
1820
command_name: &[&str],
@@ -58,6 +60,8 @@ where T: FromArgs
5860
/// This function will exit early from the current process if argument parsing was unsuccessful or if information like `--help` was requested.
5961
/// Error messages will be printed to stderr, and `--help` output to stdout.
6062
pub fn from_env<T>() -> T
61-
where T: TopLevelCommand {
63+
where
64+
T: TopLevelCommand,
65+
{
6266
argp::parse_args_or_exit::<ArgsOrVersion<T>>(argp::DEFAULT).0
6367
}

objdiff-cli/src/cmd/diff.rs

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -322,9 +322,13 @@ impl AppState {
322322
pub struct TermWaker(pub AtomicBool);
323323

324324
impl Wake for TermWaker {
325-
fn wake(self: Arc<Self>) { self.0.store(true, Ordering::Relaxed); }
325+
fn wake(self: Arc<Self>) {
326+
self.0.store(true, Ordering::Relaxed);
327+
}
326328

327-
fn wake_by_ref(self: &Arc<Self>) { self.0.store(true, Ordering::Relaxed); }
329+
fn wake_by_ref(self: &Arc<Self>) {
330+
self.0.store(true, Ordering::Relaxed);
331+
}
328332
}
329333

330334
fn run_interactive(

objdiff-core/src/arch/arm.rs

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -43,10 +43,13 @@ impl ArchArm {
4343
&& s.name() == Ok(".ARM.attributes")
4444
}) {
4545
let attr_data = arm_attrs.uncompressed_data()?;
46-
let build_attrs = BuildAttrs::new(&attr_data, match file.endianness() {
47-
object::Endianness::Little => arm_attr::Endian::Little,
48-
object::Endianness::Big => arm_attr::Endian::Big,
49-
})?;
46+
let build_attrs = BuildAttrs::new(
47+
&attr_data,
48+
match file.endianness() {
49+
object::Endianness::Little => arm_attr::Endian::Little,
50+
object::Endianness::Big => arm_attr::Endian::Big,
51+
},
52+
)?;
5053
for subsection in build_attrs.subsections() {
5154
let subsection = subsection?;
5255
if !subsection.is_aeabi() {

objdiff-core/src/arch/arm64.rs

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,9 @@ use crate::{
2121
pub struct ArchArm64 {}
2222

2323
impl ArchArm64 {
24-
pub fn new(_file: &object::File) -> Result<Self> { Ok(Self {}) }
24+
pub fn new(_file: &object::File) -> Result<Self> {
25+
Ok(Self {})
26+
}
2527
}
2628

2729
impl Arch for ArchArm64 {
@@ -186,7 +188,9 @@ struct DisplayCtx<'a> {
186188
// Reworked for more structured output. The library only gives us a Display impl, and no way to
187189
// capture any of this information, so it needs to be reimplemented here.
188190
fn display_instruction<Cb>(args: &mut Cb, ins: &Instruction, ctx: &mut DisplayCtx) -> &'static str
189-
where Cb: FnMut(InstructionPart<'static>) {
191+
where
192+
Cb: FnMut(InstructionPart<'static>),
193+
{
190194
let mnemonic = match ins.opcode {
191195
Opcode::Invalid => return "<invalid>",
192196
Opcode::UDF => "udf",
@@ -2001,13 +2005,17 @@ fn condition_code(cond: u8) -> &'static str {
20012005

20022006
#[inline]
20032007
fn push_register<Cb>(args: &mut Cb, size: SizeCode, reg: u16, sp: bool)
2004-
where Cb: FnMut(InstructionPart<'static>) {
2008+
where
2009+
Cb: FnMut(InstructionPart<'static>),
2010+
{
20052011
push_opaque(args, reg_name(size, reg, sp));
20062012
}
20072013

20082014
#[inline]
20092015
fn push_shift<Cb>(args: &mut Cb, style: ShiftStyle, amount: u8)
2010-
where Cb: FnMut(InstructionPart<'static>) {
2016+
where
2017+
Cb: FnMut(InstructionPart<'static>),
2018+
{
20112019
push_opaque(args, shift_style(style));
20122020
if amount != 0 {
20132021
push_plain(args, " ");
@@ -2017,12 +2025,16 @@ where Cb: FnMut(InstructionPart<'static>) {
20172025

20182026
#[inline]
20192027
fn push_condition_code<Cb>(args: &mut Cb, cond: u8)
2020-
where Cb: FnMut(InstructionPart<'static>) {
2028+
where
2029+
Cb: FnMut(InstructionPart<'static>),
2030+
{
20212031
push_opaque(args, condition_code(cond));
20222032
}
20232033

20242034
fn push_barrier<Cb>(args: &mut Cb, option: u8)
2025-
where Cb: FnMut(InstructionPart<'static>) {
2035+
where
2036+
Cb: FnMut(InstructionPart<'static>),
2037+
{
20262038
match option {
20272039
0b0001 => push_opaque(args, "oshld"),
20282040
0b0010 => push_opaque(args, "oshst"),
@@ -2042,32 +2054,42 @@ where Cb: FnMut(InstructionPart<'static>) {
20422054

20432055
#[inline]
20442056
fn push_opaque<'a, Cb>(args: &mut Cb, text: &'a str)
2045-
where Cb: FnMut(InstructionPart<'a>) {
2057+
where
2058+
Cb: FnMut(InstructionPart<'a>),
2059+
{
20462060
args(InstructionPart::opaque(text));
20472061
}
20482062

20492063
#[inline]
20502064
fn push_plain<Cb>(args: &mut Cb, text: &'static str)
2051-
where Cb: FnMut(InstructionPart<'static>) {
2065+
where
2066+
Cb: FnMut(InstructionPart<'static>),
2067+
{
20522068
args(InstructionPart::basic(text));
20532069
}
20542070

20552071
#[inline]
20562072
fn push_separator<Cb>(args: &mut Cb)
2057-
where Cb: FnMut(InstructionPart<'static>) {
2073+
where
2074+
Cb: FnMut(InstructionPart<'static>),
2075+
{
20582076
args(InstructionPart::separator());
20592077
}
20602078

20612079
#[inline]
20622080
fn push_unsigned<Cb>(args: &mut Cb, v: u64)
2063-
where Cb: FnMut(InstructionPart<'static>) {
2081+
where
2082+
Cb: FnMut(InstructionPart<'static>),
2083+
{
20642084
push_plain(args, "#");
20652085
args(InstructionPart::unsigned(v));
20662086
}
20672087

20682088
#[inline]
20692089
fn push_signed<Cb>(args: &mut Cb, v: i64)
2070-
where Cb: FnMut(InstructionPart<'static>) {
2090+
where
2091+
Cb: FnMut(InstructionPart<'static>),
2092+
{
20712093
push_plain(args, "#");
20722094
args(InstructionPart::signed(v));
20732095
}
@@ -2107,7 +2129,9 @@ fn is_reg_index_reloc(resolved: Option<ResolvedRelocation>) -> bool {
21072129
}
21082130

21092131
fn push_operand<Cb>(args: &mut Cb, o: &Operand, ctx: &mut DisplayCtx)
2110-
where Cb: FnMut(InstructionPart<'static>) {
2132+
where
2133+
Cb: FnMut(InstructionPart<'static>),
2134+
{
21112135
match o {
21122136
Operand::Nothing => unreachable!(),
21132137
Operand::PCOffset(off) => {

objdiff-core/src/arch/mod.rs

Lines changed: 32 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -143,20 +143,26 @@ impl DataType {
143143
DataType::Float => {
144144
let bytes: [u8; 4] = bytes.try_into().unwrap();
145145
strs.push((
146-
format!("{:?}f", match endian {
147-
object::Endianness::Little => f32::from_le_bytes(bytes),
148-
object::Endianness::Big => f32::from_be_bytes(bytes),
149-
}),
146+
format!(
147+
"{:?}f",
148+
match endian {
149+
object::Endianness::Little => f32::from_le_bytes(bytes),
150+
object::Endianness::Big => f32::from_be_bytes(bytes),
151+
}
152+
),
150153
None,
151154
));
152155
}
153156
DataType::Double => {
154157
let bytes: [u8; 8] = bytes.try_into().unwrap();
155158
strs.push((
156-
format!("{:?}", match endian {
157-
object::Endianness::Little => f64::from_le_bytes(bytes),
158-
object::Endianness::Big => f64::from_be_bytes(bytes),
159-
}),
159+
format!(
160+
"{:?}",
161+
match endian {
162+
object::Endianness::Little => f64::from_le_bytes(bytes),
163+
object::Endianness::Big => f64::from_be_bytes(bytes),
164+
}
165+
),
160166
None,
161167
));
162168
}
@@ -371,11 +377,15 @@ pub trait Arch: Any + Debug + Send + Sync {
371377
Ok(None)
372378
}
373379

374-
fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> { None }
380+
fn reloc_name(&self, _flags: RelocationFlags) -> Option<&'static str> {
381+
None
382+
}
375383

376384
fn data_reloc_size(&self, flags: RelocationFlags) -> usize;
377385

378-
fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 { address }
386+
fn symbol_address(&self, address: u64, _kind: SymbolKind) -> u64 {
387+
address
388+
}
379389

380390
fn extra_symbol_flags(&self, _symbol: &object::Symbol) -> SymbolFlagSet {
381391
SymbolFlagSet::default()
@@ -389,9 +399,13 @@ pub trait Arch: Any + Debug + Send + Sync {
389399
None
390400
}
391401

392-
fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec<HoverItem> { Vec::new() }
402+
fn symbol_hover(&self, _obj: &Object, _symbol_index: usize) -> Vec<HoverItem> {
403+
Vec::new()
404+
}
393405

394-
fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec<ContextItem> { Vec::new() }
406+
fn symbol_context(&self, _obj: &Object, _symbol_index: usize) -> Vec<ContextItem> {
407+
Vec::new()
408+
}
395409

396410
fn instruction_hover(
397411
&self,
@@ -449,7 +463,9 @@ pub fn new_arch(object: &object::File, diff_side: DiffSide) -> Result<Box<dyn Ar
449463
pub struct ArchDummy {}
450464

451465
impl ArchDummy {
452-
pub fn new() -> Box<Self> { Box::new(Self {}) }
466+
pub fn new() -> Box<Self> {
467+
Box::new(Self {})
468+
}
453469
}
454470

455471
impl Arch for ArchDummy {
@@ -473,7 +489,9 @@ impl Arch for ArchDummy {
473489
Ok(())
474490
}
475491

476-
fn data_reloc_size(&self, _flags: RelocationFlags) -> usize { 0 }
492+
fn data_reloc_size(&self, _flags: RelocationFlags) -> usize {
493+
0
494+
}
477495
}
478496

479497
#[derive(Debug, Clone, Copy, PartialEq, Eq)]

objdiff-core/src/arch/ppc/flow_analysis.rs

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,9 @@ impl RegisterState {
175175
impl Index<powerpc::GPR> for RegisterState {
176176
type Output = RegisterContent;
177177

178-
fn index(&self, gpr: powerpc::GPR) -> &Self::Output { &self.gpr[gpr.0 as usize] }
178+
fn index(&self, gpr: powerpc::GPR) -> &Self::Output {
179+
&self.gpr[gpr.0 as usize]
180+
}
179181
}
180182
impl IndexMut<powerpc::GPR> for RegisterState {
181183
fn index_mut(&mut self, gpr: powerpc::GPR) -> &mut Self::Output {
@@ -186,7 +188,9 @@ impl IndexMut<powerpc::GPR> for RegisterState {
186188
impl Index<powerpc::FPR> for RegisterState {
187189
type Output = RegisterContent;
188190

189-
fn index(&self, fpr: powerpc::FPR) -> &Self::Output { &self.fpr[fpr.0 as usize] }
191+
fn index(&self, fpr: powerpc::FPR) -> &Self::Output {
192+
&self.fpr[fpr.0 as usize]
193+
}
190194
}
191195
impl IndexMut<powerpc::FPR> for RegisterState {
192196
fn index_mut(&mut self, fpr: powerpc::FPR) -> &mut Self::Output {
@@ -296,7 +300,9 @@ impl PPCFlowAnalysisResult {
296300
self.argument_contents.insert((address, argument), value);
297301
}
298302

299-
fn new() -> Self { PPCFlowAnalysisResult { argument_contents: Default::default() } }
303+
fn new() -> Self {
304+
PPCFlowAnalysisResult { argument_contents: Default::default() }
305+
}
300306
}
301307

302308
impl FlowAnalysisResult for PPCFlowAnalysisResult {
@@ -377,7 +383,9 @@ fn fill_registers_from_relocation(
377383
// See: https://github.com/encounter/decomp-toolkit/blob/main/src/analysis/pass.rs
378384
const SLEDS: [&str; 6] = ["_savefpr_", "_restfpr_", "_savegpr_", "_restgpr_", "_savev", "_restv"];
379385

380-
fn is_sled_function(name: &str) -> bool { SLEDS.iter().any(|sled| name.starts_with(sled)) }
386+
fn is_sled_function(name: &str) -> bool {
387+
SLEDS.iter().any(|sled| name.starts_with(sled))
388+
}
381389

382390
pub fn ppc_data_flow_analysis(
383391
obj: &Object,

objdiff-core/src/arch/ppc/mod.rs

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,9 @@ fn is_rel_abs_arg(arg: &powerpc::Argument) -> bool {
4545
)
4646
}
4747

48-
fn is_offset_arg(arg: &powerpc::Argument) -> bool { matches!(arg, powerpc::Argument::Offset(_)) }
48+
fn is_offset_arg(arg: &powerpc::Argument) -> bool {
49+
matches!(arg, powerpc::Argument::Offset(_))
50+
}
4951

5052
#[derive(Debug)]
5153
pub struct ArchPpc {
@@ -228,9 +230,10 @@ impl Arch for ArchPpc {
228230
.skip_while(|&(a, _)| a < address)
229231
.take_while(|&(a, _)| a == address)
230232
.find(|(_, reloc)| {
231-
matches!(reloc.flags(), object::RelocationFlags::Coff {
232-
typ: pe::IMAGE_REL_PPC_PAIR
233-
})
233+
matches!(
234+
reloc.flags(),
235+
object::RelocationFlags::Coff { typ: pe::IMAGE_REL_PPC_PAIR }
236+
)
234237
})
235238
.map_or(
236239
Ok(Some(RelocationOverride {
@@ -624,12 +627,15 @@ fn decode_exception_info(
624627
};
625628

626629
//Add the new entry to the list
627-
result.insert(extab_func.index().0 - 1, ExceptionInfo {
628-
eti_symbol: make_symbol_ref(&extabindex)?,
629-
etb_symbol: make_symbol_ref(&extab)?,
630-
data,
631-
dtors,
632-
});
630+
result.insert(
631+
extab_func.index().0 - 1,
632+
ExceptionInfo {
633+
eti_symbol: make_symbol_ref(&extabindex)?,
634+
etb_symbol: make_symbol_ref(&extab)?,
635+
data,
636+
dtors,
637+
},
638+
);
633639
}
634640

635641
Ok(Some(result))

objdiff-core/src/arch/superh/mod.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,9 @@ pub mod disasm;
1515
pub struct ArchSuperH {}
1616

1717
impl ArchSuperH {
18-
pub fn new(_file: &object::File) -> Result<Self> { Ok(Self {}) }
18+
pub fn new(_file: &object::File) -> Result<Self> {
19+
Ok(Self {})
20+
}
1921
}
2022

2123
struct DataInfo {

0 commit comments

Comments
 (0)