-
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
Footgun with Rc::assume_init and related methods #131861
Comments
If we
|
eg. |
That's a good point. Luckily, there are some factors that work against this happening by accident:
Of course, it would still be good to put this non-obvious gotchas, especially around |
Right - I think the std library should be opinionated here - ie. either say that it's an error to call |
Location
I came across https://doc.rust-lang.org/nightly/std/rc/struct.Rc.html#method.assume_init recently, and spotted a footgun that I think ought to be called out:
Summary
The safety section does not clarify whether multiple
Rc
s are allowed to exist whenassume_init
is called. If they are, then whetherDrop
is called on the inner value will depend on the drop order of thoseRc
s. In the case ofArc
this might well be non-deterministic.IMO, the documentation should specify whether this is allowed, and if so should point out that callers must take care around this potential issue.
The text was updated successfully, but these errors were encountered: