Skip to content
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

Merged
merged 2 commits into from
Nov 21, 2024

Conversation

compiler-errors
Copy link
Member

@compiler-errors compiler-errors commented Nov 20, 2024

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>.

@rustbot
Copy link
Collaborator

rustbot commented Nov 20, 2024

r? @Nadrieril

rustbot has assigned @Nadrieril.
They will have a look at your PR within the next two weeks and either review your PR or reassign to another reviewer.

Use r? to explicitly pick a reviewer

@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver) labels Nov 20, 2024
@compiler-errors
Copy link
Member Author

r? lcnr

@rustbot rustbot assigned lcnr and unassigned Nadrieril Nov 20, 2024
@lcnr
Copy link
Contributor

lcnr commented Nov 20, 2024

cc #102425 @nikomatsakis

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

@compiler-errors
Copy link
Member Author

I added two FIXMEs.

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 20, 2024

📌 Commit 94260bd has been approved by lcnr

It is now in the queue for this repository.

@bors bors added S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. and removed S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. labels Nov 20, 2024
@compiler-errors
Copy link
Member Author

@bors r=lcnr

@bors
Copy link
Contributor

bors commented Nov 20, 2024

📌 Commit 228068b has been approved by lcnr

It is now in the queue for this repository.

matthiaskrgr added a commit to matthiaskrgr/rust that referenced this pull request Nov 20, 2024
…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>`.
bors added a commit to rust-lang-ci/rust that referenced this pull request Nov 20, 2024
…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
@bors bors merged commit fbed195 into rust-lang:master Nov 21, 2024
6 checks passed
@rustbot rustbot added this to the 1.84.0 milestone Nov 21, 2024
rust-timer added a commit to rust-lang-ci/rust that referenced this pull request Nov 21, 2024
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>`.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-bors Status: Waiting on bors to run and complete tests. Bors will change the label on completion. T-compiler Relevant to the compiler team, which will review and decide on the PR/issue. T-libs Relevant to the library team, which will review and decide on the PR/issue. WG-trait-system-refactor The Rustc Trait System Refactor Initiative (-Znext-solver)
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants