Skip to content

Commit

Permalink
Make the macros deterministic, using BTreeMap instead of HashMap (#662)
Browse files Browse the repository at this point in the history
This fixes compile errors in non-cargo build systems, which rely on the
rustc crate hash being the same between two compiles.

HashMap order is nondeterministic due to SipHasher initialization, so
macro-generated code would change between compiles.
  • Loading branch information
cormacrelf authored Dec 6, 2024
1 parent 37dc091 commit 212ff69
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions macros/src/actionlike.rs
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
use crate::utils;
use proc_macro2::{Span, TokenStream};
use quote::quote;
use std::collections::HashMap;
use std::collections::BTreeMap;
use syn::{Attribute, Data, DataEnum, DeriveInput, Error, Ident};

// This approach and implementation is inspired by the `strum` crate,
Expand Down Expand Up @@ -81,8 +81,8 @@ fn generate_input_control_kind_body(
fn parse_variant_controls(
data: &DataEnum,
default_control: &Ident,
) -> syn::Result<HashMap<Ident, Ident>> {
let mut map = HashMap::<Ident, Ident>::new();
) -> syn::Result<BTreeMap<Ident, Ident>> {
let mut map = BTreeMap::<Ident, Ident>::new();
for variant in data.variants.iter() {
for attr in variant
.attrs
Expand Down

0 comments on commit 212ff69

Please sign in to comment.