mirror of
https://github.com/askama-rs/askama.git
synced 2025-09-27 13:00:57 +00:00
derive: more if-let
This commit is contained in:
parent
53ddd3cfc3
commit
a37d9f5a90
@ -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() {
|
||||
|
@ -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);
|
||||
}
|
||||
|
@ -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> {
|
||||
|
Loading…
x
Reference in New Issue
Block a user