From f23162a2080a3fb3fe2b8ba7eba4d61da5737dfe Mon Sep 17 00:00:00 2001 From: msrd0 Date: Mon, 2 Nov 2020 17:11:53 +0100 Subject: Use `syn::Error::to_compile_error` and add trybuild ui test (#374) --- askama_derive/src/lib.rs | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) (limited to 'askama_derive/src') diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 8844e99..101b861 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -7,6 +7,7 @@ use askama_shared::{ generator, get_template_source, read_config_file, CompileError, Config, Integrations, }; use proc_macro::TokenStream; +use proc_macro2::Span; use std::collections::HashMap; use std::path::PathBuf; @@ -15,11 +16,11 @@ use std::path::PathBuf; pub fn derive_template(input: TokenStream) -> TokenStream { let ast: syn::DeriveInput = syn::parse(input).unwrap(); match build_template(&ast) { - Ok(source) => source, - Err(e) => format!("compile_error!({:?})", e), + Ok(source) => source.parse().unwrap(), + Err(e) => syn::Error::new(Span::call_site(), e) + .to_compile_error() + .into(), } - .parse() - .unwrap() } /// Takes a `syn::DeriveInput` and generates source code for it -- cgit