diff --git a/askama_derive/src/generator/expr.rs b/askama_derive/src/generator/expr.rs index 1b926938..093b054d 100644 --- a/askama_derive/src/generator/expr.rs +++ b/askama_derive/src/generator/expr.rs @@ -696,14 +696,14 @@ impl<'a> Generator<'a, '_> { for (i, part) in path.iter().enumerate() { if i > 0 { buf.write("::"); - } else if let Some(enum_ast) = self.input.enum_ast { - if part.name == "Self" { - let this = &enum_ast.ident; - let (_, generics, _) = enum_ast.generics.split_for_impl(); - let generics = generics.as_turbofish(); - buf.write(quote!(#this #generics)); - continue; - } + } else if let Some(enum_ast) = self.input.enum_ast + && part.name == "Self" + { + let this = &enum_ast.ident; + let (_, generics, _) = enum_ast.generics.split_for_impl(); + let generics = generics.as_turbofish(); + buf.write(quote!(#this #generics)); + continue; } buf.write(part.name); if !part.generics.is_empty() { diff --git a/askama_derive/src/generator/node.rs b/askama_derive/src/generator/node.rs index 7be4acc4..27dd1066 100644 --- a/askama_derive/src/generator/node.rs +++ b/askama_derive/src/generator/node.rs @@ -1129,12 +1129,12 @@ impl<'a> Generator<'a, '_> { // short call-expression for scoped macro invocations, like `{{ scope::macro_name() }}`. if let Expr::Path(path_components) = &*v.path - && path_components.len() == 2 - && path_components[0].generics.is_empty() - && path_components[1].generics.is_empty() - && let Some(import) = ctx.imports.get(&path_components[0].name) - && let Some(import_ctx) = self.contexts.get(import) - && let Some(macro_def) = import_ctx.macros.get(&path_components[1].name) + && let [scope, macro_name] = path_components.as_slice() + && scope.generics.is_empty() + && macro_name.generics.is_empty() + && let Some(scope) = ctx.imports.get(&scope.name) + && let Some(macro_ctx) = self.contexts.get(scope) + && let Some(macro_def) = macro_ctx.macros.get(¯o_name.name) { return helpers::MacroInvocation { callsite_ctx: ctx, @@ -1143,7 +1143,7 @@ impl<'a> Generator<'a, '_> { callsite_ws: ws, call_args: &v.args, macro_def, - macro_ctx: import_ctx, + macro_ctx, } .write(buf, self); } diff --git a/askama_parser/src/expr.rs b/askama_parser/src/expr.rs index 4138a432..e3c17b49 100644 --- a/askama_parser/src/expr.rs +++ b/askama_parser/src/expr.rs @@ -1047,26 +1047,23 @@ impl<'a> Suffix<'a> { const THREE_CHARS: &[&str] = &["<<=", ">>=", "...", "..="]; // need to check long to short - if let Some((head, tail)) = i.split_at_checked(3) + *i = if let Some((head, tail)) = i.split_at_checked(3) && THREE_CHARS.contains(&head) { - *i = tail; - return Ok(()); - } - if let Some((head, tail)) = i.split_at_checked(2) + tail + } else if let Some((head, tail)) = i.split_at_checked(2) && TWO_CHARS.contains(&head) { - *i = tail; - return Ok(()); - } - if let Some((head, tail)) = i.split_at_checked(1) + tail + } else if let Some((head, tail)) = i.split_at_checked(1) && let [head] = head.as_bytes() && ONE_CHAR.contains(head) { - *i = tail; - return Ok(()); - } - fail(i) + tail + } else { + return fail(i); + }; + Ok(()) } fn open<'a>(i: &mut &'a str) -> ParseResult<'a, Group> {