Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix unsoundness in bootstrap cache code #105624

Merged
merged 1 commit into from
Dec 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
8 changes: 4 additions & 4 deletions src/bootstrap/cache.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()) }
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We still need to unsafely transmute the lifetime from the temporary borrow on this line to the &self lifetime in the signature.

}
}

Expand Down