Skip to content

Commit fa9132c

Browse files
committed
more clippy fixes
1 parent fb3bfaf commit fa9132c

File tree

4 files changed

+40
-52
lines changed

4 files changed

+40
-52
lines changed

src/elf.rs

Lines changed: 6 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -631,21 +631,16 @@ impl LibraryLookup {
631631
runpath: &VecRpath,
632632
libfilename: &str,
633633
) -> Option<PathBuf> {
634-
let parentbinpath = if let Some(parent) = binarypath.parent() {
635-
parent.to_str()
636-
} else {
637-
None
638-
};
634+
let parentbinpath =
635+
binarypath.parent().and_then(|parent| parent.to_str());
639636

640637
for rpath in rpath.iter().filter_map(|rpath| match rpath {
641638
Rpath::YesRW(ref str) | Rpath::Yes(ref str) => Some(str),
642639
Rpath::None => None,
643640
}) {
644-
let rpath = if let Some(p) = parentbinpath {
641+
let rpath = parentbinpath.map_or(Either::Right(rpath), |p| {
645642
Either::Left(rpath.replace("$ORIGIN", p))
646-
} else {
647-
Either::Right(rpath)
648-
};
643+
});
649644
let path = Path::new(&rpath).join(libfilename);
650645
if path.is_file() {
651646
return Some(path);
@@ -661,11 +656,9 @@ impl LibraryLookup {
661656

662657
Rpath::None => None,
663658
}) {
664-
let runpath = if let Some(p) = parentbinpath {
659+
let runpath = parentbinpath.map_or(Either::Right(runpath), |p| {
665660
Either::Left(runpath.replace("$ORIGIN", p))
666-
} else {
667-
Either::Right(runpath)
668-
};
661+
});
669662
let path = Path::new(&runpath).join(libfilename);
670663
if path.is_file() {
671664
return Some(path);

src/ldso.rs

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl fmt::Display for LdSoError {
5353

5454
impl From<io::Error> for LdSoError {
5555
fn from(e: io::Error) -> Self {
56-
LdSoError::IO(e)
56+
Self::IO(e)
5757
}
5858
}
5959

@@ -88,12 +88,10 @@ impl LdSoLookup {
8888
let file = file.map_err(|e| {
8989
LdSoError::Glob(e, PathBuf::from(include_path))
9090
})?;
91-
lookup_paths.append(
92-
&mut LdSoLookup::parse_ldso_conf_file(
93-
&file,
94-
include_depth + 1,
95-
)?,
96-
);
91+
lookup_paths.append(&mut Self::parse_ldso_conf_file(
92+
&file,
93+
include_depth + 1,
94+
)?);
9795
}
9896
continue;
9997
}
@@ -119,9 +117,9 @@ impl LdSoLookup {
119117
/// # Errors
120118
/// Will fail if the ld.so.conf configuration can not be read or has an
121119
/// invalid format.
122-
pub fn gen_lookup_dirs() -> Result<LdSoLookup, LdSoError> {
123-
Ok(LdSoLookup {
124-
lookup_dirs: LdSoLookup::parse_ldso_conf_file(
120+
pub fn gen_lookup_dirs() -> Result<Self, LdSoError> {
121+
Ok(Self {
122+
lookup_dirs: Self::parse_ldso_conf_file(
125123
Path::new("/etc/ld.so.conf"),
126124
0,
127125
)?,

src/main.rs

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -301,8 +301,8 @@ impl From<std::io::Error> for ParseError {
301301

302302
#[cfg(all(target_os = "linux", feature = "elf"))]
303303
impl From<LdSoError> for ParseError {
304-
fn from(err: LdSoError) -> ParseError {
305-
ParseError::LdSo(err)
304+
fn from(err: LdSoError) -> Self {
305+
Self::LdSo(err)
306306
}
307307
}
308308

@@ -533,18 +533,16 @@ fn parse_dependencies(
533533
while !to_scan.is_empty() {
534534
let mut results: Vec<Binary> = to_scan
535535
.par_iter()
536-
.filter_map(|lib| {
537-
match parse(lib, &mut cache.as_ref().map(Arc::clone)) {
538-
Ok(bins) => Some(bins),
539-
Err(err) => {
540-
eprintln!(
541-
"Failed to parse {} for {}: {}",
542-
lib.display(),
543-
binary.file.display(),
544-
err
545-
);
546-
None
547-
}
536+
.filter_map(|lib| match parse(lib, &mut cache.clone()) {
537+
Ok(bins) => Some(bins),
538+
Err(err) => {
539+
eprintln!(
540+
"Failed to parse {} for {}: {}",
541+
lib.display(),
542+
binary.file.display(),
543+
err
544+
);
545+
None
548546
}
549547
})
550548
.flatten()
@@ -640,7 +638,7 @@ fn walk(
640638
#[cfg(all(feature = "maps", target_os = "linux"))]
641639
fn parse_process_libraries(
642640
process: &sysinfo::Process,
643-
cache: &mut Option<Cache>,
641+
cache: &Option<Cache>,
644642
) -> Result<Vec<Binary>, std::io::Error> {
645643
Ok(Process::parse_maps(process.pid().as_u32() as usize)?
646644
.into_iter()
@@ -657,7 +655,7 @@ fn parse_process_libraries(
657655
match file_name.strip_suffix(" (deleted)") {
658656
Some(s) => {
659657
let mut pb = PathBuf::from(
660-
p.parent().unwrap_or(Path::new("/")),
658+
p.parent().unwrap_or_else(|| Path::new("/")),
661659
);
662660
pb.push(s);
663661
Either::Left(pb)
@@ -672,7 +670,7 @@ fn parse_process_libraries(
672670
.unique()
673671
.par_bridge()
674672
.filter_map(|p| {
675-
parse(&p, &mut cache.as_ref().map(Arc::clone))
673+
parse(&p, &mut cache.clone())
676674
.map_err(|err| {
677675
if let ParseError::IO(ref e) = err {
678676
if e.kind() == ErrorKind::NotFound
@@ -698,7 +696,7 @@ fn parse_process_libraries(
698696
#[cfg(not(all(feature = "maps", target_os = "linux")))]
699697
fn parse_process_libraries(
700698
_process: &sysinfo::Process,
701-
_cache: &mut Option<Cache>,
699+
_cache: &Option<Cache>,
702700
) -> Result<Vec<Binary>, std::io::Error> {
703701
Err(std::io::Error::new(
704702
ErrorKind::Unsupported,
@@ -743,7 +741,7 @@ where
743741
if scan_dynlibs {
744742
parse_process_libraries(
745743
process,
746-
&mut Some(Arc::clone(&cache)),
744+
&Some(Arc::clone(&cache)),
747745
)
748746
.ok()
749747
} else {

src/proc.rs

Lines changed: 9 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ pub struct Region {
7878
}
7979
#[cfg(all(feature = "maps", any(target_os = "linux", target_os = "windows")))]
8080
impl Region {
81-
pub fn new(start: usize, end: usize) -> Self {
81+
pub const fn new(start: usize, end: usize) -> Self {
8282
Self { start, end }
8383
}
8484
}
@@ -270,10 +270,10 @@ impl fmt::Display for MapEntry {
270270
self.region.start, self.region.end, self.flags
271271
)
272272
.red(),
273-
match &self.pathname {
274-
Some(pathname) => pathname.display().to_string().red(),
275-
None => String::new().red(),
276-
}
273+
self.pathname.as_ref().map_or_else(
274+
|| String::new().red(),
275+
|pathname| pathname.display().to_string().red()
276+
)
277277
)
278278
} else {
279279
write!(
@@ -282,10 +282,9 @@ impl fmt::Display for MapEntry {
282282
self.region.start,
283283
self.region.end,
284284
self.flags,
285-
match &self.pathname {
286-
Some(pathname) => pathname.display().to_string(),
287-
None => String::new(),
288-
}
285+
self.pathname.as_ref().map_or_else(String::new, |pathname| {
286+
pathname.display().to_string()
287+
})
289288
)
290289
}
291290
}
@@ -366,7 +365,7 @@ impl Process {
366365
binary: Binary,
367366
libraries: Option<Vec<Binary>>,
368367
) -> Self {
369-
match Process::parse_maps(pid) {
368+
match Self::parse_maps(pid) {
370369
Ok(maps) => Self { pid, binary, maps: Some(maps), libraries },
371370
Err(e) => {
372371
eprintln!(

0 commit comments

Comments
 (0)