diff options
author | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-02 21:21:28 +0100 |
---|---|---|
committer | Dirkjan Ochtman <dirkjan@ochtman.nl> | 2020-01-02 22:58:13 +0100 |
commit | ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f (patch) | |
tree | 207b103539bacd4147c1ee274d3a1aa4938b7853 /askama_derive | |
parent | 9085e1e3dd0ae9924433c6e5166c33e0f6d2a283 (diff) | |
download | askama-ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f.tar.gz askama-ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f.tar.bz2 askama-ea2034e8062f8db6b5ae74ca8aeab4e2ee08479f.zip |
Clean up clippy warnings
Diffstat (limited to 'askama_derive')
-rw-r--r-- | askama_derive/src/generator.rs | 2 | ||||
-rw-r--r-- | askama_derive/src/input.rs | 2 | ||||
-rw-r--r-- | askama_derive/src/lib.rs | 1 | ||||
-rw-r--r-- | askama_derive/src/parser.rs | 29 |
4 files changed, 17 insertions, 17 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 359de5a..81f6ac9 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -450,6 +450,7 @@ impl<'a> Generator<'a> { flushed + median(&mut arm_sizes) } + #[allow(clippy::too_many_arguments)] fn write_match( &mut self, ctx: &'a Context, @@ -531,6 +532,7 @@ impl<'a> Generator<'a> { flushed + median(&mut arm_sizes) } + #[allow(clippy::too_many_arguments)] fn write_loop( &mut self, ctx: &'a Context, diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs index 3b65640..6a54a99 100644 --- a/askama_derive/src/input.rs +++ b/askama_derive/src/input.rs @@ -155,7 +155,7 @@ impl<'a> TemplateInput<'a> { config .syntaxes .get(&s) - .expect(&format!("attribute syntax {} not exist", s)) + .unwrap_or_else(|| panic!("attribute syntax {} not exist", s)) }, ); diff --git a/askama_derive/src/lib.rs b/askama_derive/src/lib.rs index 2c02cb5..97228fd 100644 --- a/askama_derive/src/lib.rs +++ b/askama_derive/src/lib.rs @@ -199,6 +199,7 @@ impl<'a> Context<'a> { } } +#[allow(clippy::match_wild_err_arm)] fn get_template_source(tpl_path: &Path) -> String { match fs::read_to_string(tpl_path) { Err(_) => panic!( diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs index d22ac5a..e483ff7 100644 --- a/askama_derive/src/parser.rs +++ b/askama_derive/src/parser.rs @@ -126,17 +126,15 @@ fn split_ws_parts(s: &[u8]) -> Node { let is_ws = |c: &u8| *c != b' ' && *c != b'\t' && *c != b'\r' && *c != b'\n'; let start = s.iter().position(&is_ws); - let res = if start.is_none() { - (s, &s[0..0], &s[0..0]) - } else { - let start = start.unwrap(); + let res = if let Some(start) = start { let end = s.iter().rposition(&is_ws); - if end.is_none() { - (&s[..start], &s[start..], &s[0..0]) - } else { - let end = end.unwrap(); + if let Some(end) = end { (&s[..start], &s[start..=end], &s[end + 1..]) + } else { + (&s[..start], &s[start..], &s[0..0]) } + } else { + (s, &s[0..0], &s[0..0]) }; Node::Lit( @@ -154,10 +152,7 @@ enum ContentState { End(usize), } -fn take_content<'a>( - i: &'a [u8], - s: &'a Syntax<'a>, -) -> Result<(&'a [u8], Node<'a>), nom::Err<(&'a [u8], nom::error::ErrorKind)>> { +fn take_content<'a>(i: &'a [u8], s: &'a Syntax<'a>) -> ParserError<'a, Node<'a>> { use crate::parser::ContentState::*; let bs = s.block_start.as_bytes()[0]; let be = s.block_start.as_bytes()[1]; @@ -200,7 +195,7 @@ fn take_content<'a>( } } -fn identifier(input: &[u8]) -> Result<(&[u8], &str), nom::Err<(&[u8], nom::error::ErrorKind)>> { +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(error_position!( input, @@ -319,7 +314,7 @@ fn macro_arguments(i: &[u8]) -> IResult<&[u8], &str> { delimited(char('('), nested_parenthesis, char(')'))(i) } -fn nested_parenthesis(i: &[u8]) -> Result<(&[u8], &str), nom::Err<(&[u8], nom::error::ErrorKind)>> { +fn nested_parenthesis(i: &[u8]) -> ParserError<&str> { let mut nested = 0; let mut last = 0; let mut in_str = false; @@ -442,8 +437,8 @@ fn expr_attr(i: &[u8]) -> IResult<&[u8], Expr> { let mut res = obj; for (aname, args) in attrs { - res = if args.is_some() { - Expr::MethodCall(Box::new(res), aname, args.unwrap()) + res = if let Some(args) = args { + Expr::MethodCall(Box::new(res), aname, args) } else { Expr::Attr(Box::new(res), aname) }; @@ -1056,3 +1051,5 @@ mod tests { super::parse("{~ strvar|e ~}", &syntax); } } + +type ParserError<'a, T> = Result<(&'a [u8], T), nom::Err<(&'a [u8], nom::error::ErrorKind)>>; |