Skip to content

Commit 83a7c33

Browse files
committed
rs: apply cargo clippy
1 parent 7eaf43d commit 83a7c33

File tree

5 files changed

+21
-21
lines changed

5 files changed

+21
-21
lines changed

capstone-rs/examples/demo.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ fn arch_example(cs: &mut Capstone, code: &[u8]) -> CsResult<()> {
2727
println!("Found {} instructions", insns.len());
2828
for i in insns.iter() {
2929
println!();
30-
println!("{}", i);
30+
println!("{i}");
3131

3232
let detail: InsnDetail = cs.insn_detail(i)?;
3333
let arch_detail: ArchDetail = detail.arch_detail();
@@ -85,7 +85,7 @@ fn example() -> CsResult<()> {
8585

8686
for &mut (arch, ref mut cs, code) in examples.iter_mut() {
8787
println!("\n*************************************");
88-
println!("Architecture {}:", arch);
88+
println!("Architecture {arch}:");
8989
arch_example(cs, code)?;
9090
}
9191

@@ -94,6 +94,6 @@ fn example() -> CsResult<()> {
9494

9595
fn main() {
9696
if let Err(err) = example() {
97-
println!("Error: {}", err);
97+
println!("Error: {err}");
9898
}
9999
}

capstone-rs/src/error.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ mod test {
129129
];
130130

131131
for error in errors.iter() {
132-
println!("{}", error);
132+
println!("{error}");
133133
}
134134
}
135135
}

capstone-rs/src/instruction.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -404,9 +404,9 @@ impl Display for Insn<'_> {
404404
fn fmt(&self, fmt: &mut Formatter) -> fmt::Result {
405405
write!(fmt, "{:#x}: ", self.address())?;
406406
if let Some(mnemonic) = self.mnemonic() {
407-
write!(fmt, "{} ", mnemonic)?;
407+
write!(fmt, "{mnemonic} ")?;
408408
if let Some(op_str) = self.op_str() {
409-
write!(fmt, "{}", op_str)?;
409+
write!(fmt, "{op_str}")?;
410410
}
411411
}
412412
Ok(())
@@ -545,16 +545,16 @@ impl Display for Instructions<'_> {
545545
for instruction in self.iter() {
546546
write!(fmt, "{:x}:\t", instruction.address())?;
547547
for byte in instruction.bytes() {
548-
write!(fmt, " {:02x}", byte)?;
548+
write!(fmt, " {byte:02x}")?;
549549
}
550550
let remainder = 16 * 3 - instruction.bytes().len() * 3;
551551
for _ in 0..remainder {
552552
write!(fmt, " ")?;
553553
}
554554
if let Some(mnemonic) = instruction.mnemonic() {
555-
write!(fmt, " {}", mnemonic)?;
555+
write!(fmt, " {mnemonic}")?;
556556
if let Some(op_str) = instruction.op_str() {
557-
write!(fmt, " {}", op_str)?;
557+
write!(fmt, " {op_str}")?;
558558
}
559559
}
560560
writeln!(fmt)?;

capstone-rs/src/test.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -317,7 +317,7 @@ fn test_instruction_helper(
317317
bytes: &[u8],
318318
has_default_syntax: bool,
319319
) {
320-
println!("{:x?}", insn);
320+
println!("{insn:x?}");
321321

322322
// Check mnemonic
323323
if has_default_syntax && cfg!(feature = "full") {
@@ -908,7 +908,7 @@ fn test_invalid_mode() {
908908
#[test]
909909
fn test_capstone_version() {
910910
let (major, minor) = Capstone::lib_version();
911-
println!("Capstone lib version: ({}, {})", major, minor);
911+
println!("Capstone lib version: ({major}, {minor})");
912912
assert!(major > 0 && major < 100, "Invalid major version {}", major);
913913
assert!(minor < 500, "Invalid minor version {}", minor);
914914
}
@@ -1885,7 +1885,7 @@ fn test_arch_bpf_cbpf() {
18851885
Ok(ins) => {
18861886
for i in ins.as_ref() {
18871887
println!();
1888-
eprintln!("{}", i);
1888+
eprintln!("{i}");
18891889

18901890
let detail: InsnDetail = cs.insn_detail(i).expect("Failed to get insn detail");
18911891
let arch_detail: ArchDetail = detail.arch_detail();
@@ -1931,7 +1931,7 @@ fn test_arch_bpf_ebpf() {
19311931
Ok(ins) => {
19321932
for i in ins.as_ref() {
19331933
println!();
1934-
eprintln!("{}", i);
1934+
eprintln!("{i}");
19351935

19361936
let detail: InsnDetail = cs.insn_detail(i).expect("Failed to get insn detail");
19371937
let arch_detail: ArchDetail = detail.arch_detail();
@@ -4719,7 +4719,7 @@ fn test_arch_riscv_detail() {
47194719
&[
47204720
Reg(RegId(RISCV_REG_X11 as RegIdInt)),
47214721
Mem(RiscVOpMem(riscv_op_mem {
4722-
base: RISCV_REG_X12 as u32,
4722+
base: RISCV_REG_X12,
47234723
disp: 8,
47244724
})),
47254725
],
@@ -4956,7 +4956,7 @@ fn test_issue_175() {
49564956

49574957
let insns = cs.disasm_all(&[0x0c, 0x44, 0x3b, 0xd5], 0).unwrap();
49584958
for i in insns.as_ref() {
4959-
let id = cs.insn_detail(&i).unwrap();
4959+
let id = cs.insn_detail(i).unwrap();
49604960
let ad = id.arch_detail();
49614961
let aarch = ad.aarch64().unwrap();
49624962

cstool/src/bin/cstool.rs

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ where
2828
match self {
2929
Ok(t) => t,
3030
Err(e) => {
31-
eprintln!("error: {}", e);
31+
eprintln!("error: {e}");
3232
exit(1);
3333
}
3434
}
@@ -66,7 +66,7 @@ fn unhexed_bytes(input: Vec<u8>) -> Vec<u8> {
6666
}
6767

6868
if log::max_level() >= log::LevelFilter::Info {
69-
let output_hex: Vec<String> = output.iter().map(|x| format!("{:02x}", x)).collect();
69+
let output_hex: Vec<String> = output.iter().map(|x| format!("{x:02x}")).collect();
7070
info!("unhexed_output = {:?}", output_hex);
7171
}
7272

@@ -93,7 +93,7 @@ fn disasm<T: Iterator<Item = ExtraMode>>(
9393
let mut handle = stdout.lock();
9494

9595
for i in cs.disasm_all(code, addr).expect_exit().iter() {
96-
let bytes: Vec<_> = i.bytes().iter().map(|x| format!("{:02x}", x)).collect();
96+
let bytes: Vec<_> = i.bytes().iter().map(|x| format!("{x:02x}")).collect();
9797
let bytes = bytes.join(" ");
9898
let _ = writeln!(
9999
&mut handle,
@@ -148,19 +148,19 @@ fn main() {
148148
// Lowercase arches
149149
let arches: Vec<Str> = Arch::variants()
150150
.iter()
151-
.map(|x| format!("{}", x).to_lowercase().into())
151+
.map(|x| format!("{x}").to_lowercase().into())
152152
.collect();
153153

154154
// Lowercase modes
155155
let modes: Vec<Str> = Mode::variants()
156156
.iter()
157-
.map(|x| format!("{}", x).to_lowercase().into())
157+
.map(|x| format!("{x}").to_lowercase().into())
158158
.collect();
159159

160160
// Lowercase extra modes
161161
let extra_modes: Vec<Str> = ExtraMode::variants()
162162
.iter()
163-
.map(|x| format!("{}", x).to_lowercase().into())
163+
.map(|x| format!("{x}").to_lowercase().into())
164164
.collect();
165165

166166
let matches = Command::new("capstone-rs disassembler tool")

0 commit comments

Comments
 (0)