Skip to content

Commit 799971d

Browse files
committed
Migrate to Rust edition 2024
1 parent 8eef37e commit 799971d

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+151
-204
lines changed

Cargo.toml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ members = [
55
"objdiff-gui",
66
"objdiff-wasm",
77
]
8-
resolver = "2"
8+
resolver = "3"
99

1010
[profile.release-lto]
1111
inherits = "release"
@@ -16,7 +16,7 @@ codegen-units = 1
1616
[workspace.package]
1717
version = "3.0.0-beta.1"
1818
authors = ["Luke Street <luke@street.dev>"]
19-
edition = "2021"
19+
edition = "2024"
2020
license = "MIT OR Apache-2.0"
2121
repository = "https://github.com/encounter/objdiff"
22-
rust-version = "1.82"
22+
rust-version = "1.85"

objdiff-cli/src/argp_version.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
//! For now, this only adds a --version/-V option which causes early-exit.
55
use std::ffi::OsStr;
66

7-
use argp::{parser::ParseGlobalOptions, EarlyExit, FromArgs, TopLevelCommand};
7+
use argp::{EarlyExit, FromArgs, TopLevelCommand, parser::ParseGlobalOptions};
88

99
struct ArgsOrVersion<T>(T)
1010
where T: FromArgs;

objdiff-cli/src/cmd/diff.rs

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -3,40 +3,39 @@ use std::{
33
mem,
44
str::FromStr,
55
sync::{
6-
atomic::{AtomicBool, Ordering},
76
Arc,
7+
atomic::{AtomicBool, Ordering},
88
},
99
task::{Wake, Waker},
1010
time::Duration,
1111
};
1212

13-
use anyhow::{anyhow, bail, Context, Result};
13+
use anyhow::{Context, Result, anyhow, bail};
1414
use argp::FromArgs;
1515
use crossterm::{
1616
event,
1717
event::{DisableMouseCapture, EnableMouseCapture},
1818
terminal::{
19-
disable_raw_mode, enable_raw_mode, EnterAlternateScreen, LeaveAlternateScreen, SetTitle,
19+
EnterAlternateScreen, LeaveAlternateScreen, SetTitle, disable_raw_mode, enable_raw_mode,
2020
},
2121
};
2222
use objdiff_core::{
2323
bindings::diff::DiffResult,
2424
build::{
25-
watcher::{create_watcher, Watcher},
2625
BuildConfig,
26+
watcher::{Watcher, create_watcher},
2727
},
2828
config::{
29-
build_globset,
29+
ProjectConfig, ProjectObject, ProjectObjectMetadata, build_globset,
3030
path::{check_path_buf, platform_path, platform_path_serde_option},
31-
ProjectConfig, ProjectObject, ProjectObjectMetadata,
3231
},
3332
diff::{
3433
self, ConfigEnum, ConfigPropertyId, ConfigPropertyKind, DiffObjConfig, MappingConfig,
3534
ObjectDiff,
3635
},
3736
jobs::{
38-
objdiff::{start_build, ObjDiffConfig},
3937
Job, JobQueue, JobResult,
38+
objdiff::{ObjDiffConfig, start_build},
4039
},
4140
obj::{self, Object},
4241
};
@@ -45,10 +44,10 @@ use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf};
4544

4645
use crate::{
4746
util::{
48-
output::{write_output, OutputFormat},
47+
output::{OutputFormat, write_output},
4948
term::crossterm_panic_handler,
5049
},
51-
views::{function_diff::FunctionDiffUi, EventControlFlow, EventResult, UiView},
50+
views::{EventControlFlow, EventResult, UiView, function_diff::FunctionDiffUi},
5251
};
5352

