Make pin!() more foolproof.#158061
Open
theemathas wants to merge 1 commit into
Open
Conversation
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>
Darksonn
reviewed
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 |
Member
There was a problem hiding this comment.
Could/should we omit the helper type from error messages similar to https://github.com/rust-lang/rust/pull/145608/changes#diff-c712eee556d0df70dfc5c8c66c34fa13fc94a30853854f632f5dd84acfd9c973?
Contributor
Author
There was a problem hiding this comment.
I'm not familiar with diagnostics code. Am I supposed to add code in this function to do the check?
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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:Fixes #153438. This PR supersedes the proposed FCP on that issue.
cc @dianne
r? types