]> git.lizzy.rs Git - rust.git/commit - src/tools/clippy
Rollup merge of #60766 - vorner:weak-into-raw, r=sfackler
authorMazdak Farrokhzad <twingoow@gmail.com>
Wed, 29 May 2019 06:15:53 +0000 (08:15 +0200)
committerGitHub <noreply@github.com>
Wed, 29 May 2019 06:15:53 +0000 (08:15 +0200)
commitcb012a0430c4448ac1bb6be38b3186e80ba4bcb4
tree7cd38e2a8da4eab37b082b4694e7880f5b818cb9
parent23b9b8320b97adbd3c7c3c3b939d5d162801d9c0
parent4f1dcb34dffc26a23fa8c2cac69a31d7557fd173
Rollup merge of #60766 - vorner:weak-into-raw, r=sfackler

Weak::into_raw

Hello

This is my first shot at #60728. I'd like to consult it a bit before moving further.

The biggest question I have is if this API makes sense. My motivation for it is to be able to store the `Weak` in `AtomicPtr`. For that I don't actually need for the pointer to point to the `T`, any pointer (maybe casted to `usize`) would be good enough, but this mirrors what `Arc` does and could be useful for other things too (like comparing if Arc and Weak point to the same thing without playing with the counts), while some opaque pointer wouldn't.

Some secondary questions, if this is deemed desirable are:
* The weak pointer may be dangling if it is created by `Weak::new()`. It would make sense to treat this as NULL, but that is incompatible with `T: ?Sized` ‒ both `new()` and `ptr::null()` are available only for sized types. The current implementation is therefore also available only for sized `T`s. It would be possible to allow `?Sized` if the API would be `fn into_raw(self) -> Option<NonNull<T>>` and `fn from_raw(NonNull<T>)`, but that's different API than `Arc` has. What would be preferred?
* There's a FIXME in my code about what I suspect could be UB. Is it really UB & how to get the pointer correctly? Is manual offsetting of the pointer the only way?
* Am I missing some other necessary thing around the feature gates and such?
* Is the documentation understandable? I know writing docs is not my strongest skill :-|.

Thinks I'd like to do as part of the PR, but are not yet done:
* Turn the referenced issue into tracking issue for the feature flag.
* Once the `sync::Weak` is considered reasonable, I'd do the equivalent for `rc::Weak`.
* This might call for few more tests than what is currently part of the documentation.