Skip to content

Separate validity and safety invariants in the specification? #150

Closed
@bjorn3

Description

@bjorn3

Violating either is currently considered UB, while safety invariants can be temporarily violated provided that you don't pass it to any function expecting the safety invariants to hold, while violating the validity invariants is unconditionally UB1. As an example for bool the value being 0 or 1 is a validity invariant, while for str the value being valid UTF-8 is a safety invariant2.

Footnotes

  1. https://www.ralfj.de/blog/2018/08/22/two-kinds-of-invariants.html

  2. https://github.com/rust-lang/reference/pull/792

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions