aboutsummaryrefslogtreecommitdiffstats
path: root/askama_derive
diff options
context:
space:
mode:
authorLibravatar Dirkjan Ochtman <dirkjan@ochtman.nl>2023-01-30 09:51:23 +0100
committerLibravatar GitHub <noreply@github.com>2023-01-30 09:51:23 +0100
commit3003d86264680433e789d2726d0d12d2c6267c40 (patch)
treec7e74c13df73d05ec75ee8feec6416733e1de141 /askama_derive
parent23326b4765b04cb13dd6c72f2103ff9bd6d44d7d (diff)
downloadaskama-3003d86264680433e789d2726d0d12d2c6267c40.tar.gz
askama-3003d86264680433e789d2726d0d12d2c6267c40.tar.bz2
askama-3003d86264680433e789d2726d0d12d2c6267c40.zip
Apply clippy suggestions for 1.67 (#769)
Diffstat (limited to 'askama_derive')
-rw-r--r--askama_derive/Cargo.toml3
-rw-r--r--askama_derive/src/config.rs7
-rw-r--r--askama_derive/src/generator.rs64
-rw-r--r--askama_derive/src/input.rs8
-rw-r--r--askama_derive/src/parser.rs4
5 files changed, 43 insertions, 43 deletions
diff --git a/askama_derive/Cargo.toml b/askama_derive/Cargo.toml
index 1d176b7..61cce97 100644
--- a/askama_derive/Cargo.toml
+++ b/askama_derive/Cargo.toml
@@ -7,7 +7,8 @@ repository = "https://github.com/djc/askama"
license = "MIT/Apache-2.0"
workspace = ".."
readme = "README.md"
-edition = "2018"
+edition = "2021"
+rust-version = "1.58"
[lib]
proc-macro = true
diff --git a/askama_derive/src/config.rs b/askama_derive/src/config.rs
index cb0126c..8c49217 100644
--- a/askama_derive/src/config.rs
+++ b/askama_derive/src/config.rs
@@ -1,5 +1,4 @@
use std::collections::{BTreeMap, HashSet};
-use std::convert::TryFrom;
use std::path::{Path, PathBuf};
use std::{env, fs};
@@ -58,13 +57,13 @@ impl Config<'_> {
.insert(name.to_string(), Syntax::try_from(raw_s)?)
.is_some()
{
- return Err(format!("syntax \"{}\" is already defined", name).into());
+ return Err(format!("syntax \"{name}\" is already defined").into());
}
}
}
if !syntaxes.contains_key(default_syntax) {
- return Err(format!("default syntax \"{}\" not found", default_syntax).into());
+ return Err(format!("default syntax \"{default_syntax}\" not found").into());
}
let mut escapers = Vec::new();
@@ -193,7 +192,7 @@ struct RawConfig<'d> {
impl RawConfig<'_> {
#[cfg(feature = "config")]
fn from_toml_str(s: &str) -> std::result::Result<RawConfig<'_>, CompileError> {
- toml::from_str(s).map_err(|e| format!("invalid TOML in {}: {}", CONFIG_FILE_NAME, e).into())
+ toml::from_str(s).map_err(|e| format!("invalid TOML in {CONFIG_FILE_NAME}: {e}").into())
}
#[cfg(not(feature = "config"))]
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}"))
}
}
diff --git a/askama_derive/src/input.rs b/askama_derive/src/input.rs
index 68d01db..47d51bd 100644
--- a/askama_derive/src/input.rs
+++ b/askama_derive/src/input.rs
@@ -42,7 +42,7 @@ impl TemplateInput<'_> {
// of `ext` is merged into a synthetic `path` value here.
let source = source.expect("template path or source not found in attributes");
let path = match (&source, &ext) {
- (&Source::Path(ref path), _) => config.find_template(path, None)?,
+ (Source::Path(path), _) => config.find_template(path, None)?,
(&Source::Source(_), Some(ext)) => PathBuf::from(format!("{}.{}", ast.ident, ext)),
(&Source::Source(_), None) => {
return Err("must include 'ext' attribute when using 'source' attribute".into())
@@ -56,7 +56,7 @@ impl TemplateInput<'_> {
config
.syntaxes
.get(&s)
- .ok_or_else(|| CompileError::from(format!("attribute syntax {} not exist", s)))
+ .ok_or_else(|| CompileError::from(format!("attribute syntax {s} not exist")))
},
)?;
@@ -78,7 +78,7 @@ impl TemplateInput<'_> {
}
let escaper = escaper.ok_or_else(|| {
- CompileError::from(format!("no escaper defined for extension '{}'", escaping))
+ CompileError::from(format!("no escaper defined for extension '{escaping}'"))
})?;
let mime_type =
@@ -146,7 +146,7 @@ impl FromStr for Print {
"ast" => Ast,
"code" => Code,
"none" => None,
- v => return Err(format!("invalid value for print option: {}", v,).into()),
+ v => return Err(format!("invalid value for print option: {v}",).into()),
})
}
}
diff --git a/askama_derive/src/parser.rs b/askama_derive/src/parser.rs
index 650eabf..c59177a 100644
--- a/askama_derive/src/parser.rs
+++ b/askama_derive/src/parser.rs
@@ -1238,7 +1238,7 @@ pub(crate) fn parse<'a>(
match parse_template(src, &state) {
Ok((left, res)) => {
if !left.is_empty() {
- Err(format!("unable to parse template:\n\n{:?}", left).into())
+ Err(format!("unable to parse template:\n\n{left:?}").into())
} else {
Ok(res)
}
@@ -1251,7 +1251,7 @@ pub(crate) fn parse<'a>(
let source_after = match source_after.char_indices().enumerate().take(41).last() {
Some((40, (i, _))) => format!("{:?}...", &source_after[..i]),
- _ => format!("{:?}", source_after),
+ _ => format!("{source_after:?}"),
};
let (row, last_line) = source_before.lines().enumerate().last().unwrap();