From cc88c5023eb8bb38e4612469d6cb0207347fa0ea Mon Sep 17 00:00:00 2001 From: Sebastian Zivota Date: Wed, 6 Sep 2023 10:47:53 +0200 Subject: [PATCH] fix: Clippy (#810) --- symbolic-debuginfo/src/pdb.rs | 1 + symbolic-debuginfo/src/pe.rs | 12 +++++-- .../src/transform/bcsymbolmap.rs | 31 ++++++------------- 3 files changed, 20 insertions(+), 24 deletions(-) diff --git a/symbolic-debuginfo/src/pdb.rs b/symbolic-debuginfo/src/pdb.rs index a0ddb24b6..6ab50464a 100644 --- a/symbolic-debuginfo/src/pdb.rs +++ b/symbolic-debuginfo/src/pdb.rs @@ -141,6 +141,7 @@ impl<'data> PdbObject<'data> { } /// Tries to parse a PDB object from the given slice. + #[allow(clippy::arc_with_non_send_sync)] pub fn parse(data: &'data [u8]) -> Result { let mut pdb = Pdb::open(Cursor::new(data))?; let dbi = pdb.debug_information()?; diff --git a/symbolic-debuginfo/src/pe.rs b/symbolic-debuginfo/src/pe.rs index 31a6995a1..7c5c75e95 100644 --- a/symbolic-debuginfo/src/pe.rs +++ b/symbolic-debuginfo/src/pe.rs @@ -281,8 +281,12 @@ impl<'data> PeObject<'data> { /// Returns the raw buffer of Embedded Portable PDB Debug directory entry, if any. pub fn embedded_ppdb(&self) -> Result>, PeError> { // Note: This is currently not supported by goblin, see https://github.com/m4b/goblin/issues/314 - let Some(opt_header) = self.pe.header.optional_header else { return Ok(None) }; - let Some(debug_directory) = opt_header.data_directories.get_debug_table().as_ref() else { return Ok(None) }; + let Some(opt_header) = self.pe.header.optional_header else { + return Ok(None); + }; + let Some(debug_directory) = opt_header.data_directories.get_debug_table().as_ref() else { + return Ok(None); + }; let file_alignment = opt_header.windows_fields.file_alignment; let parse_options = &pe::options::ParseOptions::default(); let Some(offset) = pe::utils::find_offset( @@ -290,7 +294,9 @@ impl<'data> PeObject<'data> { &self.pe.sections, file_alignment, parse_options, - ) else { return Ok(None) }; + ) else { + return Ok(None); + }; use pe::debug::ImageDebugDirectory; let entries = debug_directory.size as usize / std::mem::size_of::(); diff --git a/symbolic-symcache/src/transform/bcsymbolmap.rs b/symbolic-symcache/src/transform/bcsymbolmap.rs index b68ed5b98..d554100d2 100644 --- a/symbolic-symcache/src/transform/bcsymbolmap.rs +++ b/symbolic-symcache/src/transform/bcsymbolmap.rs @@ -6,38 +6,27 @@ use symbolic_debuginfo::macho::BcSymbolMap; use super::{File, Function, SourceLocation, Transformer}; -// This ended up as a macro which "inlines" mapping the `Cow` into the calling function, as using -// a real function here would lead to the following borrow checker error: -// error[E0495]: cannot infer an appropriate lifetime for lifetime parameter `'d` due to conflicting requirements -macro_rules! map_cow { - ($cow:expr, $f: expr) => { - match $cow { - Cow::Borrowed(inner) => Cow::Borrowed($f(inner)), - Cow::Owned(inner) => Cow::Owned($f(&inner).to_owned()), - } - }; +fn resolve_cow<'f>(map: &'f BcSymbolMap<'_>, s: Cow<'f, str>) -> Cow<'f, str> { + match s { + Cow::Borrowed(inner) => Cow::Borrowed(map.resolve(inner)), + Cow::Owned(inner) => Cow::Owned(map.resolve(&inner).to_owned()), + } } impl Transformer for BcSymbolMap<'_> { fn transform_function<'f>(&'f mut self, f: Function<'f>) -> Function<'f> { Function { - name: map_cow!(f.name, |s| self.resolve(s)), - comp_dir: f.comp_dir.map(|dir| map_cow!(dir, |s| self.resolve(s))), + name: resolve_cow(self, f.name), + comp_dir: f.comp_dir.map(|dir| resolve_cow(self, dir)), } } fn transform_source_location<'f>(&'f mut self, sl: SourceLocation<'f>) -> SourceLocation<'f> { SourceLocation { file: File { - name: map_cow!(sl.file.name, |s| self.resolve(s)), - directory: sl - .file - .directory - .map(|dir| map_cow!(dir, |s| self.resolve(s))), - comp_dir: sl - .file - .comp_dir - .map(|dir| map_cow!(dir, |s| self.resolve(s))), + name: resolve_cow(self, sl.file.name), + directory: sl.file.directory.map(|dir| resolve_cow(self, dir)), + comp_dir: sl.file.comp_dir.map(|dir| resolve_cow(self, dir)), }, line: sl.line, }