]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay
authorDylan DPC <99973273+Dylan-DPC@users.noreply.github.com>
Sat, 22 Oct 2022 10:58:09 +0000 (16:28 +0530)
committerGitHub <noreply@github.com>
Sat, 22 Oct 2022 10:58:09 +0000 (16:28 +0530)
commitb22559f547f963df83987dfcf2aeb070a84d42bf
treeab9cd6ef97c921d201cd06a8fdef3f2390707665
parent3f49f9506f124097b9f773d08248432eca625f1c
parente3606b2b0298be6122d002257b50ba42f0b4d4d2
Rollup merge of #103346 - HeroicKatora:metadata_of_const_pointer_argument, r=dtolnay

Adjust argument type for mutable with_metadata_of (#75091)

The method takes two pointer arguments: one `self` supplying the pointer value, and a second pointer supplying the metadata.

The new parameter type more clearly reflects the actual requirements. The provenance of the metadata parameter is disregarded completely. Using a mutable pointer in the call site can be coerced to a const pointer while the reverse is not true.

In some cases, the current parameter type can thus lead to a very slightly confusing additional cast. [Example](https://github.com/HeroicKatora/static-alloc/commit/cad93775eb9adc62f744651e3abf19513e69e7d0).

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = val as *const _ as *mut T;
let ptr = uninit.as_ptr().with_metadata_of(ptr);
```

This could then instead be simplified to:

```rust
// Manually taking an unsized object from a `ManuallyDrop` into another allocation.
let val: &core::mem::ManuallyDrop<T> = …;

let ptr = uninit.as_ptr().with_metadata_of(&**val);
```

Tracking issue: https://github.com/rust-lang/rust/issues/75091

``@dtolnay`` you're reviewed #95249, would you mind chiming in?