Skip to content

Commit 40bf077

Browse files
authored
Please Clippy (#29)
* Please Clippy - empty String is being created manually - the borrowed expression implements the required traits - ignore clippy::manual_let_else for now, requires rustc 1.65.0 * Use variables directly in the format string
1 parent b562f26 commit 40bf077

File tree

3 files changed

+23
-23
lines changed

3 files changed

+23
-23
lines changed

src/binary.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,11 @@ impl fmt::Display for BinSpecificProperties {
7878
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
7979
match self {
8080
#[cfg(feature = "elf")]
81-
Self::Elf(b) => write!(f, "{}", b),
81+
Self::Elf(b) => write!(f, "{b}"),
8282
#[cfg(feature = "pe")]
83-
Self::PE(b) => write!(f, "{}", b),
83+
Self::PE(b) => write!(f, "{b}"),
8484
#[cfg(feature = "macho")]
85-
Self::MachO(b) => write!(f, "{}", b),
85+
Self::MachO(b) => write!(f, "{b}"),
8686
}
8787
}
8888
}

src/main.rs

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,6 @@
11
#![warn(clippy::pedantic)]
2+
// Do not require 1.65.0
3+
#![allow(clippy::manual_let_else)]
24
extern crate clap;
35
extern crate core;
46
extern crate goblin;
@@ -57,19 +59,19 @@ fn print_binary_results(binaries: &Binaries, settings: &output::Settings) {
5759
if let Ok(colored_json) =
5860
to_colored_json_auto(&json!(binaries))
5961
{
60-
println!("{}", colored_json);
62+
println!("{colored_json}");
6163
}
6264
} else if let Ok(json_str) = to_string_pretty(&json!(binaries)) {
63-
println!("{}", json_str);
65+
println!("{json_str}");
6466
}
6567
#[cfg(not(feature = "color"))]
6668
if let Ok(json_str) = to_string_pretty(&json!(binaries)) {
67-
println!("{}", json_str);
69+
println!("{json_str}");
6870
}
6971
}
7072
output::Format::Text => {
7173
for binary in &binaries.binaries {
72-
println!("{}", binary);
74+
println!("{binary}");
7375
}
7476
}
7577
}
@@ -86,14 +88,14 @@ fn print_process_results(processes: &Processes, settings: &output::Settings) {
8688
if let Ok(colored_json) =
8789
to_colored_json_auto(&json!(processes))
8890
{
89-
println!("{}", colored_json);
91+
println!("{colored_json}");
9092
}
9193
} else if let Ok(json_str) = to_string_pretty(&json!(processes)) {
92-
println!("{}", json_str);
94+
println!("{json_str}");
9395
}
9496
#[cfg(not(feature = "color"))]
9597
if let Ok(json_str) = to_string_pretty(&json!(processes)) {
96-
println!("{}", json_str);
98+
println!("{json_str}");
9799
}
98100
}
99101
output::Format::Text => {
@@ -118,7 +120,7 @@ fn print_process_results(processes: &Processes, settings: &output::Settings) {
118120
if let Some(maps) = &process.maps {
119121
println!("{:>12}", "\u{21aa} Maps:");
120122
for map in maps {
121-
println!("\t{}", map);
123+
println!("\t{map}");
122124
}
123125
}
124126
}
@@ -140,7 +142,7 @@ impl fmt::Display for ParseError {
140142
Self::Goblin(e) => e.fmt(f),
141143
Self::IO(e) => e.fmt(f),
142144
Self::Unimplemented(str) => {
143-
write!(f, "Support for files of type {} not implemented", str)
145+
write!(f, "Support for files of type {str} not implemented")
144146
}
145147
}
146148
}
@@ -315,7 +317,7 @@ fn main() {
315317
.requires("pid")
316318
.requires("process")
317319
.requires("process-all")
318-
.conflicts_with_all(&["directory", "file"]),
320+
.conflicts_with_all(["directory", "file"]),
319321
)
320322
.arg(
321323
Arg::new("no-color")
@@ -355,7 +357,7 @@ fn main() {
355357
)
356358
.group(
357359
ArgGroup::new("operation")
358-
.args(&["directory", "file", "pid", "process", "process-all"])
360+
.args(["directory", "file", "pid", "process", "process-all"])
359361
.required(true),
360362
)
361363
.get_matches();
@@ -401,7 +403,7 @@ fn main() {
401403
.map(|id| match id.parse::<sysinfo::Pid>() {
402404
Ok(id) => id,
403405
Err(msg) => {
404-
eprintln!("Invalid process ID {}: {}", id, msg);
406+
eprintln!("Invalid process ID {id}: {msg}");
405407
process::exit(1);
406408
}
407409
})
@@ -416,7 +418,7 @@ fn main() {
416418
let process = if let Some(process) = system.process(procid) {
417419
process
418420
} else {
419-
eprintln!("No process found with ID {}", procid);
421+
eprintln!("No process found with ID {procid}");
420422
continue;
421423
};
422424

@@ -463,7 +465,7 @@ fn main() {
463465
}
464466
}
465467
if procs.is_empty() {
466-
eprintln!("No process found matching name {}", procname);
468+
eprintln!("No process found matching name {procname}");
467469
process::exit(1);
468470
}
469471
print_process_results(&Processes::new(procs), &settings);

src/proc.rs

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -272,7 +272,7 @@ impl fmt::Display for MapEntry {
272272
.red(),
273273
match &self.pathname {
274274
Some(pathname) => pathname.display().to_string().red(),
275-
None => "".to_string().red(),
275+
None => String::new().red(),
276276
}
277277
)
278278
} else {
@@ -284,7 +284,7 @@ impl fmt::Display for MapEntry {
284284
self.flags,
285285
match &self.pathname {
286286
Some(pathname) => pathname.display().to_string(),
287-
None => "".to_string(),
287+
None => String::new(),
288288
}
289289
)
290290
}
@@ -361,8 +361,7 @@ impl Process {
361361
Ok(maps) => Self { pid, binary, maps: Some(maps) },
362362
Err(e) => {
363363
eprintln!(
364-
"Failed to parse maps for process with ID {}: {}",
365-
pid, e
364+
"Failed to parse maps for process with ID {pid}: {e}"
366365
);
367366
Self { pid, binary, maps: None }
368367
}
@@ -371,8 +370,7 @@ impl Process {
371370
#[cfg(all(feature = "maps", target_os = "linux"))]
372371
pub fn parse_maps(pid: usize) -> Result<Vec<MapEntry>, Error> {
373372
let mut maps = Vec::new();
374-
for line in fs::read_to_string(format!("/proc/{}/maps", pid))?.lines()
375-
{
373+
for line in fs::read_to_string(format!("/proc/{pid}/maps"))?.lines() {
376374
let mut split_line = line.split_whitespace();
377375
let (start_str, end_str) = split_line
378376
.next()

0 commit comments

Comments
 (0)