Skip to content

Commit

Permalink
use &'a lifetime rather than &'self
Browse files Browse the repository at this point in the history
this simplifies things and eliminates a usage of `unsafe`.
  • Loading branch information
Radvendii committed Nov 6, 2023
1 parent b35b7cd commit d5970b0
Showing 1 changed file with 3 additions and 7 deletions.
10 changes: 3 additions & 7 deletions core/src/identifier.rs
Original file line number Diff line number Diff line change
Expand Up @@ -258,12 +258,8 @@ mod interner {
///
/// This operation cannot fails since the only way to have a [Symbol] is to have
/// [interned](Interner::intern) the corresponding string first.
pub(crate) fn lookup<'slf>(&'slf self, sym: Symbol) -> &'slf str {
// SAFETY: We are making the returned &str lifetime the same as our struct,
// which is okay here since the InnerInterner uses a typed_arena which prevents
// deallocations, so the reference will be valid while the InnerInterner exists,
// hence while the struct exists.
unsafe { std::mem::transmute::<&'_ str, &'slf str>(self.0.read().unwrap().lookup(sym)) }
pub(crate) fn lookup(&self, sym: Symbol) -> &'a str {
self.0.read().unwrap().lookup(sym)
}
}

Expand Down Expand Up @@ -315,7 +311,7 @@ mod interner {
///
/// This operation cannot fails since the only way to have a [Symbol]
/// is to have [interned](InnerInterner::intern) the corresponding string first.
fn lookup<'slf>(&'slf self, sym: Symbol) -> &'slf str {
fn lookup(&self, sym: Symbol) -> &'a str {
self.vec[sym.0 as usize]
}
}
Expand Down

0 comments on commit d5970b0

Please sign in to comment.