Skip to content

Make pin!() more foolproof.#158061

Open
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:pin-foolproof
Open

Make pin!() more foolproof.#158061
theemathas wants to merge 1 commit into
rust-lang:mainfrom
theemathas:pin-foolproof

Conversation

@theemathas

Copy link
Copy Markdown
Contributor

Previously, the soundness argument for the pin!() macro relied on very complicated conditions on what coercions are possible. As a result, it was not obvious whether the macro was sound or not, and the macro was potentially fragile to changes in how coercions work.

Therefore, we change the pin!() macro so that it relies on less subtle properties of coercions. In particular:

  • The soundness argument now only relies on enumerating the possible types that a coercion could produce, as opposed to relying on details about how coercion expectations are propagated.
  • The soundness argument now only requires reasoning about possible coercions between a single pair of types defined in the standard library, as opposed to reasoning about two pairs of types, with some involved types being defined by the user.

Fixes #153438. This PR supersedes the proposed FCP on that issue.

cc @dianne

r? types

Previously, the soundness argument for the `pin!()` macro relied on
very complicated conditions on what coercions are possible.
As a result, it was not obvious whether the macro was sound or not,
and the macro was potentially fragile to changes in how coercions work.

Therefore, we change the `pin!()` macro so that it relies on less subtle
properties of coercions. In particular:

* The soundness argument now only relies on enumerating the possible
  types that a coercion could produce, as opposed to relying on details
  about how coercion expectations are propagated.
* The soundness argument now only requires reasoning about possible
  coercions between a single pair of types defined in the
  standard library, as opposed to reasoning about two pairs of types,
  with some involved types being defined by the user.

Fixes <rust-lang#153438>
@theemathas theemathas added T-libs Relevant to the library team, which will review and decide on the PR/issue. A-pin Area: Pin T-types Relevant to the types team, which will review and decide on the PR/issue. labels Jun 18, 2026
@rustbot rustbot added the S-waiting-on-review Status: Awaiting review from the assignee but also interested parties. label Jun 18, 2026
Comment on lines -9 to 10
| expected type parameter `T`, found `&mut T`
| expected `&mut PinMacroHelper<T>`, found `&mut PinMacroHelper<&mut T>`
| arguments to this function are incorrect

@Darksonn Darksonn Jun 18, 2026

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not familiar with diagnostics code. Am I supposed to add code in this function to do the check?

fn check_single_incompatible(&self) -> Option<ErrorGuaranteed> {

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

A-pin Area: Pin 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. T-types Relevant to the types team, which will review and decide on the PR/issue.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

pin!() is unsound due to coercions

4 participants