Uh oh!
There was an error while loading. Please reload this page.
Prevent downstream impl DerefMut for Pin<LocalType> - #145608
Conversation
Darksonn
commented
Aug 19, 2025
lcnr
commented
Aug 19, 2025
Prevent downstream impl DerefMut for Pin
This comment has been minimized.
This comment has been minimized.
dtolnay
commented
Aug 19, 2025
We discussed this PR in today's standard library API meeting. Those present were on board with the approach, but it will be important to see a reasonably clean crater result and send PRs for any breakage, because not all downstream impls of DerefMut for Pin are necessarily unsound. The new implementation rules out correct as well as incorrect impls. Once crater is finished, we would like to do a libs-api FCP to surface this to the rest of the team. We noticed that the new pin::hidden::PinHelper type is now going to appear in diagnostics such as the pin-unsound-issue-85099-derefmut.stderr in this PR, but hopefully this mostly only happens when someone is doing funny business like writing their own DerefMut impl, and not for more typical use of Pin's methods and impls. |
Darksonn
commented
Aug 19, 2025
Ok, let's see what crater says. But I don't think there are any valid use-cases for |
lcnr
commented
Aug 19, 2025
@craterbot check |
craterbot
commented
Aug 19, 2025
👌 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
017ed97 to
9bb2a3aCompareUpdating this with some additional tests for error messages. I'm not worried about (See individual commits for how the error messages change.) |
A slightly different implementation seems to give somewhat better errors: But let's wait for crater before we think about that further. |
impl DerefMut for Pin<LocalType>craterbot
commented
Aug 21, 2025
🚧 Experiment ℹ️ Crater is a tool to run experiments across parts of the Rust ecosystem. Learn more |
craterbot
commented
Aug 22, 2025
🎉 Experiment
|
Rollup of 7 pull requests Successful merges: - #143900 ([rustdoc] Correctly handle `should_panic` doctest attribute and fix `--no-run` test flag on the 2024 edition) - #145608 (Prevent downstream `impl DerefMut for Pin<LocalType>`) - #146865 (kcfi: only reify trait methods when dyn-compatible) - #147390 (Use globals instead of metadata for std::autodiff) - #147398 (Fix; correct placement of type inference error for method calls) - #147431 (compiletest: Read the whole test file before parsing directives) - #147433 (Fix doc comment) r? `@ghost` `@rustbot` modify labels: rollup
Prevent downstream `impl DerefMut for Pin<LocalType>` The safety requirements for [`PinCoerceUnsized`](https://doc.rust-lang.org/stable/std/pin/trait.PinCoerceUnsized.html) are essentially that the type does not have a malicious `Deref` or `DerefMut` impl. However, the `Pin` type is fundamental, so the end-user can provide their own implementation of `DerefMut` for `Pin<&SomeLocalType>`, so it's possible for `Pin` to have a malicious `DerefMut` impl. This unsoundness is known as #85099. Unfortunately, this means that the implementation of `PinCoerceUnsized` for `Pin` is currently unsound. To fix that, modify the impl so that it becomes impossible for downstream crates to provide their own implementation of `DerefMut` for `Pin` by abusing a hidden struct that is not fundamental. This PR is a breaking change, but it fixes#85099. The PR supersedes #144896. r? lcnr
bors
commented
Oct 7, 2025
Prevent downstream `impl DerefMut for Pin<LocalType>` The safety requirements for [`PinCoerceUnsized`](https://doc.rust-lang.org/stable/std/pin/trait.PinCoerceUnsized.html) are essentially that the type does not have a malicious `Deref` or `DerefMut` impl. However, the `Pin` type is fundamental, so the end-user can provide their own implementation of `DerefMut` for `Pin<&SomeLocalType>`, so it's possible for `Pin` to have a malicious `DerefMut` impl. This unsoundness is known as rust-lang#85099. Unfortunately, this means that the implementation of `PinCoerceUnsized` for `Pin` is currently unsound. To fix that, modify the impl so that it becomes impossible for downstream crates to provide their own implementation of `DerefMut` for `Pin` by abusing a hidden struct that is not fundamental. This PR is a breaking change, but it fixesrust-lang#85099. The PR supersedes rust-lang#144896. r? lcnr
Zalathar
commented
Oct 7, 2025
Yielding to enclosing rollup. @bors retry |
Rollup of 8 pull requests Successful merges: - #145608 (Prevent downstream `impl DerefMut for Pin<LocalType>`) - #146865 (kcfi: only reify trait methods when dyn-compatible) - #147205 (Add a new `wasm32-wasip3` target to Rust) - #147390 (Use globals instead of metadata for std::autodiff) - #147398 (Fix; correct placement of type inference error for method calls) - #147422 (collect-license-metadata: Print a diff of the expected output) - #147431 (compiletest: Read the whole test file before parsing directives) - #147433 (Fix doc comment) r? `@ghost` `@rustbot` modify labels: rollup
Prevent downstream `impl DerefMut for Pin<LocalType>` The safety requirements for [`PinCoerceUnsized`](https://doc.rust-lang.org/stable/std/pin/trait.PinCoerceUnsized.html) are essentially that the type does not have a malicious `Deref` or `DerefMut` impl. However, the `Pin` type is fundamental, so the end-user can provide their own implementation of `DerefMut` for `Pin<&SomeLocalType>`, so it's possible for `Pin` to have a malicious `DerefMut` impl. This unsoundness is known as #85099. Unfortunately, this means that the implementation of `PinCoerceUnsized` for `Pin` is currently unsound. To fix that, modify the impl so that it becomes impossible for downstream crates to provide their own implementation of `DerefMut` for `Pin` by abusing a hidden struct that is not fundamental. This PR is a breaking change, but it fixes#85099. The PR supersedes #144896. r? lcnr
bors
commented
Oct 7, 2025
fmease
commented
Oct 7, 2025
Yielding to overarching rollup @bors retry |
Rollup of 8 pull requests Successful merges: - #145608 (Prevent downstream `impl DerefMut for Pin<LocalType>`) - #146865 (kcfi: only reify trait methods when dyn-compatible) - #147205 (Add a new `wasm32-wasip3` target to Rust) - #147390 (Use globals instead of metadata for std::autodiff) - #147398 (Fix; correct placement of type inference error for method calls) - #147422 (collect-license-metadata: Print a diff of the expected output) - #147431 (compiletest: Read the whole test file before parsing directives) - #147433 (Fix doc comment) r? `@ghost` `@rustbot` modify labels: rollup
bors
commented
Oct 7, 2025
bors
commented
Oct 7, 2025
☀️ Test successful - checks-actions |
What is this?This is an experimental post-merge analysis report that shows differences in test outcomes between the merged PR and its parent PR.Comparing 4a54b26 (parent) -> fed46ff (this PR) Test differencesShow 20 test diffs20 doctest diffs were found. These are ignored, as they are noisy. Test dashboardRun cargo run --manifest-path src/ci/citool/Cargo.toml -- \
test-dashboard fed46ffd5059e11669df1bd9406b02914c3fb73f --output-dir test-dashboardAnd then open Job duration changes
How to interpret the job duration changes?Job durations can vary a lot, based on the actual runner instance |
rust-timer
commented
Oct 7, 2025
Finished benchmarking commit (fed46ff): comparison URL. Overall result: ❌✅ regressions and improvements - please read the text belowOur benchmarks found a performance regression caused by this PR. Next Steps:
@rustbot label: +perf-regression Instruction countOur most reliable metric. Used to determine the overall result above. However, even this metric can be noisy.
Max RSS (memory usage)Results (primary 1.8%, secondary 1.6%)A less reliable metric. May be of interest, but not used to determine the overall result above.
CyclesThis benchmark run did not return any relevant results for this metric. Binary sizeResults (primary 0.1%)A less reliable metric. May be of interest, but not used to determine the overall result above.
Bootstrap: 473.216s -> 474.165s (0.20%) |
Kobzol
commented
Oct 13, 2025
Tiny regression on hyper, otherwise netural. And since this is a soundness fix: @rustbot label: +perf-regression-triaged |


The safety requirements for
PinCoerceUnsizedare essentially that the type does not have a maliciousDereforDerefMutimpl. However, thePintype is fundamental, so the end-user can provide their own implementation ofDerefMutforPin<&SomeLocalType>, so it's possible forPinto have a maliciousDerefMutimpl. This unsoundness is known as #85099.Unfortunately, this means that the implementation of
PinCoerceUnsizedforPinis currently unsound. To fix that, modify the impl so that it becomes impossible for downstream crates to provide their own implementation ofDerefMutforPinby abusing a hidden struct that is not fundamental.This PR is a breaking change, but it fixes#85099. The PR supersedes #144896.
r? lcnr