Skip to content

Clarify documentation of traits with behavioral contracts (PartialOrd etc.) #73682

Description

@RalfJung

@qwaz points out that

Rust's Deref documentation says that this trait should never fail. Similarly, documentation of ExactSizeIterator, PartialOrd, and Hash also describe the behavior of implementations with enforcing words such as must and never.

However, all of these are safe traits, so unsafe code must not rely on such properties. If it does, we have a soundness bug.

I don't think Rust has RFC-style standardization of must/should/etc (maybe it should^^), but at least we should clarify these docs here I feel. Also given that safe code can break these promises, I wonder if "must" is appropriate. Maybe a better wording would be something like

implementations should do X (but since safe code can easily violate this property, users of this trait must not rely on implementations being well-behaved)

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    C-enhancementCategory: An issue proposing an enhancement or a PR with one.T-libs-api[DEPRECATED; DO NOT USE]

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions