-
Notifications
You must be signed in to change notification settings - Fork 34
Prevent implementing both ArcCastPtr and BoxCastPtr on the same type #349
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
Comments
I think this bumps into trait coherence issues. If we have: impl<T, R> CastConstPtr for T
where
T: ArcCastPtr<RustType = R>,
{
type RustType = R;
}
impl<T, R> CastConstPtr for T
where
T: BoxCastPtr<RustType = R>,
{
type RustType = R;
} Then the compiler rejects this as a conflicting implementation of |
I spent a few hours banging my head against this and I think I made a bit of progress towards the goal of making To try and minimize my own confusion I've been implementing this separate from The major problem I'm still grappling with is how to implement |
For the casting thin pointer to a fat pointer, I think you're running into the problem I described here: #350 I think there are two reasons you're running into that: one is the I suspect the "double indirect" approach we reached in the other PR ( My recommendation for this issue is to separate the issue of representing trait objects ( |
Another attempt: https://play.rust-lang.org/?version=stable&mode=debug&edition=2021&gist=57e07a98c747a5310501c75c0de442ba (Type names haven't been given significant thought) I think this might be more workable 🤞 Actually integrating it into the codebase will probably be the real test. In particular I haven't looked at the various macros from |
Nice. I think you're exactly on the right track. I tried rewriting it with free functions, because I think the Here's my attempt: As part of it I wound up adding |
Simplifying to the one
Ahhh yes. That's much simpler to work with. Thank you.
Good ideas, thanks again. I rolled all of those changes into a PR that replaces the existing I also did my best to do a pass through all of the (crate internal) doc strings to try and make explicit some of the things I've learned with your help while working through some of this. PTAL! |
In #341 (comment) we ran into a problem: both
ArcCastPtr
andBoxCastPtr
were implemented forrustls_client_cert_verifier
. This turned out fine because only theBox
-related casts were used, but it could have turned out badly if, for instance, a pointer was created as aBox
and later (incorrectly) cast to anArc
.We should see if we can use the Rust type system to make it impossible to implement both of these for the same type.
Also, right now we have helper traits
CastPtr
/ConstConstPtr
that are trait bounds forArcCastPtr
andBoxCastPtr
. So for each C-facing type, we need to do two trait impls. We could probably simplify things by removing the trait bound, and instead adding a blanket impl ofCastConstPtr
for allArcCastPtr
and allBoxCastPtr
; and a blanket impl ofCastPtr
for allBoxCastPtr
. That way we would only need to impl one ofArcCastPtr
/BoxCastPtr
for any given Rust type:today:
future?
The text was updated successfully, but these errors were encountered: