Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

derive: Shrink dependency list #771

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions askama_derive/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,7 @@ with-warp = []
mime = "0.3"
mime_guess = "2"
nom = "7"
proc-macro2 = "1"
quote = "1"
quote = { version = "1", default-features = false }
serde = { version = "1.0", optional = true, features = ["derive"] }
syn = "1"
syn = { version = "1", default-features = false }
toml_edit = { version = "0.19", optional = true, features = ["serde"] }
5 changes: 2 additions & 3 deletions askama_derive/src/generator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -463,7 +463,7 @@ impl<'a> Generator<'a> {
let mut where_clause = match where_clause {
Some(clause) => clause.clone(),
None => syn::WhereClause {
where_token: syn::Token![where](proc_macro2::Span::call_site()),
where_token: syn::token::Where::default(),
predicates: syn::punctuated::Punctuated::new(),
},
};
Expand Down Expand Up @@ -500,8 +500,7 @@ impl<'a> Generator<'a> {
// Implement Rocket's `Responder`.
#[cfg(feature = "with-rocket")]
fn impl_rocket_responder(&mut self, buf: &mut Buffer) -> Result<(), CompileError> {
let lifetime = syn::Lifetime::new("'askama", proc_macro2::Span::call_site());
let param = syn::GenericParam::Lifetime(syn::LifetimeDef::new(lifetime));
let param = syn::parse_quote!('askama);
self.write_header(
buf,
"::askama_rocket::Responder<'askama, 'askama>",
Expand Down
17 changes: 8 additions & 9 deletions askama_derive/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ use std::borrow::Cow;
use std::fmt;

use proc_macro::TokenStream;
use proc_macro2::Span;

mod config;
mod generator;
Expand All @@ -22,21 +21,21 @@ pub fn derive_template(input: TokenStream) -> TokenStream {
#[derive(Debug, Clone)]
struct CompileError {
msg: Cow<'static, str>,
span: Span,
}

impl CompileError {
fn new<S: Into<Cow<'static, str>>>(s: S, span: Span) -> Self {
fn new(s: impl Into<Cow<'static, str>>) -> Self {
Self {
msg: s.into(),
span,
}
}

fn into_compile_error(self) -> TokenStream {
syn::Error::new(self.span, self.msg)
.to_compile_error()
.into()
let msg = &*self.msg;
quote::quote! {
::core::compile_error!(#msg);
}
.into()
}
}

Expand All @@ -52,14 +51,14 @@ impl fmt::Display for CompileError {
impl From<&'static str> for CompileError {
#[inline]
fn from(s: &'static str) -> Self {
Self::new(s, Span::call_site())
Self::new(s)
}
}

impl From<String> for CompileError {
#[inline]
fn from(s: String) -> Self {
Self::new(s, Span::call_site())
Self::new(s)
}
}

Expand Down