]> git.lizzy.rs Git - rust.git/commitdiff
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)
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

1  2 
library/core/src/ptr/const_ptr.rs
library/core/src/ptr/mut_ptr.rs

Simple merge
Simple merge