5453
#[derive(FromArgs, PartialEq, Debug)]
@@ -426,15 +425,17 @@ fn run_interactive(
426425
let mut result = EventResult { redraw: true, ..Default::default() };
427426
'outer: loop {
428427
if result.redraw {
429-
terminal.draw(|f| loop {
430-
result.redraw = false;
431-
view.draw(&state, f, &mut result);
432-
result.click_xy = None;
433-
if !result.redraw {
434-
break;
428+
terminal.draw(|f| {
429+
loop {
430+
result.redraw = false;
431+
view.draw(&state, f, &mut result);
432+
result.click_xy = None;
433+
if !result.redraw {
434+
break;
435+
}
436+
// Clear buffer on redraw
437+
f.buffer_mut().reset();
435438
}
436-
// Clear buffer on redraw
437-
f.buffer_mut().reset();
438439
})?;
439440
}
440441
loop {

objdiff-cli/src/cmd/report.rs

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
use std::{collections::HashSet, fs::File, io::Read, time::Instant};
22

3-
use anyhow::{bail, Context, Result};
3+
use anyhow::{Context, Result, bail};
44
use argp::FromArgs;
55
use objdiff_core::{
66
bindings::report::{
7-
ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, Report,
8-
ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata,
9-
REPORT_VERSION,
7+
ChangeItem, ChangeItemInfo, ChangeUnit, Changes, ChangesInput, Measures, REPORT_VERSION,
8+
Report, ReportCategory, ReportItem, ReportItemMetadata, ReportUnit, ReportUnitMetadata,
109
},
1110
config::path::platform_path,
1211
diff, obj,
@@ -19,7 +18,7 @@ use typed_path::{Utf8PlatformPath, Utf8PlatformPathBuf};
1918

2019
use crate::{
2120
cmd::diff::ObjectConfig,
22-
util::output::{write_output, OutputFormat},
21+
util::output::{OutputFormat, write_output},
2322
};
2423

2524
#[derive(FromArgs, PartialEq, Debug)]
@@ -206,11 +205,7 @@ fn report_object(
206205
let section_match_percent = section_diff.match_percent.unwrap_or_else(|| {
207206
// Support cases where we don't have a target object,
208207
// assume complete means 100% match
209-
if object.complete.unwrap_or(false) {
210-
100.0
211-
} else {
212-
0.0
213-
}
208+
if object.complete.unwrap_or(false) { 100.0 } else { 0.0 }
214209
});
215210
sections.push(ReportItem {
216211
name: section.name.clone(),
@@ -251,11 +246,7 @@ fn report_object(
251246
let match_percent = symbol_diff.match_percent.unwrap_or_else(|| {
252247
// Support cases where we don't have a target object,
253248
// assume complete means 100% match
254-
if object.complete.unwrap_or(false) {
255-
100.0
256-
} else {
257-
0.0
258-
}
249+
if object.complete.unwrap_or(false) { 100.0 } else { 0.0 }
259250
});
260251
measures.fuzzy_match_percent += match_percent * symbol.size as f32;
261252
measures.total_code += symbol.size;

objdiff-cli/src/main.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ use anyhow::{Error, Result};
1717
use argp::{FromArgValue, FromArgs};
1818
use enable_ansi_support::enable_ansi_support;
1919
use supports_color::Stream;
20-
use tracing_subscriber::{filter::LevelFilter, EnvFilter};
20+
use tracing_subscriber::{EnvFilter, filter::LevelFilter};
2121

2222
#[derive(Debug, Eq, PartialEq, Copy, Clone)]
2323
enum LogLevel {

objdiff-cli/src/util/output.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use std::{
55
path::Path,
66
};
77

8-
use anyhow::{bail, Context, Result};
8+
use anyhow::{Context, Result, bail};
99
use tracing::info;
1010

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

objdiff-cli/src/util/term.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ use std::{io::stdout, panic};
33
use crossterm::{
44
cursor::Show,
55
event::DisableMouseCapture,
6-
terminal::{disable_raw_mode, LeaveAlternateScreen},
6+
terminal::{LeaveAlternateScreen, disable_raw_mode},
77
};
88

99
pub fn crossterm_panic_handler() {

objdiff-cli/src/views/function_diff.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,18 @@
11
use core::cmp::Ordering;
22

3-
use anyhow::{bail, Result};
3+
use anyhow::{Result, bail};
44
use crossterm::event::{Event, KeyCode, KeyEventKind, KeyModifiers, MouseButton, MouseEventKind};
55
use objdiff_core::{
66
diff::{
7-
display::{display_row, DiffText, DiffTextColor, HighlightKind},
87
DiffObjConfig, FunctionRelocDiffs, InstructionDiffKind, ObjectDiff, SymbolDiff,
8+
display::{DiffText, DiffTextColor, HighlightKind, display_row},
99
},
1010
obj::Object,
1111
};
1212
use ratatui::{
13+
Frame,
1314
prelude::*,
1415
widgets::{Block, Borders, Clear, Paragraph, Scrollbar, ScrollbarOrientation, ScrollbarState},
15-
Frame,
1616
};
1717

1818
use super::{EventControlFlow, EventResult, UiView};

objdiff-core/src/arch/arm.rs

Lines changed: 6 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ use alloc::{
55
vec::Vec,
66
};
77

8-
use anyhow::{bail, Result};
9-
use arm_attr::{enums::CpuArch, tag::Tag, BuildAttrs};
10-
use object::{elf, Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _};
8+
use anyhow::{Result, bail};
9+
use arm_attr::{BuildAttrs, enums::CpuArch, tag::Tag};
10+
use object::{Endian as _, Object as _, ObjectSection as _, ObjectSymbol as _, elf};
1111
use unarm::{args, arm, thumb};
1212

1313
use crate::{
1414
arch::Arch,
15-
diff::{display::InstructionPart, ArmArchVersion, ArmR9Usage, DiffObjConfig},
15+
diff::{ArmArchVersion, ArmR9Usage, DiffObjConfig, display::InstructionPart},
1616
obj::{
1717
InstructionRef, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation,
1818
ScannedInstruction, SymbolFlag, SymbolFlagSet, SymbolKind,
@@ -58,11 +58,7 @@ impl ArchArm {
5858
}
5959
// Only checking first CpuArch tag. Others may exist, but that's very unlikely.
6060
let cpu_arch = subsection.into_public_tag_iter()?.find_map(|(_, tag)| {
61-
if let Tag::CpuArch(cpu_arch) = tag {
62-
Some(cpu_arch)
63-
} else {
64-
None
65-
}
61+
if let Tag::CpuArch(cpu_arch) = tag { Some(cpu_arch) } else { None }
6662
});
6763
match cpu_arch {
6864
Some(CpuArch::V4T) => return Ok(Some(unarm::ArmVersion::V4T)),
@@ -358,11 +354,7 @@ impl Arch for ArchArm {
358354
}
359355

360356
fn symbol_address(&self, address: u64, kind: SymbolKind) -> u64 {
361-
if kind == SymbolKind::Function {
362-
address & !1
363-
} else {
364-
address
365-
}
357+
if kind == SymbolKind::Function { address & !1 } else { address }
366358
}
367359

368360
fn extra_symbol_flags(&self, symbol: &object::Symbol) -> SymbolFlagSet {

objdiff-core/src/arch/arm64.rs

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ use alloc::{
55
};
66
use core::cmp::Ordering;
77

8-
use anyhow::{bail, Result};
8+
use anyhow::{Result, bail};
99
use object::elf;
1010
use yaxpeax_arch::{Arch as YaxpeaxArch, Decoder, Reader, U8Reader};
1111
use yaxpeax_arm::armv8::a64::{
@@ -15,7 +15,7 @@ use yaxpeax_arm::armv8::a64::{
1515

1616
use crate::{
1717
arch::Arch,
18-
diff::{display::InstructionPart, DiffObjConfig},
18+
diff::{DiffObjConfig, display::InstructionPart},
1919
obj::{
2020
InstructionRef, RelocationFlags, ResolvedInstructionRef, ResolvedRelocation,
2121
ScannedInstruction,
@@ -216,11 +216,7 @@ where Cb: FnMut(InstructionPart<'static>) {
216216
unreachable!("movn operand 1 is always ImmShift");
217217
};
218218
let imm = if let Operand::Register(size, _) = ins.operands[0] {
219-
if size == SizeCode::W {
220-
imm as u32 as u64
221-
} else {
222-
imm
223-
}
219+
if size == SizeCode::W { imm as u32 as u64 } else { imm }
224220
} else {
225221
unreachable!("movn operand 0 is always Register");
226222
};
@@ -237,11 +233,7 @@ where Cb: FnMut(InstructionPart<'static>) {
237233
unreachable!("movz operand is always ImmShift");
238234
};
239235
let imm = if let Operand::Register(size, _) = ins.operands[0] {
240-
if size == SizeCode::W {
241-
imm as u32 as u64
242-
} else {
243-
imm
244-
}
236+
if size == SizeCode::W { imm as u32 as u64 } else { imm }
245237
} else {
246238
unreachable!("movz operand 0 is always Register");
247239
};
@@ -574,11 +566,7 @@ where Cb: FnMut(InstructionPart<'static>) {
574566
{
575567
if immr < imms {
576568
let size = if let Operand::Register(size, _) = ins.operands[0] {
577-
if size == SizeCode::W {
578-
32
579-
} else {
580-
64
581-
}
569+
if size == SizeCode::W { 32 } else { 64 }
582570
} else {
583571
unreachable!("operand 0 is always a register");
584572
};

0 commit comments

Comments
 (0)