From 6685d76e2c115f1dd313b7d45c52f2d9cbf724d8 Mon Sep 17 00:00:00 2001 From: Erick Tryzelaar Date: Wed, 4 Mar 2015 07:06:57 -0800 Subject: [PATCH] Initial switch to syntax_ast_builder --- serde2/serde2_macros/Cargo.toml | 3 +++ serde2/serde2_macros/src/lib.rs | 6 +++++- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/serde2/serde2_macros/Cargo.toml b/serde2/serde2_macros/Cargo.toml index d2b7e6e1..454e2102 100644 --- a/serde2/serde2_macros/Cargo.toml +++ b/serde2/serde2_macros/Cargo.toml @@ -6,3 +6,6 @@ authors = ["Erick Tryzelaar "] [lib] name = "serde2_macros" plugin = true + +[dependencies] +syntax_ast_builder = "0.1.0" diff --git a/serde2/serde2_macros/src/lib.rs b/serde2/serde2_macros/src/lib.rs index 10204e04..9a242d6b 100644 --- a/serde2/serde2_macros/src/lib.rs +++ b/serde2/serde2_macros/src/lib.rs @@ -2,6 +2,7 @@ extern crate syntax; extern crate rustc; +extern crate "syntax_ast_builder" as builder; use syntax::ast::{ Ident, @@ -1211,6 +1212,9 @@ fn deserialize_enum( ) -> P { let type_name = cx.expr_str(span, token::get_ident(type_ident)); + let ctx = builder::Ctx::new(); + let builder = builder::AstBuilder::new(&ctx); + // Match arms to extract a variant from a string let variant_arms: Vec = fields.iter() .zip(enum_def.variants.iter()) @@ -1225,7 +1229,7 @@ fn deserialize_enum( variant_ptr, ); - let s = cx.expr_str(span, token::get_ident(name)); + let s = builder.expr().str(name); quote_arm!(cx, $s => $value,) }) .collect();