Skip to content

Update UnsafeUnpin impls involving extern types.#152646

Merged
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
zachs18:unsafeunpin-marker-impls-pointee
Mar 9, 2026
Merged

Update UnsafeUnpin impls involving extern types.#152646
rust-bors[bot] merged 1 commit intorust-lang:mainfrom
zachs18:unsafeunpin-marker-impls-pointee

Conversation

@zachs18
Copy link
Contributor

@zachs18 zachs18 commented Feb 15, 2026

UnsafeUnpin tracking issue: #125735

Relaxes from T: ?Sized (i.e. T: MetaSized) to T: PointeeSized for the UnsafeUnpin impls for pointers, references, and PhantomData<T>, and for the negative UnsafeUnpin impl for UnsafePinned<T>. (Compare to the impls for Freeze on lines 911-921.)

Both UnsafeUnpin and extern types (the only way to have a !MetaSized type) are unstable, so this should have no effect on stable code.

Also updates the marker_impls macro docs to use PointeeSized bound, as most uses of the macro now do.

Concretely, this change means that the following types will newly implement UnsafeUnpin:

  • pointers and references to T where T is an extern type
  • PhantomData<T> where T is an extern type
  • either of the above where T is a struct or tuple with extern type tail

Additionally, the negative UnsafeUnpin impl for UnsafePinned<T> is also relaxed to T: PointeeSized to align with the analogous negative Freeze impl for UnsafeCell<T>, even though both structs have T: ?Sized in their declaration (which probably should be relaxed, but that is a separate issue), so this part of the change doesn't actually do anything currently, but if UnsafeCell and UnsafePinned are later relaxed to T: PointeeSized, then the negative impl will apply to the newly possible instantiations. Also cc #152645 that these impls compile at all.

Also updates the marker_impls macro docs to use PointeeSized bound, as most uses of the macro now do.
@rustbot rustbot added S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. T-libs Relevant to the library team, which will review and decide on the PR/issue. labels Feb 15, 2026
@rustbot
Copy link
Collaborator

rustbot commented Feb 15, 2026

r? @jhpratt

rustbot has assigned @jhpratt.
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

Why was this reviewer chosen?

The reviewer was selected based on:

  • Owners of files modified in this PR: @scottmcm, libs
  • @scottmcm, libs expanded to 8 candidates
  • Random selection from Mark-Simulacrum, jhpratt, joboet, scottmcm

@jhpratt
Copy link
Member

jhpratt commented Feb 19, 2026

I'm unfamiliar with the Sized hierarchy proposal

@rustbot reroll

@rustbot rustbot assigned Mark-Simulacrum and unassigned jhpratt Feb 19, 2026
@Mark-Simulacrum
Copy link
Member

I see in the tracking issue for Sized hierarchy (#144404) this note:

There is a default MetaSized supertrait which prevents traits from being implemented on extern types unless this was considered by the definition of the trait.

This implies to me that either this isn't effective or there's something special about UnsafeUnpin's trait (maybe the fact it's auto) that invalidates that line?

