Rollup merge of #105624 - compiler-errors:cache-unsound, r=jyn514

Fix unsoundness in bootstrap cache code

Discovered via #105575, which showed that rustc was failing to build during a perf run.
This commit is contained in:
Matthias Krüger 2022-12-14 17:17:58 +01:00 committed by GitHub
commit 0e861ccb9e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -89,16 +89,16 @@ impl<T: Internable + Hash> Hash for Interned<T> {
impl<T: Internable + Deref> Deref for Interned<T> {
type Target = T::Target;
fn deref(&self) -> &'static Self::Target {
fn deref(&self) -> &Self::Target {
let l = T::intern_cache().lock().unwrap();
unsafe { mem::transmute::<&Self::Target, &'static Self::Target>(l.get(*self)) }
unsafe { mem::transmute::<&Self::Target, &Self::Target>(l.get(*self)) }
}
}
impl<T: Internable + AsRef<U>, U: ?Sized> AsRef<U> for Interned<T> {
fn as_ref(&self) -> &'static U {
fn as_ref(&self) -> &U {
let l = T::intern_cache().lock().unwrap();
unsafe { mem::transmute::<&U, &'static U>(l.get(*self).as_ref()) }
unsafe { mem::transmute::<&U, &U>(l.get(*self).as_ref()) }
}
}