diff options
Diffstat (limited to 'askama_shared')
-rw-r--r-- | askama_shared/src/generator.rs | 22 | ||||
-rw-r--r-- | askama_shared/src/input.rs | 4 | ||||
-rw-r--r-- | askama_shared/src/lib.rs | 8 |
3 files changed, 21 insertions, 13 deletions
diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index ac2f4be..7462af9 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -49,7 +49,7 @@ impl<'a> State<'a> { _ => {}, } } - for (&(scope, name), ref m) in imported { + for (&(scope, name), m) in imported { macros.insert((Some(scope), name), m); } State { @@ -81,7 +81,7 @@ fn trait_name_for_path(base: &Option<&Expr>, path: &Path) -> String { res } -fn get_parent_type<'a>(ast: &'a syn::DeriveInput) -> Option<&'a syn::Type> { +fn get_parent_type(ast: &syn::DeriveInput) -> Option<&syn::Type> { match ast.data { syn::Data::Struct(syn::DataStruct { fields: syn::Fields::Named(ref fields), @@ -322,7 +322,7 @@ impl<'a> Generator<'a> { Node::Cond(ref conds, ref ws) => { self.write_cond(state, conds, ws); }, - Node::Match(ref ws1, ref expr, ref inter, ref arms, ref ws2) => { + Node::Match(ref ws1, ref expr, inter, ref arms, ref ws2) => { self.write_match(state, ws1, expr, inter, arms, ws2); }, Node::Loop(ref ws1, ref var, ref iter, ref body, ref ws2) => { @@ -437,10 +437,10 @@ impl<'a> Generator<'a> { }, None => self.write("_"), }; - if params.len() > 0 { + if !params.is_empty() { self.write("("); for (i, param) in params.iter().enumerate() { - if let MatchParameter::Name(ref p) = *param { + if let MatchParameter::Name(p) = *param { self.locals.insert(p); } if i > 0 { @@ -484,7 +484,7 @@ impl<'a> Generator<'a> { fn write_call(&mut self, state: &'a State, ws: &WS, scope: Option<&str>, name: &str, args: &[Expr]) { let def = state.macros.get(&(scope, name)).unwrap_or_else(|| { - if let Some(ref s) = scope { + if let Some(s) = scope { panic!(format!("macro '{}::{}' not found", s, name)); } else { panic!(format!("macro '{}' not found", name)); @@ -749,7 +749,7 @@ impl<'a> Generator<'a> { DisplayWrap::Unwrapped } - fn visit_array(&mut self, elements: &Vec<Expr>) -> DisplayWrap { + fn visit_array(&mut self, elements: &[Expr]) -> DisplayWrap { self.write("["); for (i, el) in elements.iter().enumerate() { if i > 0 { @@ -761,7 +761,7 @@ impl<'a> Generator<'a> { DisplayWrap::Unwrapped } - fn visit_path(&mut self, path: &Vec<&str>) -> DisplayWrap { + fn visit_path(&mut self, path: &[&str]) -> DisplayWrap { for (i, part) in path.iter().enumerate() { if i > 0 { self.write("::"); @@ -898,14 +898,20 @@ impl<'a, T: 'a> SetChain<'a, T> where T: cmp::Eq + hash::Hash { } } +#[derive(Clone)] enum AstLevel { Top, Nested, } +impl Copy for AstLevel {} + +#[derive(Clone)] enum DisplayWrap { Wrapped, Unwrapped, } +impl Copy for DisplayWrap {} + type MacroMap<'a> = HashMap<(Option<&'a str>, &'a str), &'a Macro<'a>>; diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index e3b64da..5869af0 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -24,7 +24,7 @@ impl<'a> TemplateInput<'a> { (path, s.clone()) }, Source::Path(ref s) => { - let path = path::find_template_from_path(&s, None); + let path = path::find_template_from_path(s, None); let src = path::get_template_source(&path); (path, src) }, @@ -93,7 +93,7 @@ impl TemplateMeta { } else { panic!("ext value must be string literal"); }, - attr @ _ => panic!("unsupported annotation key '{}' found", attr), + attr => panic!("unsupported annotation key '{}' found", attr), } } } diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index ed2357d..1f145f2 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -1,3 +1,5 @@ +#![cfg_attr(feature = "cargo-clippy", allow(unused_parens))] + #[macro_use] extern crate error_chain; #[macro_use] @@ -59,7 +61,7 @@ impl<'a> Imports<'a> { pub fn new(parent_nodes: &'a [Node], parent_path: &'a Path) -> Imports<'a> { let sources = parent_nodes.iter().filter_map(|n| { match *n { - Node::Import(_, ref import_path, scope) => { + Node::Import(_, import_path, scope) => { let path = path::find_template_from_path(import_path, Some(parent_path)); let src = path::get_template_source(&path); Some((scope, Cow::Owned(src))) @@ -72,8 +74,8 @@ impl<'a> Imports<'a> { pub fn macro_map(&'a self) -> HashMap<(&'a str, &'a str), Macro<'a>> { let mut macro_map = HashMap::new(); - for (scope, s) in self.sources.iter() { - for n in parser::parse(&s.as_ref()) { + for (scope, s) in &self.sources { + for n in parser::parse(s.as_ref()) { match n { Node::Macro(name, m) => macro_map.insert((*scope, name), m), _ => None, |