Skip to content

Commit

Permalink
fix: Clippy (#810)
Browse files Browse the repository at this point in the history
  • Loading branch information
loewenheim authored Sep 6, 2023
1 parent 11472bf commit cc88c50
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 24 deletions.
1 change: 1 addition & 0 deletions symbolic-debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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<Self, PdbError> {
let mut pdb = Pdb::open(Cursor::new(data))?;
let dbi = pdb.debug_information()?;
Expand Down
12 changes: 9 additions & 3 deletions symbolic-debuginfo/src/pe.rs
Original file line number Diff line number Diff line change
Expand Up @@ -281,16 +281,22 @@ impl<'data> PeObject<'data> {
/// Returns the raw buffer of Embedded Portable PDB Debug directory entry, if any.
pub fn embedded_ppdb(&self) -> Result<Option<PeEmbeddedPortablePDB<'data>>, 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(
debug_directory.virtual_address as usize,
&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::<ImageDebugDirectory>();
Expand Down
31 changes: 10 additions & 21 deletions symbolic-symcache/src/transform/bcsymbolmap.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
}
Expand Down

0 comments on commit cc88c50

Please sign in to comment.