-
-
Notifications
You must be signed in to change notification settings - Fork 14.9k
deref_patterns is unsound due to dyn of subtrait of DerefPure #154619
Copy link
Copy link
Closed
Labels
A-dyn-compatibilityArea: Dyn compatibility (formerly: object safety)Area: Dyn compatibility (formerly: object safety)A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.F-deref_patterns`#![feature(deref_patterns)]``#![feature(deref_patterns)]`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/SoundnessT-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Metadata
Metadata
Assignees
Labels
A-dyn-compatibilityArea: Dyn compatibility (formerly: object safety)Area: Dyn compatibility (formerly: object safety)A-dyn-traitArea: trait objects, vtable layoutArea: trait objects, vtable layoutA-patternsRelating to patterns and pattern matchingRelating to patterns and pattern matchingC-bugCategory: This is a bug.Category: This is a bug.F-deref_patterns`#![feature(deref_patterns)]``#![feature(deref_patterns)]`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/SoundnessT-langRelevant to the language teamRelevant to the language teamT-typesRelevant to the types team, which will review and decide on the PR/issue.Relevant to the types team, which will review and decide on the PR/issue.
Type
Fields
Give feedbackNo fields configured for issues without a type.
By defining a trait that's a subtrait of
DerefPure, the trait object of that user-defined trait automatically implementsDerefPure, without inheriting theDerefimpl of the concrete type inside. This allows users to implement a non-pureDerefon the trait object type, violating the invariant ofDerefPure.For example, the following code causes a SIGILL at run time, due to none of the arms in the
matchbeing matched.Note that making
Derefa supertrait ofDerefPuredoesn't fix this problem, since there's still a similar unsoundness withDerefMutinstead.A possible solution is applying
#[rustc_dyn_incompatible_trait]toDerefPure.Meta
Reproducible on the playground with version
1.96.0-nightly (2026-03-29 a25435bcf7cfc9b953d3)