Skip to content

Commit 42a0556

Browse files
committed
use &'a lifetime rather than &'self
this simplifies things and eliminates a usage of `unsafe`.
1 parent 2535b97 commit 42a0556

File tree

1 file changed

+3
-7
lines changed

1 file changed

+3
-7
lines changed

core/src/identifier.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -258,12 +258,8 @@ mod interner {
258258
///
259259
/// This operation cannot fails since the only way to have a [Symbol] is to have
260260
/// [interned](Interner::intern) the corresponding string first.
261-
pub(crate) fn lookup<'slf>(&'slf self, sym: Symbol) -> &'slf str {
262-
// SAFETY: We are making the returned &str lifetime the same as our struct,
263-
// which is okay here since the InnerInterner uses a typed_arena which prevents
264-
// deallocations, so the reference will be valid while the InnerInterner exists,
265-
// hence while the struct exists.
266-
unsafe { std::mem::transmute::<&'_ str, &'slf str>(self.0.read().unwrap().lookup(sym)) }
261+
pub(crate) fn lookup(&self, sym: Symbol) -> &'a str {
262+
self.0.read().unwrap().lookup(sym)
267263
}
268264
}
269265

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

0 commit comments

Comments
 (0)