From 8bb3de0a3e586da6b719abedcfcc58e901eddc12 Mon Sep 17 00:00:00 2001 From: Dirkjan Ochtman Date: Thu, 1 Jul 2021 15:52:33 +0200 Subject: Stop eliding lifetimes in paths --- askama/src/lib.rs | 2 + askama_actix/src/lib.rs | 2 + askama_derive/src/lib.rs | 4 +- askama_escape/benches/all.rs | 2 +- askama_escape/src/lib.rs | 1 + askama_gotham/src/lib.rs | 2 + askama_iron/src/lib.rs | 2 + askama_rocket/src/lib.rs | 2 + askama_shared/src/generator.rs | 118 ++++++++++++++++++++++++----------------- askama_shared/src/heritage.rs | 2 +- askama_shared/src/input.rs | 2 +- askama_shared/src/lib.rs | 1 + askama_shared/src/parser.rs | 101 +++++++++++++++++------------------ askama_tide/src/lib.rs | 2 + askama_warp/src/lib.rs | 2 + 15 files changed, 140 insertions(+), 105 deletions(-) diff --git a/askama/src/lib.rs b/askama/src/lib.rs index 601fb16..82a186b 100644 --- a/askama/src/lib.rs +++ b/askama/src/lib.rs @@ -60,6 +60,8 @@ //! provided by Askama. #![allow(unused_imports)] +#![deny(elided_lifetimes_in_paths)] + #[macro_use] extern crate askama_derive; pub use askama_shared as shared; diff --git a/askama_actix/src/lib.rs b/askama_actix/src/lib.rs index 742c7f2..bb58174 100644 --- a/askama_actix/src/lib.rs +++ b/askama_actix/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + pub use askama::*; use bytes::BytesMut; diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 1b6c02a..f97fa90 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -1,4 +1,4 @@ -extern crate proc_macro; +#![deny(elided_lifetimes_in_paths)] use askama_shared::heritage::{Context, Heritage}; use askama_shared::input::{Print, Source, TemplateInput}; @@ -71,7 +71,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result { } fn find_used_templates( - input: &TemplateInput, + input: &TemplateInput<'_>, map: &mut HashMap, source: String, ) -> Result<(), CompileError> { diff --git a/askama_escape/benches/all.rs b/askama_escape/benches/all.rs index a98f2d7..e0ef11f 100644 --- a/askama_escape/benches/all.rs +++ b/askama_escape/benches/all.rs @@ -11,7 +11,7 @@ fn functions(c: &mut Criterion) { c.bench_function("Escaping", escaping); } -fn escaping(b: &mut criterion::Bencher) { +fn escaping(b: &mut criterion::Bencher<'_>) { let string_long = r#" Lorem ipsum dolor sit amet, consectetur adipiscing elit. Mauris consequat tellus sit amet ornare fermentum. Etiam nec erat ante. In at metus a orci mollis scelerisque. diff --git a/askama_escape/src/lib.rs b/askama_escape/src/lib.rs index 577b793..4643390 100644 --- a/askama_escape/src/lib.rs +++ b/askama_escape/src/lib.rs @@ -1,4 +1,5 @@ #![no_std] +#![deny(elided_lifetimes_in_paths)] #[cfg(test)] extern crate std; diff --git a/askama_gotham/src/lib.rs b/askama_gotham/src/lib.rs index c929a40..965155e 100644 --- a/askama_gotham/src/lib.rs +++ b/askama_gotham/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + pub use askama::*; pub use gotham::handler::IntoResponse; diff --git a/askama_iron/src/lib.rs b/askama_iron/src/lib.rs index 37e79cc..07b96bd 100644 --- a/askama_iron/src/lib.rs +++ b/askama_iron/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + pub use askama::*; pub use iron::{headers::ContentType, modifier::Modifier, Response}; diff --git a/askama_rocket/src/lib.rs b/askama_rocket/src/lib.rs index ee70965..ae683c9 100644 --- a/askama_rocket/src/lib.rs +++ b/askama_rocket/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + use std::io::Cursor; pub use askama::*; diff --git a/askama_shared/src/generator.rs b/askama_shared/src/generator.rs index fc94977..8457400 100644 --- a/askama_shared/src/generator.rs +++ b/askama_shared/src/generator.rs @@ -16,9 +16,9 @@ use std::path::PathBuf; use std::{cmp, hash, mem, str}; pub fn generate( - input: &TemplateInput, - contexts: &HashMap<&PathBuf, Context, S>, - heritage: &Option, + input: &TemplateInput<'_>, + contexts: &HashMap<&PathBuf, Context<'_>, S>, + heritage: &Option>, integrations: Integrations, ) -> Result { Generator::new(input, contexts, heritage, integrations, MapChain::new()) @@ -53,9 +53,9 @@ struct Generator<'a, S: std::hash::BuildHasher> { impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn new<'n>( - input: &'n TemplateInput, + input: &'n TemplateInput<'_>, contexts: &'n HashMap<&'n PathBuf, Context<'n>, S>, - heritage: &'n Option, + heritage: &'n Option>, integrations: Integrations, locals: MapChain<'n, &'n str, LocalMeta>, ) -> Generator<'n, S> { @@ -85,7 +85,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { } // Takes a Context and generates the relevant implementations. - fn build(mut self, ctx: &'a Context) -> Result { + fn build(mut self, ctx: &'a Context<'_>) -> Result { let mut buf = Buffer::new(0); if !ctx.blocks.is_empty() { if let Some(parent) = self.input.parent { @@ -121,7 +121,11 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { } // Implement `Template` for the given context struct. - fn impl_template(&mut self, ctx: &'a Context, buf: &mut Buffer) -> Result<(), CompileError> { + fn impl_template( + &mut self, + ctx: &'a Context<'_>, + buf: &mut Buffer, + ) -> Result<(), CompileError> { self.write_header(buf, "::askama::Template", None)?; buf.writeln( "fn render_into(&self, writer: &mut dyn ::std::fmt::Write) -> \ @@ -392,8 +396,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn handle( &mut self, - ctx: &'a Context, - nodes: &'a [Node], + ctx: &'a Context<'_>, + nodes: &'a [Node<'_>], buf: &mut Buffer, level: AstLevel, ) -> Result { @@ -469,9 +473,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn write_cond( &mut self, - ctx: &'a Context, + ctx: &'a Context<'_>, buf: &mut Buffer, - conds: &'a [Cond], + conds: &'a [Cond<'_>], ws: Ws, ) -> Result { let mut flushed = 0; @@ -542,11 +546,11 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { #[allow(clippy::too_many_arguments)] fn write_match( &mut self, - ctx: &'a Context, + ctx: &'a Context<'_>, buf: &mut Buffer, ws1: Ws, - expr: &Expr, - arms: &'a [When], + expr: &Expr<'_>, + arms: &'a [When<'_>], ws2: Ws, ) -> Result { self.flush_ws(ws1); @@ -595,12 +599,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { #[allow(clippy::too_many_arguments)] fn write_loop( &mut self, - ctx: &'a Context, + ctx: &'a Context<'_>, buf: &mut Buffer, ws1: Ws, - var: &'a Target, - iter: &Expr, - body: &'a [Node], + var: &'a Target<'_>, + iter: &Expr<'_>, + body: &'a [Node<'_>], ws2: Ws, ) -> Result { self.handle_ws(ws1); @@ -657,12 +661,12 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn write_call( &mut self, - ctx: &'a Context, + ctx: &'a Context<'_>, buf: &mut Buffer, ws: Ws, scope: Option<&str>, name: &str, - args: &[Expr], + args: &[Expr<'_>], ) -> Result { if name == "super" { return self.write_block(buf, None, ws); @@ -757,7 +761,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn handle_include( &mut self, - ctx: &'a Context, + ctx: &'a Context<'_>, buf: &mut Buffer, ws: Ws, path: &str, @@ -798,7 +802,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, ws: Ws, - var: &'a Target, + var: &'a Target<'_>, ) -> Result<(), CompileError> { self.handle_ws(ws); self.write_buf_writable(buf)?; @@ -827,8 +831,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, ws: Ws, - var: &'a Target, - val: &Expr, + var: &'a Target<'_>, + val: &Expr<'_>, ) -> Result<(), CompileError> { self.handle_ws(ws); let mut expr_buf = Buffer::new(0); @@ -1053,13 +1057,17 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { /* Visitor methods for expression types */ - fn visit_expr_root(&mut self, expr: &Expr) -> Result { + fn visit_expr_root(&mut self, expr: &Expr<'_>) -> Result { let mut buf = Buffer::new(0); self.visit_expr(&mut buf, expr)?; Ok(buf.buf) } - fn visit_expr(&mut self, buf: &mut Buffer, expr: &Expr) -> Result { + fn visit_expr( + &mut self, + buf: &mut Buffer, + expr: &Expr<'_>, + ) -> Result { Ok(match *expr { Expr::BoolLit(s) => self.visit_bool_lit(buf, s), Expr::NumLit(s) => self.visit_num_lit(buf, s), @@ -1093,7 +1101,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { DisplayWrap::Unwrapped } - fn visit_match_variant(&mut self, buf: &mut Buffer, param: &MatchVariant) -> DisplayWrap { + fn visit_match_variant(&mut self, buf: &mut Buffer, param: &MatchVariant<'_>) -> DisplayWrap { let mut expr_buf = Buffer::new(0); let wrapped = match *param { MatchVariant::StrLit(s) => { @@ -1115,7 +1123,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { wrapped } - fn visit_match_param(&mut self, buf: &mut Buffer, param: &MatchParameter) -> DisplayWrap { + fn visit_match_param(&mut self, buf: &mut Buffer, param: &MatchParameter<'_>) -> DisplayWrap { let mut expr_buf = Buffer::new(0); let wrapped = match *param { MatchParameter::NumLit(s) => self.visit_num_lit(&mut expr_buf, s), @@ -1175,7 +1183,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, mut name: &str, - args: &[Expr], + args: &[Expr<'_>], ) -> Result { if name == "format" { self._visit_format_filter(buf, args)?; @@ -1224,7 +1232,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn _visit_format_filter( &mut self, buf: &mut Buffer, - args: &[Expr], + args: &[Expr<'_>], ) -> Result<(), CompileError> { buf.write("format!("); if let Some(Expr::StrLit(v)) = args.first() { @@ -1240,7 +1248,11 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { Ok(()) } - fn _visit_fmt_filter(&mut self, buf: &mut Buffer, args: &[Expr]) -> Result<(), CompileError> { + fn _visit_fmt_filter( + &mut self, + buf: &mut Buffer, + args: &[Expr<'_>], + ) -> Result<(), CompileError> { buf.write("format!("); if let Some(Expr::StrLit(v)) = args.get(1) { self.visit_str_lit(buf, v); @@ -1257,7 +1269,11 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { } // Force type coercion on first argument to `join` filter (see #39). - fn _visit_join_filter(&mut self, buf: &mut Buffer, args: &[Expr]) -> Result<(), CompileError> { + fn _visit_join_filter( + &mut self, + buf: &mut Buffer, + args: &[Expr<'_>], + ) -> Result<(), CompileError> { buf.write("::askama::filters::join((&"); for (i, arg) in args.iter().enumerate() { if i > 0 { @@ -1272,7 +1288,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { Ok(()) } - fn _visit_args(&mut self, buf: &mut Buffer, args: &[Expr]) -> Result<(), CompileError> { + fn _visit_args(&mut self, buf: &mut Buffer, args: &[Expr<'_>]) -> Result<(), CompileError> { if args.is_empty() { return Ok(()); } @@ -1313,7 +1329,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn visit_attr( &mut self, buf: &mut Buffer, - obj: &Expr, + obj: &Expr<'_>, attr: &str, ) -> Result { if let Expr::Var(name) = *obj { @@ -1343,8 +1359,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn visit_index( &mut self, buf: &mut Buffer, - obj: &Expr, - key: &Expr, + obj: &Expr<'_>, + key: &Expr<'_>, ) -> Result { buf.write("&"); self.visit_expr(buf, obj)?; @@ -1357,9 +1373,9 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn visit_method_call( &mut self, buf: &mut Buffer, - obj: &Expr, + obj: &Expr<'_>, method: &str, - args: &[Expr], + args: &[Expr<'_>], ) -> Result { if let Expr::Var("self") = obj { buf.write("self"); @@ -1377,7 +1393,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, op: &str, - inner: &Expr, + inner: &Expr<'_>, ) -> Result { buf.write(op); self.visit_expr(buf, inner)?; @@ -1388,8 +1404,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, op: &str, - left: &Option>, - right: &Option>, + left: &Option>>, + right: &Option>>, ) -> Result { if let Some(left) = left { self.visit_expr(buf, left)?; @@ -1405,8 +1421,8 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, op: &str, - left: &Expr, - right: &Expr, + left: &Expr<'_>, + right: &Expr<'_>, ) -> Result { self.visit_expr(buf, left)?; buf.write(&format!(" {} ", op)); @@ -1414,7 +1430,11 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { Ok(DisplayWrap::Unwrapped) } - fn visit_group(&mut self, buf: &mut Buffer, inner: &Expr) -> Result { + fn visit_group( + &mut self, + buf: &mut Buffer, + inner: &Expr<'_>, + ) -> Result { buf.write("("); self.visit_expr(buf, inner)?; buf.write(")"); @@ -1424,7 +1444,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { fn visit_array( &mut self, buf: &mut Buffer, - elements: &[Expr], + elements: &[Expr<'_>], ) -> Result { buf.write("["); for (i, el) in elements.iter().enumerate() { @@ -1451,7 +1471,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, path: &[&str], - args: &[Expr], + args: &[Expr<'_>], ) -> Result { for (i, part) in path.iter().enumerate() { if i > 0 { @@ -1479,7 +1499,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { &mut self, buf: &mut Buffer, s: &str, - args: &[Expr], + args: &[Expr<'_>], ) -> Result { buf.write("("); let s = normalize_identifier(s); @@ -1513,7 +1533,7 @@ impl<'a, S: std::hash::BuildHasher> Generator<'a, S> { DisplayWrap::Unwrapped } - fn visit_target(&mut self, buf: &mut Buffer, target: &'a Target) { + fn visit_target(&mut self, buf: &mut Buffer, target: &'a Target<'_>) { match *target { Target::Name(name) => { let name = normalize_identifier(name); @@ -1663,7 +1683,7 @@ where } } - fn with_parent<'p>(parent: &'p MapChain) -> MapChain<'p, K, V> { + fn with_parent<'p>(parent: &'p MapChain<'_, K, V>) -> MapChain<'p, K, V> { MapChain { parent: Some(parent), scopes: vec![HashMap::new()], diff --git a/askama_shared/src/heritage.rs b/askama_shared/src/heritage.rs index 87f23e0..c03163d 100644 --- a/askama_shared/src/heritage.rs +++ b/askama_shared/src/heritage.rs @@ -43,7 +43,7 @@ pub struct Context<'a> { impl<'a> Context<'a> { pub fn new<'n>( - config: &Config, + config: &Config<'_>, path: &Path, nodes: &'n [Node<'n>], ) -> Result, CompileError> { diff --git a/askama_shared/src/input.rs b/askama_shared/src/input.rs index 8986fea..c94c217 100644 --- a/askama_shared/src/input.rs +++ b/askama_shared/src/input.rs @@ -24,7 +24,7 @@ impl<'a> TemplateInput<'a> { /// field, if any. pub fn new<'n>( ast: &'n syn::DeriveInput, - config: &'n Config, + config: &'n Config<'_>, ) -> Result, CompileError> { // Check that an attribute called `template()` exists and that it is // the proper type (list). diff --git a/askama_shared/src/lib.rs b/askama_shared/src/lib.rs index 0b1f375..f217cfb 100644 --- a/askama_shared/src/lib.rs +++ b/askama_shared/src/lib.rs @@ -1,4 +1,5 @@ #![cfg_attr(feature = "cargo-clippy", allow(unused_parens))] +#![deny(elided_lifetimes_in_paths)] use std::collections::{BTreeMap, HashSet}; use std::convert::TryFrom; diff --git a/askama_shared/src/parser.rs b/askama_shared/src/parser.rs index 3c5a86c..5610a24 100644 --- a/askama_shared/src/parser.rs +++ b/askama_shared/src/parser.rs @@ -172,7 +172,7 @@ where } } -fn split_ws_parts(s: &[u8]) -> Node { +fn split_ws_parts(s: &[u8]) -> Node<'_> { if s.is_empty() { let rs = str::from_utf8(s).unwrap(); return Node::Lit(rs, rs, rs); @@ -249,7 +249,7 @@ fn take_content<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> ParserError<'a, Node<'a>> } } -fn identifier(input: &[u8]) -> ParserError<&str> { +fn identifier(input: &[u8]) -> ParserError<'_, &str> { if !nom::character::is_alphabetic(input[0]) && input[0] != b'_' && !non_ascii(input[0]) { return Err(nom::Err::Error(nom::error::Error::new( input, @@ -270,7 +270,7 @@ fn non_ascii(chr: u8) -> bool { (0x80..=0xFD).contains(&chr) } -fn expr_bool_lit(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_bool_lit(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(alt((tag("false"), tag("true"))), |s| { Expr::BoolLit(str::from_utf8(s).unwrap()) })(i) @@ -282,11 +282,11 @@ fn num_lit(i: &[u8]) -> IResult<&[u8], &str> { })(i) } -fn expr_num_lit(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_num_lit(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(num_lit, |s| Expr::NumLit(s))(i) } -fn expr_array_lit(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_array_lit(i: &[u8]) -> IResult<&[u8], Expr<'_>> { delimited( ws(tag("[")), map(separated_list1(ws(tag(",")), expr_any), |arr| { @@ -296,11 +296,11 @@ fn expr_array_lit(i: &[u8]) -> IResult<&[u8], Expr> { )(i) } -fn variant_num_lit(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn variant_num_lit(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { map(num_lit, |s| MatchVariant::NumLit(s))(i) } -fn param_num_lit(i: &[u8]) -> IResult<&[u8], MatchParameter> { +fn param_num_lit(i: &[u8]) -> IResult<&[u8], MatchParameter<'_>> { map(num_lit, |s| MatchParameter::NumLit(s))(i) } @@ -315,15 +315,15 @@ fn str_lit(i: &[u8]) -> IResult<&[u8], &str> { )(i) } -fn expr_str_lit(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_str_lit(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(str_lit, |s| Expr::StrLit(s))(i) } -fn variant_str_lit(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn variant_str_lit(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { map(str_lit, |s| MatchVariant::StrLit(s))(i) } -fn param_str_lit(i: &[u8]) -> IResult<&[u8], MatchParameter> { +fn param_str_lit(i: &[u8]) -> IResult<&[u8], MatchParameter<'_>> { map(str_lit, |s| MatchParameter::StrLit(s))(i) } @@ -338,23 +338,23 @@ fn char_lit(i: &[u8]) -> IResult<&[u8], &str> { )(i) } -fn expr_char_lit(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_char_lit(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(char_lit, |s| Expr::CharLit(s))(i) } -fn variant_char_lit(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn variant_char_lit(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { map(char_lit, |s| MatchVariant::CharLit(s))(i) } -fn param_char_lit(i: &[u8]) -> IResult<&[u8], MatchParameter> { +fn param_char_lit(i: &[u8]) -> IResult<&[u8], MatchParameter<'_>> { map(char_lit, |s| MatchParameter::CharLit(s))(i) } -fn expr_var(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_var(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(identifier, |s| Expr::Var(s))(i) } -fn expr_var_call(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_var_call(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (s, args)) = tuple((ws(identifier), arguments))(i)?; Ok((i, Expr::VarCall(s, args))) } @@ -388,27 +388,27 @@ fn path(i: &[u8]) -> IResult<&[u8], Vec<&str>> { } } -fn expr_path(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_path(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, path) = path(i)?; Ok((i, Expr::Path(path))) } -fn expr_path_call(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_path_call(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (path, args)) = tuple((ws(path), arguments))(i)?; Ok((i, Expr::PathCall(path, args))) } -fn variant_path(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn variant_path(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { map(separated_list1(ws(tag("::")), identifier), |path| { MatchVariant::Path(path) })(i) } -fn target_single(i: &[u8]) -> IResult<&[u8], Target> { +fn target_single(i: &[u8]) -> IResult<&[u8], Target<'_>> { map(identifier, |s| Target::Name(s))(i) } -fn target_tuple(i: &[u8]) -> IResult<&[u8], Target> { +fn target_tuple(i: &[u8]) -> IResult<&[u8], Target<'_>> { let parts = separated_list0(tag(","), ws(identifier)); let trailing = opt(ws(tag(","))); let mut full = delimited(tag("("), tuple((parts, trailing)), tag(")")); @@ -417,15 +417,15 @@ fn target_tuple(i: &[u8]) -> IResult<&[u8], Target> { Ok((i, Target::Tuple(elems))) } -fn variant_name(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn variant_name(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { map(identifier, |s| MatchVariant::Name(s))(i) } -fn param_name(i: &[u8]) -> IResult<&[u8], MatchParameter> { +fn param_name(i: &[u8]) -> IResult<&[u8], MatchParameter<'_>> { map(identifier, |s| MatchParameter::Name(s))(i) } -fn arguments(i: &[u8]) -> IResult<&[u8], Vec> { +fn arguments(i: &[u8]) -> IResult<&[u8], Vec>> { delimited( ws(tag("(")), separated_list0(tag(","), ws(expr_any)), @@ -437,7 +437,7 @@ fn macro_arguments(i: &[u8]) -> IResult<&[u8], &str> { delimited(char('('), nested_parenthesis, char(')'))(i) } -fn nested_parenthesis(i: &[u8]) -> ParserError<&str> { +fn nested_parenthesis(i: &[u8]) -> ParserError<'_, &str> { let mut nested = 0; let mut last = 0; let mut in_str = false; @@ -493,7 +493,7 @@ fn parameters(i: &[u8]) -> IResult<&[u8], Vec<&str>> { )(i) } -fn with_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { +fn with_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters<'_>> { let (i, (_, value)) = tuple(( tag("with"), alt((match_simple_parameters, match_named_parameters)), @@ -501,7 +501,7 @@ fn with_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { Ok((i, value)) } -fn match_simple_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { +fn match_simple_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters<'_>> { delimited( ws(tag("(")), map(separated_list0(tag(","), ws(match_parameter)), |mps| { @@ -511,7 +511,7 @@ fn match_simple_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { )(i) } -fn match_named_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { +fn match_named_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters<'_>> { delimited( ws(tag("{")), map( @@ -522,13 +522,13 @@ fn match_named_parameters(i: &[u8]) -> IResult<&[u8], MatchParameters> { )(i) } -fn expr_group(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_group(i: &[u8]) -> IResult<&[u8], Expr<'_>> { map(delimited(ws(char('(')), expr_any, ws(char(')'))), |s| { Expr::Group(Box::new(s)) })(i) } -fn expr_single(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_single(i: &[u8]) -> IResult<&[u8], Expr<'_>> { alt(( expr_bool_lit, expr_num_lit, @@ -544,7 +544,7 @@ fn expr_single(i: &[u8]) -> IResult<&[u8], Expr> { ))(i) } -fn match_variant(i: &[u8]) -> IResult<&[u8], MatchVariant> { +fn match_variant(i: &[u8]) -> IResult<&[u8], MatchVariant<'_>> { alt(( variant_path, variant_name, @@ -554,23 +554,23 @@ fn match_variant(i: &[u8]) -> IResult<&[u8], MatchVariant> { ))(i) } -fn match_parameter(i: &[u8]) -> IResult<&[u8], MatchParameter> { +fn match_parameter(i: &[u8]) -> IResult<&[u8], MatchParameter<'_>> { alt((param_name, param_num_lit, param_str_lit, param_char_lit))(i) } -fn match_named_parameter(i: &[u8]) -> IResult<&[u8], (&str, Option)> { +fn match_named_parameter(i: &[u8]) -> IResult<&[u8], (&str, Option>)> { let param = tuple((ws(tag(":")), match_parameter)); let (i, (name, param)) = tuple((identifier, opt(param)))(i)?; Ok((i, (name, param.map(|s| s.1)))) } -fn attr(i: &[u8]) -> IResult<&[u8], (&str, Option>)> { +fn attr(i: &[u8]) -> IResult<&[u8], (&str, Option>>)> { let (i, (_, attr, args)) = tuple((ws(tag(".")), alt((num_lit, identifier)), ws(opt(arguments))))(i)?; Ok((i, (attr, args))) } -fn expr_attr(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_attr(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (obj, attrs)) = tuple((expr_single, many0(attr)))(i)?; let mut res = obj; @@ -585,7 +585,7 @@ fn expr_attr(i: &[u8]) -> IResult<&[u8], Expr> { Ok((i, res)) } -fn expr_index(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_index(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let key = opt(tuple((ws(tag("[")), expr_any, ws(tag("]"))))); let (i, (obj, key)) = tuple((expr_attr, key))(i)?; let key = key.map(|(_, key, _)| key); @@ -599,12 +599,12 @@ fn expr_index(i: &[u8]) -> IResult<&[u8], Expr> { )) } -fn filter(i: &[u8]) -> IResult<&[u8], (&str, Option>)> { +fn filter(i: &[u8]) -> IResult<&[u8], (&str, Option>>)> { let (i, (_, fname, args)) = tuple((tag("|"), ws(identifier), opt(arguments)))(i)?; Ok((i, (fname, args))) } -fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (obj, filters)) = tuple((expr_unary, many0(filter)))(i)?; let mut res = obj; @@ -622,7 +622,7 @@ fn expr_filtered(i: &[u8]) -> IResult<&[u8], Expr> { Ok((i, res)) } -fn expr_unary(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_unary(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (op, expr)) = tuple((opt(alt((ws(tag("!")), ws(tag("-"))))), expr_index))(i)?; Ok(( i, @@ -633,14 +633,14 @@ fn expr_unary(i: &[u8]) -> IResult<&[u8], Expr> { )) } -fn expr_rust_macro(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_rust_macro(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (mname, _, args)) = tuple((identifier, tag("!"), macro_arguments))(i)?; Ok((i, Expr::RustMacro(mname, args))) } macro_rules! expr_prec_layer { ( $name:ident, $inner:ident, $op:expr ) => { - fn $name(i: &[u8]) -> IResult<&[u8], Expr> { + fn $name(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, left) = $inner(i)?; let (i, right) = many0(pair( ws(tag($op)), @@ -655,7 +655,7 @@ macro_rules! expr_prec_layer { } }; ( $name:ident, $inner:ident, $( $op:expr ),+ ) => { - fn $name(i: &[u8]) -> IResult<&[u8], Expr> { + fn $name(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, left) = $inner(i)?; let (i, right) = many0(pair( ws(alt(($( tag($op) ),*,))), @@ -681,7 +681,7 @@ expr_prec_layer!(expr_compare, expr_bor, "==", "!=", ">=", ">", "<=", "<"); expr_prec_layer!(expr_and, expr_compare, "&&"); expr_prec_layer!(expr_or, expr_and, "||"); -fn range_right(i: &[u8]) -> IResult<&[u8], Expr> { +fn range_right(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let (i, (_, incl, right)) = tuple((ws(tag("..")), opt(ws(tag("="))), opt(expr_or)))(i)?; Ok(( i, @@ -693,7 +693,7 @@ fn range_right(i: &[u8]) -> IResult<&[u8], Expr> { )) } -fn expr_any(i: &[u8]) -> IResult<&[u8], Expr> { +fn expr_any(i: &[u8]) -> IResult<&[u8], Expr<'_>> { let compound = map(tuple((expr_or, range_right)), |(left, rest)| match rest { Expr::Range(op, _, right) => Expr::Range(op, Some(Box::new(left)), right), _ => unreachable!(), @@ -713,7 +713,7 @@ fn expr_node<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a>> Ok((i, Node::Expr(Ws(pws.is_some(), nws.is_some()), expr))) } -fn block_call(i: &[u8]) -> IResult<&[u8], Node> { +fn block_call(i: &[u8]) -> IResult<&[u8], Node<'_>> { let mut p = tuple(( opt(tag("-")), ws(tag("call")), @@ -730,7 +730,7 @@ fn block_call(i: &[u8]) -> IResult<&[u8], Node> { )) } -fn cond_if(i: &[u8]) -> IResult<&[u8], CondTest> { +fn cond_if(i: &[u8]) -> IResult<&[u8], CondTest<'_>> { let mut p = tuple(( ws(tag("if")), opt(tuple(( @@ -879,7 +879,7 @@ fn block_match<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a> )) } -fn block_let(i: &[u8]) -> IResult<&[u8], Node> { +fn block_let(i: &[u8]) -> IResult<&[u8], Node<'_>> { let mut p = tuple(( opt(tag("-")), ws(alt((tag("let"), tag("set")))), @@ -927,7 +927,7 @@ fn block_for<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a>> )) } -fn block_extends(i: &[u8]) -> IResult<&[u8], Node> { +fn block_extends(i: &[u8]) -> IResult<&[u8], Node<'_>> { let (i, (_, name)) = tuple((ws(tag("extends")), ws(expr_str_lit)))(i)?; Ok((i, Node::Extends(name))) } @@ -963,7 +963,7 @@ fn block_block<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> IResult<&'a [u8], Node<'a> )) } -fn block_include(i: &[u8]) -> IResult<&[u8], Node> { +fn block_include(i: &[u8]) -> IResult<&[u8], Node<'_>> { let mut p = tuple(( opt(tag("-")), ws(tag("include")), @@ -983,7 +983,7 @@ fn block_include(i: &[u8]) -> IResult<&[u8], Node> { )) } -fn block_import(i: &[u8]) -> IResult<&[u8], Node> { +fn block_import(i: &[u8]) -> IResult<&[u8], Node<'_>> { let mut p = tuple(( opt(tag("-")), ws(tag("import")), @@ -1170,8 +1170,7 @@ mod tests { use crate::Syntax; fn check_ws_split(s: &str, res: &(&str, &str, &str)) { - let node = super::split_ws_parts(s.as_bytes()); - match node { + match super::split_ws_parts(s.as_bytes()) { Node::Lit(lws, s, rws) => { assert_eq!(lws, res.0); assert_eq!(s, res.1); diff --git a/askama_tide/src/lib.rs b/askama_tide/src/lib.rs index 59f90e9..715f77e 100644 --- a/askama_tide/src/lib.rs +++ b/askama_tide/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + pub use askama; pub use tide; diff --git a/askama_warp/src/lib.rs b/askama_warp/src/lib.rs index e721ab4..30d15fa 100644 --- a/askama_warp/src/lib.rs +++ b/askama_warp/src/lib.rs @@ -1,3 +1,5 @@ +#![deny(elided_lifetimes_in_paths)] + pub use askama::*; pub use warp; -- cgit