Skip to content

Can the standard library rely on stated but unenforceable invariants of traits like TotalOrd? #14418

Closed
@huonw

Description

@huonw

Some traits like TotalOrd and TotalEq have invariants (like a < b || a == b || a > b for all a and b for TotalOrd). These can be stated in documentation but not enforced by the compiler or in the type system.

Some algorithms (e.g. a sort, or a data structure) may wish to rely on these stated invariants in a way that means a violation could be memory unsafe. E.g. a highly-optimised sort might run out of bounds when a comparison function is incorrect in exactly the right (well, wrong) way. Being safe in the face of incorrectness can come at the cost of efficiency by being forced to use a slower algorithm, or perform bounds checks etc.

Nominating.

Metadata

Metadata

Assignees

No one assigned

    Labels

    P-lowLow priority

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions