-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
pin!() is unsound due to coercions #153438
Copy link
Copy link
Open
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-pinArea: PinArea: PinC-bugCategory: This is a bug.Category: This is a bug.F-super_letit's super, let's go!it's super, let's go!I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Metadata
Metadata
Assignees
Labels
A-coercionsArea: implicit and explicit `expr as Type` coercionsArea: implicit and explicit `expr as Type` coercionsA-macrosArea: All kinds of macros (custom derive, macro_rules!, proc macros, ..)Area: All kinds of macros (custom derive, macro_rules!, proc macros, ..)A-pinArea: PinArea: PinC-bugCategory: This is a bug.Category: This is a bug.F-super_letit's super, let's go!it's super, let's go!I-unsoundIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessIssue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/SoundnessP-highHigh priorityHigh priorityT-compilerRelevant to the compiler team, which will review and decide on the PR/issue.Relevant to the compiler team, which will review and decide on the PR/issue.T-langRelevant to the language teamRelevant to the language teamT-libsRelevant to the library team, which will review and decide on the PR/issue.Relevant to the library team, which will review and decide on the PR/issue.regression-from-stable-to-stablePerformance or correctness regression from one stable version to another.Performance or correctness regression from one stable version to another.
Type
Fields
Give feedbackNo fields configured for issues without a type.
Related to #153425
Edit: See #153438 (comment) for an easier exploit
The following code causes UB. In my testing, it prints a random-looking number.
The issue is that the
pin!(thing)macro call moves the entireThinginto an inaccessible variable. Then, instead of pinningThing, it deref-coerces the&mut Thing<T>into a&mut Tand pins that instead. Then, theDropimpl can later access the&mut T, breaking thePininvariant.This presumably regressed in #139114, which changed
pin!()to usesuper let.This uses a block expression in the syntax, which then presumably runs into the bug in #23014, causing the strange coercion behavior.The code compiled since 1.88.0. It didn't compile in 1.87.0.
Meta
Reproducible on the playground with version
1.96.0-nightly (2026-03-04 b90dc1e597db0bbc0cab)