Skip to content

Commit f02d3ca

Browse files
authored
Fix non-reproducible builds #151
Fixes #150
1 parent bd18870 commit f02d3ca

File tree

1 file changed

+16
-11
lines changed

1 file changed

+16
-11
lines changed

i18n-embed-fl/src/lib.rs

Lines changed: 16 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ enum FlArgs {
6666
/// arg3 = calc_value());
6767
/// ```
6868
KeyValuePairs {
69-
specified_args: HashMap<syn::LitStr, Box<syn::Expr>>,
69+
specified_args: Vec<(syn::LitStr, Box<syn::Expr>)>,
7070
},
7171
/// `fl!(LOADER, "message", "optional-attribute")` no arguments after the message id and optional attribute id.
7272
None,
@@ -83,7 +83,7 @@ impl Parse for FlArgs {
8383
return Ok(FlArgs::HashMap(hash_map));
8484
}
8585

86-
let mut args_map: HashMap<syn::LitStr, Box<syn::Expr>> = HashMap::new();
86+
let mut args: Vec<(syn::LitStr, Box<syn::Expr>)> = Vec::new();
8787

8888
while let Ok(expr) = input.parse::<syn::ExprAssign>() {
8989
let argument_name_ident_opt = match &*expr.left {
@@ -108,7 +108,10 @@ impl Parse for FlArgs {
108108

109109
let argument_value = expr.right;
110110

111-
if let Some(_duplicate) = args_map.insert(argument_name_lit_str, argument_value) {
111+
if args
112+
.iter()
113+
.any(|(key, _value)| argument_name_lit_str == *key)
114+
{
112115
// There's no Clone implementation by default.
113116
let argument_name_lit_str =
114117
syn::LitStr::new(&argument_name_string, argument_name_ident.span());
@@ -120,20 +123,22 @@ impl Parse for FlArgs {
120123
),
121124
));
122125
}
126+
args.push((argument_name_lit_str, argument_value));
123127

124128
// parse the next comma if there is one
125129
let _result = input.parse::<syn::Token![,]>();
126130
}
127131

128-
if args_map.is_empty() {
132+
if args.is_empty() {
129133
let span = match input.fork().parse::<syn::Expr>() {
130134
Ok(expr) => expr.span(),
131135
Err(_) => input.span(),
132136
};
133137
Err(syn::Error::new(span, "fl!() unable to parse args input"))
134138
} else {
139+
args.sort_by_key(|(s, _)| s.value());
135140
Ok(FlArgs::KeyValuePairs {
136-
specified_args: args_map,
141+
specified_args: args,
137142
})
138143
}
139144
} else {
@@ -725,7 +730,7 @@ fn fuzzy_attribute_suggestions(
725730
fn check_message_args<R>(
726731
message: FluentMessage<'_>,
727732
bundle: &FluentBundle<R>,
728-
specified_args: &HashMap<syn::LitStr, Box<syn::Expr>>,
733+
specified_args: &Vec<(syn::LitStr, Box<syn::Expr>)>,
729734
) where
730735
R: std::borrow::Borrow<FluentResource>,
731736
{
@@ -736,8 +741,8 @@ fn check_message_args<R>(
736741
let args_set: HashSet<&str> = args.into_iter().collect();
737742

738743
let key_args: Vec<String> = specified_args
739-
.keys()
740-
.map(|key| {
744+
.iter()
745+
.map(|(key, _value)| {
741746
let arg = key.value();
742747

743748
if !args_set.contains(arg.as_str()) {
@@ -795,7 +800,7 @@ fn check_message_args<R>(
795800
fn check_attribute_args<R>(
796801
attr: FluentAttribute<'_>,
797802
bundle: &FluentBundle<R>,
798-
specified_args: &HashMap<syn::LitStr, Box<syn::Expr>>,
803+
specified_args: &Vec<(syn::LitStr, Box<syn::Expr>)>,
799804
) where
800805
R: std::borrow::Borrow<FluentResource>,
801806
{
@@ -806,8 +811,8 @@ fn check_attribute_args<R>(
806811
let args_set: HashSet<&str> = args.into_iter().collect();
807812

808813
let key_args: Vec<String> = specified_args
809-
.keys()
810-
.map(|key| {
814+
.iter()
815+
.map(|(key, _value)| {
811816
let arg = key.value();
812817

813818
if !args_set.contains(arg.as_str()) {

0 commit comments

Comments
 (0)