Skip to content

Commit

Permalink
Make the macros deterministic, using BTreeMap instead of HashMap (Lea…
Browse files Browse the repository at this point in the history
…fwing-Studios#662)

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 committed Dec 10, 2024
1 parent 0526be0 commit 9d87dcb
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 9d87dcb

Please sign in to comment.