diff options
Diffstat (limited to 'askama_derive/src/generator.rs')
-rw-r--r-- | askama_derive/src/generator.rs | 64 |
1 files changed, 32 insertions, 32 deletions
diff --git a/askama_derive/src/generator.rs b/askama_derive/src/generator.rs index 08c1de1..5770bd5 100644 --- a/askama_derive/src/generator.rs +++ b/askama_derive/src/generator.rs @@ -70,7 +70,7 @@ fn build_template(ast: &syn::DeriveInput) -> Result<String, CompileError> { ) .build(&contexts[input.path.as_path()])?; if input.print == Print::Code || input.print == Print::All { - eprintln!("{}", code); + eprintln!("{code}"); } Ok(code) } @@ -106,7 +106,7 @@ impl TemplateArgs { template_args = Some(nested); } Ok(_) => return Err("'template' attribute must be a list".into()), - Err(e) => return Err(format!("unable to parse attribute: {}", e).into()), + Err(e) => return Err(format!("unable to parse attribute: {e}").into()), } } } @@ -182,7 +182,7 @@ impl TemplateArgs { return Err("config value must be string literal".into()); } } else { - return Err(format!("unsupported attribute key {:?} found", ident).into()); + return Err(format!("unsupported attribute key {ident:?} found").into()); } } @@ -362,7 +362,7 @@ impl<'a> Generator<'a> { buf.writeln(";")?; buf.writeln("const SIZE_HINT: ::std::primitive::usize = ")?; - buf.writeln(&format!("{}", size_hint))?; + buf.writeln(&format!("{size_hint}"))?; buf.writeln(";")?; buf.writeln("const MIME_TYPE: &'static ::std::primitive::str = ")?; @@ -478,7 +478,7 @@ impl<'a> Generator<'a> { buf.writeln( format!( "{} {} for {} {} {{", - quote!(impl#impl_generics), + quote!(impl #impl_generics), "::mendes::application::IntoResponse<A>", self.input.ast.ident, quote!(#orig_ty_generics #where_clause), @@ -573,7 +573,7 @@ impl<'a> Generator<'a> { buf.writeln( format!( "{} {} for {}{} {{", - quote!(impl#impl_generics), + quote!(impl #impl_generics), target, self.input.ast.ident, quote!(#orig_ty_generics #where_clause), @@ -755,7 +755,7 @@ impl<'a> Generator<'a> { let mut arm_sizes = Vec::new(); let expr_code = self.visit_expr_root(expr)?; - buf.writeln(&format!("match &{} {{", expr_code))?; + buf.writeln(&format!("match &{expr_code} {{"))?; let mut arm_size = 0; for (i, arm) in arms.iter().enumerate() { @@ -802,24 +802,24 @@ impl<'a> Generator<'a> { buf.writeln("{")?; buf.writeln("let mut _did_loop = false;")?; match loop_block.iter { - Expr::Range(_, _, _) => buf.writeln(&format!("let _iter = {};", expr_code)), - Expr::Array(..) => buf.writeln(&format!("let _iter = {}.iter();", expr_code)), + Expr::Range(_, _, _) => buf.writeln(&format!("let _iter = {expr_code};")), + Expr::Array(..) => buf.writeln(&format!("let _iter = {expr_code}.iter();")), // If `iter` is a call then we assume it's something that returns // an iterator. If not then the user can explicitly add the needed // call without issues. Expr::Call(..) | Expr::Index(..) => { - buf.writeln(&format!("let _iter = ({}).into_iter();", expr_code)) + buf.writeln(&format!("let _iter = ({expr_code}).into_iter();")) } // If accessing `self` then it most likely needs to be // borrowed, to prevent an attempt of moving. _ if expr_code.starts_with("self.") => { - buf.writeln(&format!("let _iter = (&{}).into_iter();", expr_code)) + buf.writeln(&format!("let _iter = (&{expr_code}).into_iter();")) } // If accessing a field then it most likely needs to be // borrowed, to prevent an attempt of moving. - Expr::Attr(..) => buf.writeln(&format!("let _iter = (&{}).into_iter();", expr_code)), + Expr::Attr(..) => buf.writeln(&format!("let _iter = (&{expr_code}).into_iter();")), // Otherwise, we borrow `iter` assuming that it implements `IntoIterator`. - _ => buf.writeln(&format!("let _iter = ({}).into_iter();", expr_code)), + _ => buf.writeln(&format!("let _iter = ({expr_code}).into_iter();")), }?; if let Some(cond) = &loop_block.cond { self.locals.push(); @@ -872,13 +872,14 @@ impl<'a> Generator<'a> { let (def, own_ctx) = match scope { Some(s) => { let path = ctx.imports.get(s).ok_or_else(|| { - CompileError::from(format!("no import found for scope {:?}", s)) - })?; - let mctx = self.contexts.get(path.as_path()).ok_or_else(|| { - CompileError::from(format!("context for {:?} not found", path)) + CompileError::from(format!("no import found for scope {s:?}")) })?; + let mctx = self + .contexts + .get(path.as_path()) + .ok_or_else(|| CompileError::from(format!("context for {path:?} not found")))?; let def = mctx.macros.get(name).ok_or_else(|| { - CompileError::from(format!("macro {:?} not found in scope {:?}", name, s)) + CompileError::from(format!("macro {name:?} not found in scope {s:?}")) })?; (def, mctx) } @@ -886,7 +887,7 @@ impl<'a> Generator<'a> { let def = ctx .macros .get(name) - .ok_or_else(|| CompileError::from(format!("macro {:?} not found", name)))?; + .ok_or_else(|| CompileError::from(format!("macro {name:?} not found")))?; (def, ctx) } }; @@ -902,7 +903,7 @@ impl<'a> Generator<'a> { let mut is_first_variable = true; for (i, arg) in def.args.iter().enumerate() { let expr = args.get(i).ok_or_else(|| { - CompileError::from(format!("macro {:?} takes more than {} arguments", name, i)) + CompileError::from(format!("macro {name:?} takes more than {i} arguments")) })?; match expr { @@ -1089,7 +1090,7 @@ impl<'a> Generator<'a> { (Some(cur_name), None) => (cur_name, 0), // A block definition contains a block definition of the same name (Some(cur_name), Some((prev_name, _))) if cur_name == prev_name => { - return Err(format!("cannot define recursive blocks ({})", cur_name).into()); + return Err(format!("cannot define recursive blocks ({cur_name})").into()); } // A block definition contains a definition of another block (Some(cur_name), Some((_, _))) => (cur_name, 0), @@ -1108,7 +1109,7 @@ impl<'a> Generator<'a> { let (ctx, def) = heritage.blocks[cur.0].get(cur.1).ok_or_else(|| { CompileError::from(match name { None => format!("no super() block found for block '{}'", cur.0), - Some(name) => format!("no block found for name '{}'", name), + Some(name) => format!("no block found for name '{name}'"), }) })?; @@ -1193,7 +1194,7 @@ impl<'a> Generator<'a> { let id = self.named; self.named += 1; - buf_expr.write(&format!("expr{} = ", id)); + buf_expr.write(&format!("expr{id} = ")); buf_expr.write("&"); buf_expr.write(&expression); buf_expr.writeln(",")?; @@ -1206,7 +1207,7 @@ impl<'a> Generator<'a> { } }; - buf_format.write(&format!("{{expr{}}}", id)); + buf_format.write(&format!("{{expr{id}}}")); size_hint += 3; } } @@ -1395,9 +1396,9 @@ impl<'a> Generator<'a> { name, self.input.escaper )); } else if crate::BUILT_IN_FILTERS.contains(&name) { - buf.write(&format!("::askama::filters::{}(", name)); + buf.write(&format!("::askama::filters::{name}(")); } else { - buf.write(&format!("filters::{}(", name)); + buf.write(&format!("filters::{name}(")); } self._visit_args(buf, args)?; @@ -1601,7 +1602,7 @@ impl<'a> Generator<'a> { } _ => return Err("loop.cycle(…) expects exactly one argument".into()), }, - s => return Err(format!("unknown loop method: {:?}", s).into()), + s => return Err(format!("unknown loop method: {s:?}").into()), }, left => { match left { @@ -1658,7 +1659,7 @@ impl<'a> Generator<'a> { right: &Expr<'_>, ) -> Result<DisplayWrap, CompileError> { self.visit_expr(buf, left)?; - buf.write(&format!(" {} ", op)); + buf.write(&format!(" {op} ")); self.visit_expr(buf, right)?; Ok(DisplayWrap::Unwrapped) } @@ -1733,12 +1734,12 @@ impl<'a> Generator<'a> { } fn visit_str_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { - buf.write(&format!("\"{}\"", s)); + buf.write(&format!("\"{s}\"")); DisplayWrap::Unwrapped } fn visit_char_lit(&mut self, buf: &mut Buffer, s: &str) -> DisplayWrap { - buf.write(&format!("'{}'", s)); + buf.write(&format!("'{s}'")); DisplayWrap::Unwrapped } @@ -2032,8 +2033,7 @@ impl MapChain<'_, &str, LocalMeta> { fn resolve_or_self(&self, name: &str) -> String { let name = normalize_identifier(name); - self.resolve(name) - .unwrap_or_else(|| format!("self.{}", name)) + self.resolve(name).unwrap_or_else(|| format!("self.{name}")) } } |