Skip to content

Use BTreeMap for deterministic Into impl order (fixes #48)#49

Open
pchikku wants to merge 1 commit into
magiclen:masterfrom
pchikku:fix/into-deterministic-btreemap
Open

Use BTreeMap for deterministic Into impl order (fixes #48)#49
pchikku wants to merge 1 commit into
magiclen:masterfrom
pchikku:fix/into-deterministic-btreemap

Conversation

@pchikku

@pchikku pchikku commented Jun 6, 2026

Copy link
Copy Markdown

Fixes #48.

The Into derive emits one impl Into<…> block per entry of TypeAttribute.types, which is a std::collections::HashMap. HashMap iteration order is randomized per process (getrandom seed), so the generated impl blocks come out in a different order on every compile, which changes the consuming crate's metadata hash (SVH). Under content-addressed build systems with a shared cache this causes the same input to produce different artifacts, and mixing a fresh build with a cached dependency fails with error[E0463]: can't find crate (the proc-macro variant of rust-lang/rust#89904).

HashType already implements Ord, so this PR switches TypeAttribute.types from HashMap to BTreeMap — deterministic iteration order, no other change.

Verified: a struct with several Into targets, built three times with a clean rebuild each, produced three different .rmeta hashes before this change and three identical hashes after.

The Into derive iterated TypeAttribute.types (a HashMap) to emit one impl
block per target. HashMap iteration order is randomized per process, so the
generated impls came out in a different order each compile, changing the
consuming crate's metadata hash (SVH) build-to-build (rust-lang/rust#89904
class). HashType already implements Ord, so switching types to BTreeMap makes
the order deterministic with no other change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Into derive is non-deterministic: impl blocks emitted in HashMap order (changes consuming crate SVH)

1 participant