-
-
Notifications
You must be signed in to change notification settings - Fork 14.7k
Implied bounds on nested references + variance = soundness hole #25860
Copy link
Copy link
Open
Labels
A-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.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-mediumMedium priorityMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-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-implied-boundsArea: Implied bounds / inferred outlives-boundsArea: Implied bounds / inferred outlives-boundsA-type-systemArea: Type systemArea: Type systemA-varianceArea: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)Area: Variance (https://doc.rust-lang.org/nomicon/subtyping.html)C-bugCategory: This is a bug.Category: This is a bug.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-mediumMedium priorityMedium priorityS-bug-has-testStatus: This bug is tracked inside the repo by a `known-bug` test.Status: This bug is tracked inside the repo by a `known-bug` test.T-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.
Projects
Status
new solver everywhere
The combination of variance and implied bounds for nested references opens a hole in the current type system:
This hole has been fixed in #129021 for non-higher-ranked function pointers. The underlying issue still persists.
Update from @pnkfelix :
While the test as written above is rejected by Rust today (with the error message for line 6 saying "in type
&'static &'a (), reference has a longer lifetime than the data it references"), that is just an artifact of the original source code (with its explicit type signature) running up against one new WF-check.The fundamental issue persists, since one can today write instead:
(and this way, still get the bad behaving
fn bad, by just side-stepping one of the explicit type declarations.)Update from @lcnr :
While the test as written above is rejected by Rust today, that is just an artifact of the original source code (with its lack of higher ranked regions) running up against one new WF-check ✨
The fundamental issue persists, since one can today write instead:
All the non-higher ranked variants of this issue have been fixed by #129021.