diff options
| author | Mara Bos <m-ou.se@m-ou.se> | 2021-01-16 17:29:56 +0000 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2021-01-16 17:29:56 +0000 |
| commit | 5702cfa2551a56172a4e392aab4b494562242f35 (patch) | |
| tree | ae4ea8cb340bf092311100a0ec0f1d3ff2a68516 /src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs | |
| parent | 40d2506cab20cfd7df17f390ec662b22f166f0a6 (diff) | |
| parent | c14e919f1e221dd0629bd88db6db77c52e03604e (diff) | |
| download | rust-5702cfa2551a56172a4e392aab4b494562242f35.tar.gz rust-5702cfa2551a56172a4e392aab4b494562242f35.zip | |
Rollup merge of #80764 - CAD97:weak-unsized-as-ptr-again, r=RalfJung
Re-stabilize Weak::as_ptr and friends for unsized T
As per [T-lang consensus](https://hackmd.io/7r3_is6uTz-163fsOV8Vfg), this uses a branch to handle the dangling case. The discussed optimization of only doing the branch in the T: ?Sized case is left for a followup patch, as doing so is not trivial (as it requires specialization) and not _obviously_ better (as it requires using `wrapping_offset` rather than `offset` more).
<details><summary>Basically said optimization</summary>
Specialize on `T: Sized`:
```rust
fn as_ptr(&self) -> *const T {
if [ T is Sized ] || !is_dangling(ptr) {
(ptr as *mut T).set_ptr_value( (ptr as *mut u8).wrapping_offset(data_offset) )
} else {
ptr::null()
}
}
fn from_raw(*const T) -> Self {
if [ T is Sized ] || !ptr.is_null() {
let ptr = (ptr as *mut RcBox).set_ptr_value( (ptr as *mut u8).wrapping_offset(-data_offset) );
Weak { ptr }
} else {
Weak::new()
}
}
```
(but with more `set_ptr_value` to avoid `Sized` restrictions and maintain metadata.)
Written in this fashion, this is not a correctness-critical specialization (i.e. so long as `[ T is Sized ]` is false for unsized `T`, it can be `rand()` for sized `T` without breaking correctness), but it's still touchy, so I'd rather do it in another PR with separate review.
---
</details>
This effectively reverts #80422 and re-establishes #74160. T-libs [previously signed off](https://github.com/rust-lang/rust/pull/74160#issuecomment-660539373) on this stable API change in #74160.
Diffstat (limited to 'src/test/codegen/src-hash-algorithm/src-hash-algorithm-md5.rs')
0 files changed, 0 insertions, 0 deletions
