You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
partial fix for #1
By implementing a function that rebind the lifetime of values we're
forcing the compiler to check that the types are covariant
Signed-off-by: Petros Angelatos <[email protected]>
@dtolnay thank you so much for taking a look! I was planning of posting about this method in the forum soon after improving the explanation.
Regarding the issue, I added a rebind method that rebinds values (whereas the Rebind type alias rebinds types). The generated implementation looks like this:
The above acts as a covariance proof as it only typechecks if SomeType is covariant over its lifetimes and so the compiler will now complain if you attempt to implement this trait on a contravariant or invariant type.
However, the same approach doesn't work for mutable references because a &mut self receiver is invariant over the lifetime of self. I need to think about it more so for now I have removed the implementation of as_mut().
I'm curious of your thoughts on the general approach though, specifically if it is fundamentally unsound or if there is something along these lines.
Here is an example of Undefined Behavior (use after free) in safe code caused by escher.
This should print a variety of interesting characters, such as:
To provoke a segfault instead, you can replace
s.as_ptr()
with0usize
.The text was updated successfully, but these errors were encountered: