-
Notifications
You must be signed in to change notification settings - Fork 12.8k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Make PointerLike
opt-in instead of built-in
#133226
Conversation
r? @Nadrieril rustbot has assigned @Nadrieril. Use |
r? lcnr |
this seems reasonable to me and r=me on the impl after nits, idk about the lang side here 😁 I agree with the backcompat concerns, I feel like layout cycles are something we can definitely solve in the solver |
ccfe08a
to
94260bd
Compare
I added two FIXMEs. @bors r=lcnr |
94260bd
to
228068b
Compare
@bors r=lcnr |
…e, r=lcnr Make `PointerLike` opt-in instead of built-in The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles. This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it. On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles. Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
…iaskrgr Rollup of 6 pull requests Successful merges: - rust-lang#129838 (uefi: process: Add args support) - rust-lang#130800 (Mark `get_mut` and `set_position` in `std::io::Cursor` as const.) - rust-lang#132708 (Point at `const` definition when used instead of a binding in a `let` statement) - rust-lang#133226 (Make `PointerLike` opt-in instead of built-in) - rust-lang#133244 (Account for `wasm32v1-none` when exporting TLS symbols) - rust-lang#133257 (Add `UnordMap::clear` method) r? `@ghost` `@rustbot` modify labels: rollup
Rollup merge of rust-lang#133226 - compiler-errors:opt-in-pointer-like, r=lcnr Make `PointerLike` opt-in instead of built-in The `PointerLike` trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, calling `layout_of` in the trait system also causes cycles. This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be `derive()`d for custom smart pointers, and we can trust *that* as a semver promise rather than risking library authors accidentally breaking it. On the other hand, we may never expose `PointerLike`, but at least now the implementation doesn't invoke `layout_of` which could cause ICEs or cause cycles. Right now for a `PointerLike` impl to be valid, it must be an ADT that is `repr(transparent)` and the non-1zst field needs to implement `PointerLike`. There are also some primitive impls for `&T`/ `&mut T`/`*const T`/`*mut T`/`Box<T>`.
The
PointerLike
trait currently is a built-in trait that computes the layout of the type. This is a bit problematic, because types implement this trait automatically. Since this can be broken due to semver-compatible changes to a type's layout, this is undesirable. Also, callinglayout_of
in the trait system also causes cycles.This PR makes the trait implemented via regular impls, and adds additional validation on top to make sure that those impls are valid. This could eventually be
derive()
d for custom smart pointers, and we can trust that as a semver promise rather than risking library authors accidentally breaking it.On the other hand, we may never expose
PointerLike
, but at least now the implementation doesn't invokelayout_of
which could cause ICEs or cause cycles.Right now for a
PointerLike
impl to be valid, it must be an ADT that isrepr(transparent)
and the non-1zst field needs to implementPointerLike
. There are also some primitive impls for&T
/&mut T
/*const T
/*mut T
/Box<T>
.