-
Notifications
You must be signed in to change notification settings - Fork 52
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
OwningRef::map
is unsound
#71
Comments
A possible fix is to use pub struct OwningRef<'t, O, T: ?Sized> {
owner: O,
reference: *const T,
marker: PhantomData<&'t T>,
} and pub struct OwningRefMut<'t, O, T: ?Sized> {
owner: O,
reference: *mut T,
marker: PhantomData<&'t T>,
} see for example the draft PR #72. |
This was referenced Aug 3, 2022
This was referenced Jan 6, 2023
This was referenced Sep 9, 2024
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Explanation
Since
supports non-
'static
types forU
andF
, we can useU == &'short T
to turninto
In the example code above,
T == str
and the call tomap
is.map(|_| &s_ref)
.Then, on the next call to
map
, you only need to provide ani.e.
Since
&'a &'short T
comes with an implicit'short: 'a
bound, you can easily turn theinto
in effect liberating yourself from the
'short
bound. The call tomap
in the example is.map(|s: &&str| *s)
.Another example
I also managed to create a general
transmute_lifetime
function:which works like this:
The text was updated successfully, but these errors were encountered: