-
-
Notifications
You must be signed in to change notification settings - Fork 14.8k
TypeId exposes equality-by-subtyping vs normal-form-syntactic-equality unsoundness. #97156
Copy link
Copy link
Closed
Labels
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/SoundnessS-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
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/SoundnessS-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
Completed
EDIT by @BoxyUwU
playground
has UB from hitting the
unreachable_uncheckedbecauseTypeId::of::<One>()is not the same asTypeId::of::<Two>()despite them being considered the same types by the type checker. Originally this was thought to be a nightly-only issue withfeature(generic_const_exprs)but actually the weird behaviour ofTypeIdcan be seen on stable and result in crashes or UB in unsafe code.original description follows below:
TypeIdbeing different for types which are considered equal types allows us to take change the value of a projection by switching between the equal types in its substs and observing that change by looking at theirTypeId. This is possible as switching between equal types is allowed even in invariant positions.This means that stabilizing
const TypeId::ofand allowing constants to flow into the type system, e.g. some minimal version offeature(generic_const_exprs), will be currently unsound.I have no idea on how to fix this. I don't expect that we're able to convert higher ranked types to some canonical representation. Ah well, cc @rust-lang/project-const-generics @nikomatsakis