From 2020d41874f7681ba948a40d8e8f8993d651a81c Mon Sep 17 00:00:00 2001 From: Nadrieril Date: Thu, 9 May 2019 12:48:41 +0200 Subject: Detect duplicate record fields in typecheck --- dhall_proc_macros/src/quote.rs | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) (limited to 'dhall_proc_macros/src') 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(m: BTreeMap) -> TokenStream +fn quote_map(m: impl IntoIterator) -> 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(m: BTreeMap>) -> TokenStream +fn quote_opt_map( + m: impl IntoIterator)>, +) -> 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)))) } -- cgit v1.2.3