diff options
author | Nadrieril | 2019-05-09 12:48:41 +0200 |
---|---|---|
committer | Nadrieril | 2019-05-09 12:48:41 +0200 |
commit | 2020d41874f7681ba948a40d8e8f8993d651a81c (patch) | |
tree | 48668a407c9049d5b40f0195b5060cca6f5fd67d /dhall_proc_macros/src | |
parent | 325228d54a5b51979e0be112a51988c7449df89c (diff) |
Detect duplicate record fields in typecheck
Diffstat (limited to 'dhall_proc_macros/src')
-rw-r--r-- | dhall_proc_macros/src/quote.rs | 15 |
1 files changed, 8 insertions, 7 deletions
diff --git a/dhall_proc_macros/src/quote.rs b/dhall_proc_macros/src/quote.rs index 77ed5de..241ef66 100644 --- a/dhall_proc_macros/src/quote.rs +++ b/dhall_proc_macros/src/quote.rs @@ -3,7 +3,6 @@ use dhall_syntax::context::Context; use dhall_syntax::*; use proc_macro2::TokenStream; use quote::quote; -use std::collections::BTreeMap; pub fn expr(input: proc_macro::TokenStream) -> proc_macro::TokenStream { let input_str = input.to_string(); @@ -201,25 +200,27 @@ where quote! { vec![ #(#e),* ] } } -fn quote_map<TS>(m: BTreeMap<Label, TS>) -> TokenStream +fn quote_map<TS>(m: impl IntoIterator<Item = (Label, TS)>) -> TokenStream where TS: quote::ToTokens + std::fmt::Debug, { let entries = m.into_iter().map(|(k, v)| { let k = quote_label(&k); - quote!(m.insert(#k, #v);) + quote!(m.push((#k, #v));) }); quote! { { - use std::collections::BTreeMap; - let mut m = BTreeMap::new(); + use std::vec::Vec; + let mut m = Vec::new(); #( #entries )* m } } } -fn quote_opt_map<TS>(m: BTreeMap<Label, Option<TS>>) -> TokenStream +fn quote_opt_map<TS>( + m: impl IntoIterator<Item = (Label, Option<TS>)>, +) -> TokenStream where TS: quote::ToTokens + std::fmt::Debug, { - quote_map(m.into_iter().map(|(k, v)| (k, quote_opt(v))).collect()) + quote_map(m.into_iter().map(|(k, v)| (k, quote_opt(v)))) } |