Am I correctly interpreting that PointeeSized is the 'lowest rung' of the ladder currently proposed? It's confusing to me that the RFC's current text (https://github.com/davidtwco/rfcs/blob/sized-hierarchy/text/3729-sized-hierarchy.md#guide-level-explanation) has Sized, MetaSized, and Pointee, but doesn't seem to have a PointeeSized (it makes no mention of PointeeSized at all!).

cc @davidtwco

@zachs18
Copy link
Contributor Author

zachs18 commented Feb 23, 2026

I see in the tracking issue for Sized hierarchy (#144404) this note:

There is a default MetaSized supertrait which prevents traits from being implemented on extern types unless this was considered by the definition of the trait.

This implies to me that either this isn't effective or there's something special about UnsafeUnpin's trait (maybe the fact it's auto) that invalidates that line?

Yes, auto traits do not have a MetaSized default bound (playground). IIUC, that is intentional because the "normal" way to opt-out of the default MetaSized bound (by adding a : PointeeSized supertrait bound) doesn't work for auto traits since supertrait bounds are rejected for auto traits1.

Either way, this would not affect the impls for PhantomData<T>, references, or pointers, as those are always Sized regardless of T.

This would be important for the UnsafePinned<T> negative impl... if UnsafePinned<T> allowed T: PointeeSized, but it doesn't, and the fact that this changed impl compiles at all is #152645 which also affects the existing UnsafeCell<T> negative Freeze impl. I could split the UnsafePinned<T> change into a separate PR if that seems better, since the pointer/reference/PhantomData changes shouldn't be affected by the question of #152645 .

Am I correctly interpreting that PointeeSized is the 'lowest rung' of the ladder currently proposed? It's confusing to me that the RFC's current text (https://github.com/davidtwco/rfcs/blob/sized-hierarchy/text/3729-sized-hierarchy.md#guide-level-explanation) has Sized, MetaSized, and Pointee, but doesn't seem to have a PointeeSized (it makes no mention of PointeeSized at all!).

Yes, my understanding is that the name PointeeSized was chosen for the unstable impl instead of Pointee to not cause confusion/conflicts with the existing std::ptr::Pointee, ("PointeeSized is a different name from the RFC just to make it more obvious that it is different from std::ptr::Pointee but all the names are yet to be bikeshed anyway." from the initial PR).


Footnotes

  1. https://github.com/rust-lang/rust/blob/main/compiler/rustc_hir_analysis/src/hir_ty_lowering/bounds.rs#L188 says that the reasoning for auto traits not having a default : MetaSized bound is "Don't add default sizedness supertraits to auto traits because it isn't possible to relax an automatically added supertrait on the defn itself". I at first thought "but doesn't trait Foo: PointeeSized {} do that? Why is it different for auto traits?" but then I tried it and got error[E0568]: auto traits cannot have super traits or lifetime bounds, which is an AST pass error, so might be more difficult to change for specifically PointeeSized due to name resolution(?).

@Mark-Simulacrum
Copy link
Member

@bors r+

@rust-bors
Copy link
Contributor

rust-bors bot commented Mar 8, 2026

📌 Commit ca1defc has been approved by Mark-Simulacrum

It is now in the queue for this repository.

@rust-bors rust-bors bot 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 Mar 8, 2026
rust-bors bot pushed a commit that referenced this pull request Mar 9, 2026
…uwer

Rollup of 6 pull requests

Successful merges:

 - #152535 (std: use `OnceLock` for Xous environment variables)
 - #152646 (Update `UnsafeUnpin` impls involving extern types.)
 - #153559 (Inline and simplify some code for saving incremental data to disk)
 - #151900 (num: Separate public API from internal implementations)
 - #153520 (.mailmap: fix broken line with multiple emails)
 - #153573 (rustdoc-json: fix incorrect documentation for VariantKind::Struct)

Failed merges:

 - #153509 (Cleanup unused diagnostic emission methods - part 2)
@rust-bors rust-bors bot merged commit e21a5df into rust-lang:main Mar 9, 2026
11 checks passed
@rustbot rustbot added this to the 1.96.0 milestone Mar 9, 2026
rust-timer added a commit that referenced this pull request Mar 9, 2026
Rollup merge of #152646 - zachs18:unsafeunpin-marker-impls-pointee, r=Mark-Simulacrum

Update `UnsafeUnpin` impls involving extern types.

`UnsafeUnpin` tracking issue: #125735

Relaxes from `T: ?Sized` (i.e. `T: MetaSized`) to `T: PointeeSized` for the `UnsafeUnpin` impls for pointers, references, and `PhantomData<T>`, and for the negative `UnsafeUnpin` impl for `UnsafePinned<T>`. (Compare to the impls for `Freeze` on lines 911-921.)

Both `UnsafeUnpin` and `extern type`s (the only way to have a `!MetaSized` type) are unstable, so this should have no effect on stable code.

Also updates the marker_impls macro docs to use PointeeSized bound, as most uses of the macro now do.

Concretely, this change means that the following types will newly implement `UnsafeUnpin`:

* pointers and references to `T` where `T` is an `extern type`
* `PhantomData<T>` where `T` is an extern type
* either of the above where `T` is a `struct` or tuple with `extern type` tail

Additionally, the negative `UnsafeUnpin` impl for `UnsafePinned<T>` is also relaxed to `T: PointeeSized` to align with the analogous negative `Freeze` impl for `UnsafeCell<T>`, even though both structs have `T: ?Sized` in their declaration (which probably should be relaxed, but that is a separate issue), so this part of the change doesn't actually *do* anything currently, but if `UnsafeCell` and `UnsafePinned` are later relaxed to `T: PointeeSized`, then the negative impl will apply to the newly possible instantiations. Also cc #152645 that these impls compile at all.
JonathanBrouwer added a commit to JonathanBrouwer/rust that referenced this pull request Mar 18, 2026
…ed, r=scottmcm

Change `?Sized` to `PointeeSized` in `UnwindSafe` impls for pointers

Tracking issue: rust-lang#144404.

This PR is similar to rust-lang#152646.
Zalathar added a commit to Zalathar/rust that referenced this pull request Mar 18, 2026
…ed, r=scottmcm

Change `?Sized` to `PointeeSized` in `UnwindSafe` impls for pointers

Tracking issue: rust-lang#144404.

This PR is similar to rust-lang#152646.
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-libs Relevant to the library team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants