Skip to content

Hash portability between compiler versions is potentially misleading #144540

@hoxxep

Description

@hoxxep

Location

https://doc.rust-lang.org/std/hash/trait.Hash.html#portability

Summary

Whether Hash and Hasher is portable between compiler versions is ambiguously documented, and potentially misleading.

Serialization formats intended to be portable between platforms or compiler versions should either avoid encoding hashes or only rely on Hash and Hasher implementations that provide additional guarantees.

Changes to the default behaviour of Hasher are frequently[1] discussed[2] without considering portability between rust versions. I am not aware of any breaking changes on stable rust yet, but implying that Hasher output can be stable between compiler versions seems misleading.

A rust-users discussion over whether rapidhash can offer a Hasher-compatible persistent hasher has generated conflicting opinions.

I think it would be restrictive to future work on the Hash trait to claim that Hash and Hasher are portable between compiler versions, and suggest that non-portability between compiler versions is made explicit in both the Hash and Hasher documentation.

Very happy to be convinced otherwise, as it would let me build a persistent RapidHasher if portability is indeed guaranteed. Thanks!

Metadata

Metadata

Assignees

No one assigned

    Labels

    A-docsArea: Documentation for any part of the project, including the compiler, standard library, and toolsC-discussionCategory: Discussion or questions that doesn't represent real issues.T-libs-apiRelevant to the library API team, which will review and decide on the PR/issue.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions