Skip to content

Commit

Permalink
feat: Unsafe transmute for PDB symbols (#258)
Browse files Browse the repository at this point in the history
This works around compilation errors on nightly when casting to the
generic `DynIterator` type. This is caused by invariant lifetimes on
PDB's stream type. The transmute is actually safe since the lifetime of
the data is proved to be larger than the lifetime of the derived object.
  • Loading branch information
jan-auer authored Aug 21, 2020
1 parent 812ef4b commit f56d3f4
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 2 deletions.
2 changes: 1 addition & 1 deletion debuginfo/src/object.rs
Original file line number Diff line number Diff line change
Expand Up @@ -346,7 +346,7 @@ impl<'d> ObjectLike for Object<'d> {
}

fn symbols(&self) -> DynIterator<'_, Symbol<'_>> {
Box::new(self.symbols())
unsafe { std::mem::transmute(Box::new(self.symbols()) as DynIterator<'_, _>) }
}

fn has_debug_info(&self) -> bool {
Expand Down
3 changes: 2 additions & 1 deletion debuginfo/src/pdb.rs
Original file line number Diff line number Diff line change
Expand Up @@ -292,7 +292,8 @@ impl<'d> ObjectLike for PdbObject<'d> {
}

fn symbols(&self) -> DynIterator<'_, Symbol<'_>> {
Box::new(self.symbols())
// TODO: Avoid this transmute by introducing explicit lifetimes on the trait.
unsafe { std::mem::transmute(Box::new(self.symbols()) as DynIterator<'_, _>) }
}

fn symbol_map(&self) -> SymbolMap<'_> {
Expand Down

0 comments on commit f56d3f4

Please sign in to comment.