-
Notifications
You must be signed in to change notification settings - Fork 12.7k
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
Support T: ?Sized in Weak::new() #50513
Comments
I don’t see why not. I’d r+ a PR. |
I don't see how that's possible for arbitrary DSTs. Constructing the Of course, it could easily be done for |
@rkruppe this is Weak::new, not Rc::new. Weak::new makes a weak reference that does not refer to any T. So there should not need to exist an actual T or vtable. |
Weak refers to an |
Additionally, |
This is a good point @rkuppe, I should have thought of it :) |
Yep you are right. If custom DSTs were required a way to synthesize an arbitrary but unusable metadata, that would be useful both here and for extending |
That sort of operation seems dubious to me. For example, if we ever add any sort of reflection based on vtable contents (even if opt in), the choice of "arbitrary" vtable will leak to users. Similarly, I suspect there might be reasonable custom DSTs that can't really oblige this requirement (e.g. if the metadata is a handle into some out-of-line data structure). |
Okay I buy that. I think that means I give up on this issue. 😸 Thanks for the justifications! |
I think this should be revisited: I don't buy @hanna-kruppe's argument about reflection, because IMO, any reflection machinery which allows you to obtain metadata from a de-allocated Weak pointer is broken. Weak should be treated like an This is discussed further in the UCG repo but the consensus seems to be that at the moment the only validity requirement on the vtable pointer is that it be non-null. Therefore, it would be valid to implement this method by storing any non-zero value in the vtable portion of the pointer. |
Note that #73845 by @CAD97 relies on unsized
Yes, but that is a "what rustc happens to do" kind of situation. Before we rely on it for a stable API, we should have it RFC'd or FCP'd by the lang team at least. |
The functionality doesn't strictly rely on unsized It does, however, require that the metadata is "real" for DSTs, so a dangling vtable would be UB in those methods as implemented. They could always be adjusted to explicitly check for the sentinel value, however, and avoid using the metadata in that case. |
The
std::rc::Weak::new
andstd::sync::Weak::new
constructors added in #30467 should be able to work withT: ?Sized
.The text was updated successfully, but these errors were encountered: