]> git.lizzy.rs Git - rust.git/commit
Rollup merge of #103489 - WaffleLapkin:byte_offset_from_you, r=scottmcm
authorMatthias Krüger <matthias.krueger@famsik.de>
Wed, 16 Nov 2022 07:36:10 +0000 (08:36 +0100)
committerGitHub <noreply@github.com>
Wed, 16 Nov 2022 07:36:10 +0000 (08:36 +0100)
commit91963cc244f4986818dadbb2c73dd6f67e779802
treef1c1232f5c5e2ef7e6e5788eb34b06ef02775119
parent5140bbd10258d8c0f5afb286d0fd57a296720652
parent6279d092c32bc60be2eeb91210f1d875e28b6b72
Rollup merge of #103489 - WaffleLapkin:byte_offset_from_you, r=scottmcm

Make `pointer::byte_offset_from` more generic

As suggested by https://github.com/rust-lang/rust/issues/96283#issuecomment-1288792955 (cc ````@scottmcm),```` make `pointer::byte_offset_from` work on pointers of different types. `byte_offset_from` really doesn't care about pointer types, so this is totally fine and, for example, allows patterns like this:
```rust
ptr::addr_of!(x.b).byte_offset_from(ptr::addr_of!(x))
```

The only possible downside is that this removes the `T` == `U` hint to inference, but I don't think this matter much. I don't think there are a lot of cases where you'd want to use `byte_offset_from` with a pointer of unbounded type (and in such cases you can just specify the type).

````@rustbot```` label +T-libs-api
library/core/src/ptr/const_ptr.rs
library/core/src/ptr/mut_ptr.rs