Object safety of traits with generic implementation for ?Sized
and with associated types is unsound
#80783
Labels
A-associated-items
Area: Associated items (types, constants & functions)
A-DSTs
Area: Dynamically-sized types (DSTs)
A-trait-system
Area: Trait system
A-type-system
Area: Type system
C-bug
Category: This is a bug.
I-unsound
Issue: A soundness hole (worst kind of bug), see: https://en.wikipedia.org/wiki/Soundness
T-compiler
Relevant to the compiler team, which will review and decide on the PR/issue.
T-lang
Relevant to the language team, which will review and decide on the PR/issue.
Traits such as the
IsEqual
trait at the beginning of the code below are object safe in a setting where this object safety leads to unsoundness.Perhaps the case where we might want to remove object safety is best described along the lines of:
Self
type in at least one of the associated type definitions (e.g. how the implementation ofIsEqual for A
usesA
in thetype To
).^^^ Just a guess. No idea if this actually catches all the problems or if might be too restrictive.
(Playground)
Output:
Errors:
@rustbot prioritize
@rustbot modify labels: C-bug, A-traits, T-compiler, T-lang, A-associated-items, A-dst, A-typesystem
and someone needs to add “I-unsound”Edit:
Also, I don’t know if “I-unsound” supersedes “I-ICE”. I ran into about 10 different kinds of ICEs before I got this to create a segfault, so “I-ICE” might very well apply, too. Actually, it’s pretty nice that there are all these things that you can’t get the code generation to accept, even with a hole like this in the typesystem.
One thing that, surprisingly, didn’t ICE was requesting the size of an unsized type. Instead, it just returns
0
.The text was updated successfully, but these errors were encountered: