-
Notifications
You must be signed in to change notification settings - Fork 12.8k
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
Can Weak be null? #114517
Comments
I don't think there's a discrepancy here? The documentation says that the method isn't guaranteed to return a non-null pointer. The current implementation happens to never return a null pointer due to an internal detail (using (For example, changing the implementation to return a null pointer in some circumstances would not be a breaking change, because the documented behaviour allows that possibility, even though the current implementation doesn't exercise it.) |
Yeah, the key point is that |
Good point, makes sense.
This is not written anywhere in the docs of I think there is a small, but non zero chance that when people read that the output of I'll make a PR to improve the docs. |
PR filed: #114525 |
There is a discrepancy between the docs of
Weak
and its implementation, originally found by @Urgau in #114494 (comment) .On one hand, the docs of Weak::as_ptr state:
On the other hand, the implementation of
Weak
usesNonNull
:rust/library/alloc/src/rc.rs
Lines 2681 to 2693 in 1cabb8e
From what I know, it is okay for
NonNull
pointers to be dangling or unaligned, but, staying true to their name, they are never allowed to be null pointers.I think this discrepancy should be resolved, but I wonder, which way? Should the docs be adjusted, or the implementation?
The issue exists both with
alloc::sync::Weak
as well asalloc::rc::Weak
.The text was updated successfully, but these errors were encountered: