diff --git a/build/configure/src/python.rs b/build/configure/src/python.rs index 474a55f31..dde4dd51e 100644 --- a/build/configure/src/python.rs +++ b/build/configure/src/python.rs @@ -51,7 +51,7 @@ fn normalize_version(version: &str) -> String { part.to_string() } else { let normalized_prefix = numeric_prefix.parse::().unwrap_or(0).to_string(); - format!("{}{}", normalized_prefix, rest) + format!("{normalized_prefix}{rest}") } } }) diff --git a/build/ninja_gen/src/bin/update_protoc.rs b/build/ninja_gen/src/bin/update_protoc.rs index 224dbaa50..3a8f06b8b 100644 --- a/build/ninja_gen/src/bin/update_protoc.rs +++ b/build/ninja_gen/src/bin/update_protoc.rs @@ -72,12 +72,11 @@ fn fetch_protoc_release_info() -> Result> { "MacArm" => continue, // Skip MacArm since it's handled with MacX64 "WindowsX64" => "Platform::WindowsX64 | Platform::WindowsArm", "WindowsArm" => continue, // Skip WindowsArm since it's handled with WindowsX64 - _ => &format!("Platform::{}", platform), + _ => &format!("Platform::{platform}"), }; match_blocks.push(format!( - " {} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}", - match_pattern, download_url, sha256 + " {match_pattern} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}" )); } diff --git a/build/ninja_gen/src/bin/update_uv.rs b/build/ninja_gen/src/bin/update_uv.rs index 39cf87668..5a5d2d253 100644 --- a/build/ninja_gen/src/bin/update_uv.rs +++ b/build/ninja_gen/src/bin/update_uv.rs @@ -53,7 +53,7 @@ fn fetch_uv_release_info() -> Result> { // Find the corresponding .sha256 or .sha256sum asset let sha_asset = assets.iter().find(|a| { let name = a["name"].as_str().unwrap_or(""); - name == format!("{}.sha256", asset_name) || name == format!("{}.sha256sum", asset_name) + name == format!("{asset_name}.sha256") || name == format!("{asset_name}.sha256sum") }); if sha_asset.is_none() { eprintln!("No sha256 asset found for {asset_name}"); @@ -71,8 +71,7 @@ fn fetch_uv_release_info() -> Result> { let sha256 = sha_text.split_whitespace().next().unwrap_or(""); match_blocks.push(format!( - " Platform::{} => {{\n OnlineArchive {{\n url: \"{}\",\n sha256: \"{}\",\n }}\n }}", - platform, download_url, sha256 + " Platform::{platform} => {{\n OnlineArchive {{\n url: \"{download_url}\",\n sha256: \"{sha256}\",\n }}\n }}" )); } @@ -135,10 +134,7 @@ mod tests { assert_eq!( updated_lines, original_lines - EXPECTED_LINES_REMOVED, - "Expected line count to decrease by exactly {} lines (original: {}, updated: {})", - EXPECTED_LINES_REMOVED, - original_lines, - updated_lines + "Expected line count to decrease by exactly {EXPECTED_LINES_REMOVED} lines (original: {original_lines}, updated: {updated_lines})" ); } } diff --git a/build/ninja_gen/src/build.rs b/build/ninja_gen/src/build.rs index df8ec82fb..ed416b000 100644 --- a/build/ninja_gen/src/build.rs +++ b/build/ninja_gen/src/build.rs @@ -300,7 +300,7 @@ impl BuildStatement<'_> { writeln!(buf, "build {outputs_str}: {action_name} {inputs_str}").unwrap(); for (key, value) in self.variables.iter().sorted() { - writeln!(buf, " {key} = {}", value).unwrap(); + writeln!(buf, " {key} = {value}").unwrap(); } writeln!(buf).unwrap(); @@ -476,7 +476,7 @@ impl FilesHandle for BuildStatement<'_> { let outputs = outputs.into_iter().map(|v| { let v = v.as_ref(); let v = if !v.starts_with("$builddir/") && !v.starts_with("$builddir\\") { - format!("$builddir/{}", v) + format!("$builddir/{v}") } else { v.to_owned() }; diff --git a/build/ninja_gen/src/python.rs b/build/ninja_gen/src/python.rs index a799bd517..7ec11516c 100644 --- a/build/ninja_gen/src/python.rs +++ b/build/ninja_gen/src/python.rs @@ -148,7 +148,7 @@ impl BuildAction for PythonEnvironment { // Add --python flag to extra_args if PYTHON_BINARY is set let mut args = self.extra_args.to_string(); if let Ok(python_binary) = env::var("PYTHON_BINARY") { - args = format!("--python {} {}", python_binary, args); + args = format!("--python {python_binary} {args}"); } build.add_variable("extra_args", args); } diff --git a/build/ninja_gen/src/render.rs b/build/ninja_gen/src/render.rs index a9a32cf84..dde307e73 100644 --- a/build/ninja_gen/src/render.rs +++ b/build/ninja_gen/src/render.rs @@ -30,12 +30,12 @@ impl Build { ) .unwrap(); for (key, value) in &self.variables { - writeln!(&mut buf, "{} = {}", key, value).unwrap(); + writeln!(&mut buf, "{key} = {value}").unwrap(); } buf.push('\n'); for (key, value) in &self.pools { - writeln!(&mut buf, "pool {}\n depth = {}", key, value).unwrap(); + writeln!(&mut buf, "pool {key}\n depth = {value}").unwrap(); } buf.push('\n'); diff --git a/build/runner/src/archive.rs b/build/runner/src/archive.rs index 8a78dd515..932b924e1 100644 --- a/build/runner/src/archive.rs +++ b/build/runner/src/archive.rs @@ -65,7 +65,7 @@ fn sha2_data(data: &[u8]) -> String { let mut digest = sha2::Sha256::new(); digest.update(data); let result = digest.finalize(); - format!("{:x}", result) + format!("{result:x}") } enum CompressionKind { diff --git a/build/runner/src/build.rs b/build/runner/src/build.rs index 535254736..107be9783 100644 --- a/build/runner/src/build.rs +++ b/build/runner/src/build.rs @@ -138,7 +138,7 @@ fn setup_build_root() -> Utf8PathBuf { true }; if create { - println!("Switching build root to {}", new_target); + println!("Switching build root to {new_target}"); std::os::unix::fs::symlink(new_target, build_root).unwrap(); } } diff --git a/build/runner/src/run.rs b/build/runner/src/run.rs index bff88eb97..fd8877cd9 100644 --- a/build/runner/src/run.rs +++ b/build/runner/src/run.rs @@ -83,7 +83,7 @@ fn split_args(args: Vec) -> Vec> { pub fn run_command(command: &mut Command) { if let Err(err) = command.ensure_success() { - println!("{}", err); + println!("{err}"); std::process::exit(1); } } diff --git a/ftl/src/serialize.rs b/ftl/src/serialize.rs index c6eda559c..73513df69 100644 --- a/ftl/src/serialize.rs +++ b/ftl/src/serialize.rs @@ -435,7 +435,7 @@ impl TextWriter { item = item.trim_start_matches(' '); } - write!(self.buffer, "{}", item) + write!(self.buffer, "{item}") } fn write_char_into_indent(&mut self, ch: char) { diff --git a/ftl/src/string/mod.rs b/ftl/src/string/mod.rs index 1b64dd91c..e7bf2c5bd 100644 --- a/ftl/src/string/mod.rs +++ b/ftl/src/string/mod.rs @@ -67,7 +67,7 @@ fn additional_template_folder(dst_folder: &Utf8Path) -> Option { fn all_langs(lang_folder: &Utf8Path) -> Result> { std::fs::read_dir(lang_folder) - .with_context(|| format!("reading {:?}", lang_folder))? + .with_context(|| format!("reading {lang_folder:?}"))? .filter_map(Result::ok) .map(|e| Ok(e.path().utf8()?)) .collect() diff --git a/pylib/rsbridge/build.rs b/pylib/rsbridge/build.rs index 2940563cb..4671bc296 100644 --- a/pylib/rsbridge/build.rs +++ b/pylib/rsbridge/build.rs @@ -28,6 +28,6 @@ fn main() { .to_string(); let libs_path = stdlib_path + "s"; - println!("cargo:rustc-link-search={}", libs_path); + println!("cargo:rustc-link-search={libs_path}"); } } diff --git a/qt/launcher/src/bin/anki_console.rs b/qt/launcher/src/bin/anki_console.rs index 596377ba1..181db920f 100644 --- a/qt/launcher/src/bin/anki_console.rs +++ b/qt/launcher/src/bin/anki_console.rs @@ -12,7 +12,7 @@ use anyhow::Result; fn main() { if let Err(e) = run() { - eprintln!("Error: {:#}", e); + eprintln!("Error: {e:#}"); std::process::exit(1); } } diff --git a/qt/launcher/src/bin/build_win.rs b/qt/launcher/src/bin/build_win.rs index 3ad2c7ce0..fc9082bf2 100644 --- a/qt/launcher/src/bin/build_win.rs +++ b/qt/launcher/src/bin/build_win.rs @@ -221,7 +221,7 @@ fn generate_install_manifest(output_dir: &Path) -> Result<()> { // Convert to Windows-style backslashes for NSIS let windows_path = relative_path.display().to_string().replace('/', "\\"); // Use Windows line endings (\r\n) as expected by NSIS - manifest_content.push_str(&format!("{}\r\n", windows_path)); + manifest_content.push_str(&format!("{windows_path}\r\n")); } } } diff --git a/qt/launcher/src/main.rs b/qt/launcher/src/main.rs index d9d639abe..3cfbca45a 100644 --- a/qt/launcher/src/main.rs +++ b/qt/launcher/src/main.rs @@ -64,7 +64,7 @@ pub enum MainMenuChoice { fn main() { if let Err(e) = run() { - eprintln!("Error: {:#}", e); + eprintln!("Error: {e:#}"); eprintln!("Press enter to close..."); let mut input = String::new(); let _ = stdin().read_line(&mut input); @@ -252,7 +252,7 @@ fn main_menu_loop(state: &State) -> Result<()> { // If sync fails due to things like a missing wheel on pypi, // we need to remove the lockfile or uv will cache the bad result. let _ = remove_file(&state.uv_lock_path); - println!("Install failed: {:#}", e); + println!("Install failed: {e:#}"); println!(); continue; } @@ -402,7 +402,7 @@ fn update_pyproject_for_version( ) } VersionKind::Uv(version) => { - content_str.replace("anki-release", &format!("anki-release=={}", version)) + content_str.replace("anki-release", &format!("anki-release=={version}")) } }; write_file(&user_pyproject_path, &updated_content)?; diff --git a/rslib/i18n/check.rs b/rslib/i18n/check.rs index f168406d1..48521bbdd 100644 --- a/rslib/i18n/check.rs +++ b/rslib/i18n/check.rs @@ -21,14 +21,11 @@ pub fn check(lang_map: &TranslationsByLang) { fn check_content(lang: &str, fname: &str, content: &str) { let lang_id: LanguageIdentifier = "en-US".parse().unwrap(); let resource = FluentResource::try_new(content.into()).unwrap_or_else(|e| { - panic!("{}\nUnable to parse {}/{}: {:?}", content, lang, fname, e); + panic!("{content}\nUnable to parse {lang}/{fname}: {e:?}"); }); let mut bundle: FluentBundle = FluentBundle::new(vec![lang_id]); bundle.add_resource(resource).unwrap_or_else(|e| { - panic!( - "{}\nUnable to bundle - duplicate key? {}/{}: {:?}", - content, lang, fname, e - ); + panic!("{content}\nUnable to bundle - duplicate key? {lang}/{fname}: {e:?}"); }); } diff --git a/rslib/i18n/gather.rs b/rslib/i18n/gather.rs index a25e5813e..835e108af 100644 --- a/rslib/i18n/gather.rs +++ b/rslib/i18n/gather.rs @@ -48,8 +48,7 @@ fn add_folder(map: &mut TranslationsByLang, folder: &Path, lang: &str) { let text = fs::read_to_string(entry.path()).unwrap(); assert!( text.ends_with('\n'), - "file was missing final newline: {:?}", - entry + "file was missing final newline: {entry:?}" ); map_entry.entry(module).or_default().push_str(&text); println!("cargo:rerun-if-changed={}", entry.path().to_str().unwrap()); diff --git a/rslib/i18n/src/lib.rs b/rslib/i18n/src/lib.rs index 1d79198bf..bfd6f5ba2 100644 --- a/rslib/i18n/src/lib.rs +++ b/rslib/i18n/src/lib.rs @@ -130,7 +130,7 @@ fn get_bundle( ) -> Option> { let res = FluentResource::try_new(text.into()) .map_err(|e| { - println!("Unable to parse translations file: {:?}", e); + println!("Unable to parse translations file: {e:?}"); }) .ok()?; @@ -138,14 +138,14 @@ fn get_bundle( bundle .add_resource(res) .map_err(|e| { - println!("Duplicate key detected in translation file: {:?}", e); + println!("Duplicate key detected in translation file: {e:?}"); }) .ok()?; if !extra_text.is_empty() { match FluentResource::try_new(extra_text) { Ok(res) => bundle.add_resource_overriding(res), - Err((_res, e)) => println!("Unable to parse translations file: {:?}", e), + Err((_res, e)) => println!("Unable to parse translations file: {e:?}"), } } @@ -291,7 +291,7 @@ impl I18n { let mut errs = vec![]; let out = bundle.format_pattern(pat, args.as_ref(), &mut errs); if !errs.is_empty() { - println!("Error(s) in translation '{}': {:?}", key, errs); + println!("Error(s) in translation '{key}': {errs:?}"); } // clone so we can discard args return out.to_string().into(); diff --git a/rslib/i18n/typescript.rs b/rslib/i18n/typescript.rs index 0c2230338..ce30048e2 100644 --- a/rslib/i18n/typescript.rs +++ b/rslib/i18n/typescript.rs @@ -81,7 +81,7 @@ fn get_args(variables: &[Variable]) -> String { .iter() .map(|v| format!("\"{}\": args.{}", v.name, typescript_arg_name(&v.name))) .join(", "); - format!("{{{}}}", out) + format!("{{{out}}}") } } diff --git a/rslib/i18n/write_strings.rs b/rslib/i18n/write_strings.rs index f9df5716f..36af62eeb 100644 --- a/rslib/i18n/write_strings.rs +++ b/rslib/i18n/write_strings.rs @@ -69,12 +69,6 @@ impl I18n { {var_build} self.translate("{key}"{out_args}) }}"#, - func = func, - key = key, - doc = doc, - in_args = in_args, - out_args = out_args, - var_build = var_build, ) .unwrap(); } @@ -103,9 +97,6 @@ fn build_vars(translation: &Translation) -> String { writeln!( buf, r#" args.set("{fluent_name}", {rust_name}{trailer});"#, - fluent_name = fluent_name, - rust_name = rust_name, - trailer = trailer, ) .unwrap(); } @@ -204,13 +195,7 @@ pub(crate) const {lang_name}: phf::Map<&str, &str> = phf::phf_map! {{", .unwrap(); for (module, contents) in modules { - writeln!( - buf, - r###" "{module}" => r##"{contents}"##,"###, - module = module, - contents = contents - ) - .unwrap(); + writeln!(buf, r###" "{module}" => r##"{contents}"##,"###).unwrap(); } buf.push_str("};\n"); diff --git a/rslib/proto/python.rs b/rslib/proto/python.rs index 0ca2c15ea..6a7b5653b 100644 --- a/rslib/proto/python.rs +++ b/rslib/proto/python.rs @@ -183,9 +183,9 @@ fn python_type(field: &FieldDescriptor, output: bool) -> String { }; if field.is_list() { if output { - format!("Sequence[{}]", kind) + format!("Sequence[{kind}]") } else { - format!("Iterable[{}]", kind) + format!("Iterable[{kind}]") } } else if field.is_map() { let map_kind = field.kind(); diff --git a/rslib/rust_interface.rs b/rslib/rust_interface.rs index a75100b5b..6861df7dc 100644 --- a/rslib/rust_interface.rs +++ b/rslib/rust_interface.rs @@ -263,7 +263,7 @@ impl MethodHelpers for Method { fn get_input_arg_with_label(&self) -> String { self.input_type() .as_ref() - .map(|t| format!("input: {}", t)) + .map(|t| format!("input: {t}")) .unwrap_or_default() } diff --git a/rslib/src/browser_table.rs b/rslib/src/browser_table.rs index 022708a80..85b0572d3 100644 --- a/rslib/src/browser_table.rs +++ b/rslib/src/browser_table.rs @@ -515,7 +515,7 @@ impl RowContext { return "".into(); }; if self.cards[0].is_undue_queue() { - format!("({})", due) + format!("({due})") } else { due.into() } @@ -623,7 +623,7 @@ impl RowContext { if self.notes_mode { let decks = self.cards.iter().map(|c| c.deck_id).unique().count(); if decks > 1 { - return format!("({})", decks); + return format!("({decks})"); } } let deck_name = self.deck.human_name(); diff --git a/rslib/src/card_rendering/writer.rs b/rslib/src/card_rendering/writer.rs index 892cb9087..22fb1fb34 100644 --- a/rslib/src/card_rendering/writer.rs +++ b/rslib/src/card_rendering/writer.rs @@ -52,7 +52,7 @@ trait Write { } fn write_sound(&mut self, buf: &mut String, resource: &str) { - write!(buf, "[sound:{}]", resource).unwrap(); + write!(buf, "[sound:{resource}]").unwrap(); } fn write_directive(&mut self, buf: &mut String, directive: &Directive) { @@ -94,9 +94,9 @@ trait Write { fn write_directive_option(&mut self, buf: &mut String, key: &str, val: &str) { if val.contains([']', ' ', '\t', '\r', '\n']) { - write!(buf, " {}=\"{}\"", key, val).unwrap(); + write!(buf, " {key}=\"{val}\"").unwrap(); } else { - write!(buf, " {}={}", key, val).unwrap(); + write!(buf, " {key}={val}").unwrap(); } } @@ -158,7 +158,7 @@ impl Write for AvExtractor<'_> { fn write_tts_directive(&mut self, buf: &mut String, directive: &TtsDirective) { if let Some(error) = directive.error(self.tr) { - write!(buf, "[{}]", error).unwrap(); + write!(buf, "[{error}]").unwrap(); return; } @@ -173,7 +173,7 @@ impl Write for AvExtractor<'_> { other_args: directive .options .iter() - .map(|(key, val)| format!("{}={}", key, val)) + .map(|(key, val)| format!("{key}={val}")) .collect(), }, )), @@ -204,7 +204,7 @@ impl AvPrettifier { impl Write for AvPrettifier { fn write_sound(&mut self, buf: &mut String, resource: &str) { - write!(buf, "🔉{}🔉", resource).unwrap(); + write!(buf, "🔉{resource}🔉").unwrap(); } fn write_tts_directive(&mut self, buf: &mut String, directive: &TtsDirective) { diff --git a/rslib/src/config/deck.rs b/rslib/src/config/deck.rs index d684534c0..a88ca61a7 100644 --- a/rslib/src/config/deck.rs +++ b/rslib/src/config/deck.rs @@ -41,5 +41,5 @@ impl Collection { } fn build_aux_deck_key(deck: DeckId, key: &str) -> String { - format!("_deck_{deck}_{key}", deck = deck, key = key) + format!("_deck_{deck}_{key}") } diff --git a/rslib/src/config/notetype.rs b/rslib/src/config/notetype.rs index 0d3fd9611..f9b70292d 100644 --- a/rslib/src/config/notetype.rs +++ b/rslib/src/config/notetype.rs @@ -32,7 +32,7 @@ impl Collection { }; Ok(get_aux_notetype_config_key( ntid, - &format!("{}_{}", key, ordinal), + &format!("{key}_{ordinal}"), )) } } @@ -70,5 +70,5 @@ impl Collection { } pub fn get_aux_notetype_config_key(ntid: NotetypeId, key: &str) -> String { - format!("_nt_{ntid}_{key}", ntid = ntid, key = key) + format!("_nt_{ntid}_{key}") } diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index ae960ab5c..f58a2184a 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -387,10 +387,10 @@ impl Collection { let mut basic = all_stock_notetypes(&self.tr).remove(0); let mut field = 3; while basic.fields.len() < field_count { - basic.add_field(format!("{}", field)); + basic.add_field(format!("{field}")); field += 1; } - basic.name = format!("db-check-{}-{}", stamp, field_count); + basic.name = format!("db-check-{stamp}-{field_count}"); let qfmt = basic.templates[0].config.q_format.clone(); let afmt = basic.templates[0].config.a_format.clone(); for n in 0..extra_cards_required { diff --git a/rslib/src/decks/addupdate.rs b/rslib/src/decks/addupdate.rs index be4cb34cd..eb9e242a5 100644 --- a/rslib/src/decks/addupdate.rs +++ b/rslib/src/decks/addupdate.rs @@ -93,7 +93,7 @@ impl Collection { pub(crate) fn recover_missing_deck(&mut self, did: DeckId, usn: Usn) -> Result<()> { let mut deck = Deck::new_normal(); deck.id = did; - deck.name = NativeDeckName::from_native_str(format!("recovered{}", did)); + deck.name = NativeDeckName::from_native_str(format!("recovered{did}")); deck.set_modified(usn); self.add_or_update_single_deck_with_existing_id(&mut deck, usn) } diff --git a/rslib/src/error/db.rs b/rslib/src/error/db.rs index b44f771dc..a36cd1a60 100644 --- a/rslib/src/error/db.rs +++ b/rslib/src/error/db.rs @@ -67,7 +67,7 @@ impl From for AnkiError { } AnkiError::DbError { source: DbError { - info: format!("{:?}", err), + info: format!("{err:?}"), kind: DbErrorKind::Other, }, } @@ -88,7 +88,7 @@ impl From for AnkiError { } AnkiError::DbError { source: DbError { - info: format!("{:?}", err), + info: format!("{err:?}"), kind: DbErrorKind::Other, }, } @@ -101,7 +101,7 @@ impl DbError { DbErrorKind::Corrupt => self.info.clone(), // fixme: i18n DbErrorKind::Locked => "Anki already open, or media currently syncing.".into(), - _ => format!("{:?}", self), + _ => format!("{self:?}"), } } } diff --git a/rslib/src/error/invalid_input.rs b/rslib/src/error/invalid_input.rs index f62174578..970e1c692 100644 --- a/rslib/src/error/invalid_input.rs +++ b/rslib/src/error/invalid_input.rs @@ -26,7 +26,7 @@ impl InvalidInputError { pub fn context(&self) -> String { if let Some(source) = &self.source { - format!("{}", source) + format!("{source}") } else { String::new() } diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index 0da89e0ff..d2bd11cf0 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -149,13 +149,13 @@ impl AnkiError { } CardTypeErrorDetails::MissingCloze => tr.card_templates_missing_cloze(), }; - format!("{}
{}", header, details) + format!("{header}
{details}") } AnkiError::DbError { source } => source.message(tr), AnkiError::SearchError { source } => source.message(tr), AnkiError::ParseNumError => tr.errors_parse_number_fail().into(), AnkiError::FilteredDeckError { source } => source.message(tr), - AnkiError::InvalidRegex { info: source } => format!("
{}
", source), + AnkiError::InvalidRegex { info: source } => format!("
{source}
"), AnkiError::MultipleNotetypesSelected => tr.errors_multiple_notetypes_selected().into(), AnkiError::DatabaseCheckRequired => tr.errors_please_check_database().into(), AnkiError::MediaCheckRequired => tr.errors_please_check_media().into(), @@ -172,7 +172,7 @@ impl AnkiError { | AnkiError::InvalidServiceIndex | AnkiError::InvalidMethodIndex | AnkiError::UndoEmpty - | AnkiError::InvalidCertificateFormat => format!("{:?}", self), + | AnkiError::InvalidCertificateFormat => format!("{self:?}"), AnkiError::FileIoError { source } => source.message(), AnkiError::InvalidInput { source } => source.message(), AnkiError::NotFound { source } => source.message(tr), diff --git a/rslib/src/error/network.rs b/rslib/src/error/network.rs index 469978cff..eb293c359 100644 --- a/rslib/src/error/network.rs +++ b/rslib/src/error/network.rs @@ -68,7 +68,7 @@ impl AnkiError { impl From<&reqwest::Error> for AnkiError { fn from(err: &reqwest::Error) -> Self { let url = err.url().map(|url| url.as_str()).unwrap_or(""); - let str_err = format!("{}", err); + let str_err = format!("{err}"); // strip url from error to avoid exposing keys let info = str_err.replace(url, ""); @@ -205,7 +205,7 @@ impl NetworkError { NetworkErrorKind::Other => tr.network_other(), }; let details = tr.network_details(self.info.as_str()); - format!("{}\n\n{}", summary, details) + format!("{summary}\n\n{details}") } } @@ -226,7 +226,7 @@ impl From for AnkiError { } .into() } else { - AnkiError::sync_error(format!("{:?}", err), SyncErrorKind::Other) + AnkiError::sync_error(format!("{err:?}"), SyncErrorKind::Other) } } } diff --git a/rslib/src/image_occlusion/imagedata.rs b/rslib/src/image_occlusion/imagedata.rs index 9319d85c6..fdf8ea4fd 100644 --- a/rslib/src/image_occlusion/imagedata.rs +++ b/rslib/src/image_occlusion/imagedata.rs @@ -77,7 +77,7 @@ impl Collection { ) -> Result { let value = match self.get_image_occlusion_note_inner(note_id) { Ok(note) => Value::Note(note), - Err(err) => Value::Error(format!("{:?}", err)), + Err(err) => Value::Error(format!("{err:?}")), }; Ok(GetImageOcclusionNoteResponse { value: Some(value) }) } diff --git a/rslib/src/image_occlusion/imageocclusion.rs b/rslib/src/image_occlusion/imageocclusion.rs index e2eea9a39..1de86bf87 100644 --- a/rslib/src/image_occlusion/imageocclusion.rs +++ b/rslib/src/image_occlusion/imageocclusion.rs @@ -98,7 +98,7 @@ pub fn get_image_cloze_data(text: &str) -> String { let Some((x, y)) = point_pair.split_once(',') else { continue; }; - write!(&mut point_str, "{},{} ", x, y).unwrap(); + write!(&mut point_str, "{x},{y} ").unwrap(); } // remove the trailing space point_str.pop(); diff --git a/rslib/src/latex.rs b/rslib/src/latex.rs index 3ebeebf8a..e5cb002ac 100644 --- a/rslib/src/latex.rs +++ b/rslib/src/latex.rs @@ -100,7 +100,7 @@ fn fname_for_latex(latex: &str, svg: bool) -> String { let ext = if svg { "svg" } else { "png" }; let csum = hex::encode(sha1_of_data(latex.as_bytes())); - format!("latex-{}.{}", csum, ext) + format!("latex-{csum}.{ext}") } fn image_link_for_fname(src: &str, fname: &str) -> String { @@ -122,11 +122,7 @@ mod test { assert_eq!( extract_latex("a[latex]one
and
two[/latex]b", false), ( - format!( - "a\"one
and
two\"b", - fname - ) - .into(), + format!("a\"one
and
two\"b").into(), vec![ExtractedLatex { fname: fname.into(), latex: "one\nand\ntwo".into() diff --git a/rslib/src/log.rs b/rslib/src/log.rs index 4fb4dcfaf..fedc597c4 100644 --- a/rslib/src/log.rs +++ b/rslib/src/log.rs @@ -69,8 +69,8 @@ fn maybe_rotate_log(path: &str) -> io::Result<()> { return Ok(()); } - let path2 = format!("{}.1", path); - let path3 = format!("{}.2", path); + let path2 = format!("{path}.1"); + let path3 = format!("{path}.2"); // if a rotated file already exists, rename it if let Err(e) = fs::rename(&path2, path3) { diff --git a/rslib/src/media/files.rs b/rslib/src/media/files.rs index 9fd3bc85f..6974e2f81 100644 --- a/rslib/src/media/files.rs +++ b/rslib/src/media/files.rs @@ -218,7 +218,7 @@ fn truncate_filename(fname: &str, max_bytes: usize) -> Cow { let mut new_name = if ext.is_empty() { stem.to_string() } else { - format!("{}.{}", stem, ext) + format!("{stem}.{ext}") }; // make sure we don't break Windows by ending with a space or dot diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 2b53321b9..932022e99 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -270,7 +270,7 @@ impl Note { self.fields .last_mut() .unwrap() - .push_str(&format!("; {}", last)); + .push_str(&format!("; {last}")); } } } diff --git a/rslib/src/notetype/schema11.rs b/rslib/src/notetype/schema11.rs index 272456ab7..8d713cbe7 100644 --- a/rslib/src/notetype/schema11.rs +++ b/rslib/src/notetype/schema11.rs @@ -126,7 +126,7 @@ fn other_to_bytes(other: &HashMap) -> Vec { } else { serde_json::to_vec(other).unwrap_or_else(|e| { // theoretically should never happen - println!("serialization failed for {:?}: {}", other, e); + println!("serialization failed for {other:?}: {e}"); vec![] }) } @@ -140,7 +140,7 @@ pub(crate) fn parse_other_fields( Default::default() } else { let mut map: HashMap = serde_json::from_slice(bytes).unwrap_or_else(|e| { - println!("deserialization failed for other: {}", e); + println!("deserialization failed for other: {e}"); Default::default() }); map.retain(|k, _v| !reserved.contains(k)); diff --git a/rslib/src/notetype/stock.rs b/rslib/src/notetype/stock.rs index f17f6b949..9b5df66d5 100644 --- a/rslib/src/notetype/stock.rs +++ b/rslib/src/notetype/stock.rs @@ -179,8 +179,8 @@ pub(crate) fn cloze(tr: &I18n) -> Notetype { let back_extra = tr.notetypes_back_extra_field(); config = nt.add_field(back_extra.as_ref()); config.tag = Some(ClozeField::BackExtra as u32); - let qfmt = format!("{{{{cloze:{}}}}}", text); - let afmt = format!("{}
\n{{{{{}}}}}", qfmt, back_extra); + let qfmt = format!("{{{{cloze:{text}}}}}"); + let afmt = format!("{qfmt}
\n{{{{{back_extra}}}}}"); nt.add_template(nt.name.clone(), qfmt, afmt); nt } diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index 8ae1518d0..ce6720d3d 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -889,22 +889,20 @@ pub(crate) mod test { ) -> Result<()> { // Change due time to fake card answer_time, // works since answer_time is calculated as due - last_ivl - let update_due_string = format!("update cards set due={}", shift_due_time); + let update_due_string = format!("update cards set due={shift_due_time}"); col.storage.db.execute_batch(&update_due_string)?; col.clear_study_queues(); let current_card_state = current_state(col, post_answer.card_id); let state = match current_card_state { CardState::Normal(NormalState::Learning(state)) => state, - _ => panic!("State is not Normal: {:?}", current_card_state), + _ => panic!("State is not Normal: {current_card_state:?}"), }; let elapsed_secs = state.elapsed_secs as i32; // Give a 1 second leeway when the test runs on the off chance // that the test runs as a second rolls over. assert!( (elapsed_secs - expected_elapsed_secs).abs() <= 1, - "elapsed_secs: {} != expected_elapsed_secs: {}", - elapsed_secs, - expected_elapsed_secs + "elapsed_secs: {elapsed_secs} != expected_elapsed_secs: {expected_elapsed_secs}" ); Ok(()) diff --git a/rslib/src/scheduler/filtered/mod.rs b/rslib/src/scheduler/filtered/mod.rs index f1f3cc07d..ad7979e3c 100644 --- a/rslib/src/scheduler/filtered/mod.rs +++ b/rslib/src/scheduler/filtered/mod.rs @@ -214,14 +214,14 @@ impl Collection { .search_terms .get_mut(0) .unwrap(); - term1.search = format!("{} is:due", search); + term1.search = format!("{search} is:due"); let term2 = deck .filtered_mut() .unwrap() .search_terms .get_mut(1) .unwrap(); - term2.search = format!("{} is:new", search); + term2.search = format!("{search} is:new"); } } diff --git a/rslib/src/scheduler/timespan.rs b/rslib/src/scheduler/timespan.rs index c779d33bc..b015e3e1e 100644 --- a/rslib/src/scheduler/timespan.rs +++ b/rslib/src/scheduler/timespan.rs @@ -25,7 +25,7 @@ pub fn answer_button_time_collapsible(seconds: u32, collapse_secs: u32, tr: &I18 if seconds == 0 { tr.scheduling_end().into() } else if seconds < collapse_secs { - format!("<{}", string) + format!("<{string}") } else { string } diff --git a/rslib/src/search/builder.rs b/rslib/src/search/builder.rs index 452f4d832..a76af0560 100644 --- a/rslib/src/search/builder.rs +++ b/rslib/src/search/builder.rs @@ -219,7 +219,7 @@ impl From for SearchNode { impl From for SearchNode { fn from(n: NoteId) -> Self { - SearchNode::NoteIds(format!("{}", n)) + SearchNode::NoteIds(format!("{n}")) } } diff --git a/rslib/src/search/mod.rs b/rslib/src/search/mod.rs index 63096dad8..ff21bf4ca 100644 --- a/rslib/src/search/mod.rs +++ b/rslib/src/search/mod.rs @@ -240,7 +240,7 @@ impl Collection { } else { self.storage.setup_searched_cards_table()?; } - let sql = format!("insert into search_cids {}", sql); + let sql = format!("insert into search_cids {sql}"); let cards = self .storage @@ -307,7 +307,7 @@ impl Collection { let (sql, args) = writer.build_query(&top_node, mode.required_table())?; self.storage.setup_searched_notes_table()?; - let sql = format!("insert into search_nids {}", sql); + let sql = format!("insert into search_nids {sql}"); let notes = self .storage diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 041ec4948..409862fce 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -277,7 +277,7 @@ fn unquoted_term(s: &str) -> IResult { Err(parse_failure( s, FailKind::UnknownEscape { - provided: format!("\\{}", c), + provided: format!("\\{c}"), }, )) } else if "\"() \u{3000}".contains(s.chars().next().unwrap()) { @@ -637,7 +637,7 @@ fn check_id_list<'a>(s: &'a str, context: &str) -> ParseResult<'a, &'a str> { s, // id lists are undocumented, so no translation FailKind::Other { - info: Some(format!("expected only digits and commas in {}:", context)), + info: Some(format!("expected only digits and commas in {context}:")), }, )) } @@ -1110,19 +1110,19 @@ mod test { for term in &["added", "edited", "rated", "resched"] { assert!(matches!( - failkind(&format!("{}:1.1", term)), + failkind(&format!("{term}:1.1")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("{}:-1", term)), + failkind(&format!("{term}:-1")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("{}:", term)), + failkind(&format!("{term}:")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("{}:foo", term)), + failkind(&format!("{term}:foo")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); } @@ -1223,19 +1223,19 @@ mod test { for term in &["ivl", "reps", "lapses", "pos"] { assert!(matches!( - failkind(&format!("prop:{}>", term)), + failkind(&format!("prop:{term}>")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("prop:{}=0.5", term)), + failkind(&format!("prop:{term}=0.5")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("prop:{}!=-1", term)), + failkind(&format!("prop:{term}!=-1")), SearchErrorKind::InvalidPositiveWholeNumber { .. } )); assert!(matches!( - failkind(&format!("prop:{} { }, SearchNode::Deck(deck) => self.write_deck(&norm(deck))?, SearchNode::NotetypeId(ntid) => { - write!(self.sql, "n.mid = {}", ntid).unwrap(); + write!(self.sql, "n.mid = {ntid}").unwrap(); } SearchNode::DeckIdsWithoutChildren(dids) => { write!( self.sql, - "c.did in ({}) or (c.odid != 0 and c.odid in ({}))", - dids, dids + "c.did in ({dids}) or (c.odid != 0 and c.odid in ({dids}))" ) .unwrap(); } @@ -175,13 +174,13 @@ impl SqlWriter<'_> { SearchNode::Tag { tag, is_re } => self.write_tag(&norm(tag), *is_re), SearchNode::State(state) => self.write_state(state)?, SearchNode::Flag(flag) => { - write!(self.sql, "(c.flags & 7) == {}", flag).unwrap(); + write!(self.sql, "(c.flags & 7) == {flag}").unwrap(); } SearchNode::NoteIds(nids) => { write!(self.sql, "{} in ({})", self.note_id_column(), nids).unwrap(); } SearchNode::CardIds(cids) => { - write!(self.sql, "c.id in ({})", cids).unwrap(); + write!(self.sql, "c.id in ({cids})").unwrap(); } SearchNode::Property { operator, kind } => self.write_prop(operator, kind)?, SearchNode::CustomData(key) => self.write_custom_data(key)?, @@ -199,7 +198,7 @@ impl SqlWriter<'_> { text }; // implicitly wrap in % - let text = format!("%{}%", text); + let text = format!("%{text}%"); self.args.push(text); let arg_idx = self.args.len(); @@ -279,7 +278,7 @@ impl SqlWriter<'_> { text => { write!(self.sql, "n.tags regexp ?").unwrap(); let re = &to_custom_re(text, r"\S"); - self.args.push(format!("(?i).* {}(::| ).*", re)); + self.args.push(format!("(?i).* {re}(::| ).*")); } } } @@ -293,10 +292,10 @@ impl SqlWriter<'_> { write!(self.sql, "c.id in (select cid from revlog where id").unwrap(); match op { - ">" => write!(self.sql, " >= {}", target_cutoff_ms), - ">=" => write!(self.sql, " >= {}", day_before_cutoff_ms), - "<" => write!(self.sql, " < {}", day_before_cutoff_ms), - "<=" => write!(self.sql, " < {}", target_cutoff_ms), + ">" => write!(self.sql, " >= {target_cutoff_ms}"), + ">=" => write!(self.sql, " >= {day_before_cutoff_ms}"), + "<" => write!(self.sql, " < {day_before_cutoff_ms}"), + "<=" => write!(self.sql, " < {target_cutoff_ms}"), "=" => write!( self.sql, " between {} and {}", @@ -314,7 +313,7 @@ impl SqlWriter<'_> { .unwrap(); match ease { - RatingKind::AnswerButton(u) => write!(self.sql, " and ease = {})", u), + RatingKind::AnswerButton(u) => write!(self.sql, " and ease = {u})"), RatingKind::AnyAnswerButton => write!(self.sql, " and ease > 0)"), RatingKind::ManualReschedule => write!(self.sql, " and ease = 0)"), } @@ -356,9 +355,9 @@ impl SqlWriter<'_> { pos = pos ) .unwrap(), - PropertyKind::Interval(ivl) => write!(self.sql, "ivl {} {}", op, ivl).unwrap(), - PropertyKind::Reps(reps) => write!(self.sql, "reps {} {}", op, reps).unwrap(), - PropertyKind::Lapses(days) => write!(self.sql, "lapses {} {}", op, days).unwrap(), + PropertyKind::Interval(ivl) => write!(self.sql, "ivl {op} {ivl}").unwrap(), + PropertyKind::Reps(reps) => write!(self.sql, "reps {op} {reps}").unwrap(), + PropertyKind::Lapses(days) => write!(self.sql, "lapses {op} {days}").unwrap(), PropertyKind::Ease(ease) => { write!(self.sql, "factor {} {}", op, (ease * 1000.0) as u32).unwrap() } @@ -474,7 +473,7 @@ impl SqlWriter<'_> { }; // convert to a regex that includes child decks - self.args.push(format!("(?i)^{}($|\x1f)", native_deck)); + self.args.push(format!("(?i)^{native_deck}($|\x1f)")); let arg_idx = self.args.len(); self.sql.push_str(&format!(concat!( "(c.did in (select id from decks where name regexp ?{n})", @@ -491,7 +490,7 @@ impl SqlWriter<'_> { let ids = self.col.storage.deck_id_with_children(&parent)?; let mut buf = String::new(); ids_to_string(&mut buf, &ids); - write!(self.sql, "c.did in {}", buf,).unwrap(); + write!(self.sql, "c.did in {buf}",).unwrap(); } else { self.sql.push_str("false") } @@ -502,7 +501,7 @@ impl SqlWriter<'_> { fn write_template(&mut self, template: &TemplateKind) { match template { TemplateKind::Ordinal(n) => { - write!(self.sql, "c.ord = {}", n).unwrap(); + write!(self.sql, "c.ord = {n}").unwrap(); } TemplateKind::Name(name) => { if is_glob(name) { @@ -550,7 +549,7 @@ impl SqlWriter<'_> { } fn write_all_fields_regexp(&mut self, val: &str) { - self.args.push(format!("(?i){}", val)); + self.args.push(format!("(?i){val}")); write!(self.sql, "regexp_fields(?{}, n.flds)", self.args.len()).unwrap(); } @@ -566,7 +565,7 @@ impl SqlWriter<'_> { return Ok(()); } - self.args.push(format!("(?i){}", val)); + self.args.push(format!("(?i){val}")); let arg_idx = self.args.len(); let all_notetype_clauses = field_indicies_by_notetype @@ -775,13 +774,13 @@ impl SqlWriter<'_> { fn write_added(&mut self, days: u32) -> Result<()> { let cutoff = self.previous_day_cutoff(days)?.as_millis(); - write!(self.sql, "c.id > {}", cutoff).unwrap(); + write!(self.sql, "c.id > {cutoff}").unwrap(); Ok(()) } fn write_edited(&mut self, days: u32) -> Result<()> { let cutoff = self.previous_day_cutoff(days)?; - write!(self.sql, "n.mod > {}", cutoff).unwrap(); + write!(self.sql, "n.mod > {cutoff}").unwrap(); Ok(()) } @@ -813,7 +812,7 @@ impl SqlWriter<'_> { } else { std::borrow::Cow::Borrowed(word) }; - self.args.push(format!(r"(?i){}", word)); + self.args.push(format!(r"(?i){word}")); let arg_idx = self.args.len(); if let Some(field_indices_by_notetype) = self.included_fields_for_unqualified_regex()? { let notetype_clause = |ctx: &UnqualifiedRegexSearchContext| -> String { diff --git a/rslib/src/search/writer.rs b/rslib/src/search/writer.rs index 600a18fd6..2158bffba 100644 --- a/rslib/src/search/writer.rs +++ b/rslib/src/search/writer.rs @@ -70,30 +70,30 @@ fn write_search_node(node: &SearchNode) -> String { match node { UnqualifiedText(s) => maybe_quote(&s.replace(':', "\\:")), SingleField { field, text, is_re } => write_single_field(field, text, *is_re), - AddedInDays(u) => format!("added:{}", u), - EditedInDays(u) => format!("edited:{}", u), - IntroducedInDays(u) => format!("introduced:{}", u), + AddedInDays(u) => format!("added:{u}"), + EditedInDays(u) => format!("edited:{u}"), + IntroducedInDays(u) => format!("introduced:{u}"), CardTemplate(t) => write_template(t), - Deck(s) => maybe_quote(&format!("deck:{}", s)), - DeckIdsWithoutChildren(s) => format!("did:{}", s), + Deck(s) => maybe_quote(&format!("deck:{s}")), + DeckIdsWithoutChildren(s) => format!("did:{s}"), // not exposed on the GUI end DeckIdWithChildren(_) => "".to_string(), - NotetypeId(NotetypeIdType(i)) => format!("mid:{}", i), - Notetype(s) => maybe_quote(&format!("note:{}", s)), + NotetypeId(NotetypeIdType(i)) => format!("mid:{i}"), + Notetype(s) => maybe_quote(&format!("note:{s}")), Rated { days, ease } => write_rated(days, ease), Tag { tag, is_re } => write_single_field("tag", tag, *is_re), Duplicates { notetype_id, text } => write_dupe(notetype_id, text), State(k) => write_state(k), - Flag(u) => format!("flag:{}", u), - NoteIds(s) => format!("nid:{}", s), - CardIds(s) => format!("cid:{}", s), + Flag(u) => format!("flag:{u}"), + NoteIds(s) => format!("nid:{s}"), + CardIds(s) => format!("cid:{s}"), Property { operator, kind } => write_property(operator, kind), WholeCollection => "deck:*".to_string(), - Regex(s) => maybe_quote(&format!("re:{}", s)), - NoCombining(s) => maybe_quote(&format!("nc:{}", s)), - WordBoundary(s) => maybe_quote(&format!("w:{}", s)), - CustomData(k) => maybe_quote(&format!("has-cd:{}", k)), - Preset(s) => maybe_quote(&format!("preset:{}", s)), + Regex(s) => maybe_quote(&format!("re:{s}")), + NoCombining(s) => maybe_quote(&format!("nc:{s}")), + WordBoundary(s) => maybe_quote(&format!("w:{s}")), + CustomData(k) => maybe_quote(&format!("has-cd:{k}")), + Preset(s) => maybe_quote(&format!("preset:{s}")), } } @@ -128,23 +128,23 @@ fn write_single_field(field: &str, text: &str, is_re: bool) -> String { fn write_template(template: &TemplateKind) -> String { match template { TemplateKind::Ordinal(u) => format!("card:{}", u + 1), - TemplateKind::Name(s) => maybe_quote(&format!("card:{}", s)), + TemplateKind::Name(s) => maybe_quote(&format!("card:{s}")), } } fn write_rated(days: &u32, ease: &RatingKind) -> String { use RatingKind::*; match ease { - AnswerButton(n) => format!("rated:{}:{}", days, n), - AnyAnswerButton => format!("rated:{}", days), - ManualReschedule => format!("resched:{}", days), + AnswerButton(n) => format!("rated:{days}:{n}"), + AnyAnswerButton => format!("rated:{days}"), + ManualReschedule => format!("resched:{days}"), } } /// Escape double quotes and backslashes: \" fn write_dupe(notetype_id: &NotetypeId, text: &str) -> String { let esc = text.replace('\\', r"\\"); - maybe_quote(&format!("dupe:{},{}", notetype_id, esc)) + maybe_quote(&format!("dupe:{notetype_id},{esc}")) } fn write_state(kind: &StateKind) -> String { @@ -167,19 +167,19 @@ fn write_state(kind: &StateKind) -> String { fn write_property(operator: &str, kind: &PropertyKind) -> String { use PropertyKind::*; match kind { - Due(i) => format!("prop:due{}{}", operator, i), - Interval(u) => format!("prop:ivl{}{}", operator, u), - Reps(u) => format!("prop:reps{}{}", operator, u), - Lapses(u) => format!("prop:lapses{}{}", operator, u), - Ease(f) => format!("prop:ease{}{}", operator, f), - Position(u) => format!("prop:pos{}{}", operator, u), - Stability(u) => format!("prop:s{}{}", operator, u), - Difficulty(u) => format!("prop:d{}{}", operator, u), - Retrievability(u) => format!("prop:r{}{}", operator, u), + Due(i) => format!("prop:due{operator}{i}"), + Interval(u) => format!("prop:ivl{operator}{u}"), + Reps(u) => format!("prop:reps{operator}{u}"), + Lapses(u) => format!("prop:lapses{operator}{u}"), + Ease(f) => format!("prop:ease{operator}{f}"), + Position(u) => format!("prop:pos{operator}{u}"), + Stability(u) => format!("prop:s{operator}{u}"), + Difficulty(u) => format!("prop:d{operator}{u}"), + Retrievability(u) => format!("prop:r{operator}{u}"), Rated(u, ease) => match ease { - RatingKind::AnswerButton(val) => format!("prop:rated{}{}:{}", operator, u, val), - RatingKind::AnyAnswerButton => format!("prop:rated{}{}", operator, u), - RatingKind::ManualReschedule => format!("prop:resched{}{}", operator, u), + RatingKind::AnswerButton(val) => format!("prop:rated{operator}{u}:{val}"), + RatingKind::AnyAnswerButton => format!("prop:rated{operator}{u}"), + RatingKind::ManualReschedule => format!("prop:resched{operator}{u}"), }, CustomDataNumber { key, value } => format!("prop:cdn:{key}{operator}{value}"), CustomDataString { key, value } => { diff --git a/rslib/src/storage/card/mod.rs b/rslib/src/storage/card/mod.rs index 38cf5ef0f..0205aef0d 100644 --- a/rslib/src/storage/card/mod.rs +++ b/rslib/src/storage/card/mod.rs @@ -829,8 +829,7 @@ impl fmt::Display for ReviewOrderSubclause { ReviewOrderSubclause::RetrievabilitySm2 { today, order } => { temp_string = format!( // - (elapsed days+0.001)/(scheduled interval) - "-(1 + cast({today}-due+0.001 as real)/ivl) {order}", - today = today + "-(1 + cast({today}-due+0.001 as real)/ivl) {order}" ); &temp_string } @@ -844,7 +843,7 @@ impl fmt::Display for ReviewOrderSubclause { ReviewOrderSubclause::Added => "nid asc, ord asc", ReviewOrderSubclause::ReverseAdded => "nid desc, ord asc", }; - write!(f, "{}", clause) + write!(f, "{clause}") } } diff --git a/rslib/src/storage/deck/mod.rs b/rslib/src/storage/deck/mod.rs index 7b1e08d58..d47d03894 100644 --- a/rslib/src/storage/deck/mod.rs +++ b/rslib/src/storage/deck/mod.rs @@ -33,7 +33,7 @@ fn row_to_deck(row: &Row) -> Result { common, kind: kind.kind.ok_or_else(|| { AnkiError::db_error( - format!("invalid deck kind: {}", id), + format!("invalid deck kind: {id}"), DbErrorKind::MissingEntity, ) })?, @@ -347,8 +347,8 @@ impl SqliteStorage { ))?; let top = current.name.as_native_str(); - let prefix_start = &format!("{}\x1f", top); - let prefix_end = &format!("{}\x20", top); + let prefix_start = &format!("{top}\x1f"); + let prefix_end = &format!("{top}\x20"); self.db .prepare_cached(include_str!("update_active.sql"))? @@ -379,7 +379,7 @@ impl SqliteStorage { let decks = self .get_schema11_decks() .map_err(|e| AnkiError::JsonError { - info: format!("decoding decks: {}", e), + info: format!("decoding decks: {e}"), })?; let mut names = HashSet::new(); for (_id, deck) in decks { diff --git a/rslib/src/storage/deckconfig/mod.rs b/rslib/src/storage/deckconfig/mod.rs index 2103e1512..5cc39cfc8 100644 --- a/rslib/src/storage/deckconfig/mod.rs +++ b/rslib/src/storage/deckconfig/mod.rs @@ -197,7 +197,7 @@ impl SqliteStorage { serde_json::from_value(conf) }) .map_err(|e| AnkiError::JsonError { - info: format!("decoding deck config: {}", e), + info: format!("decoding deck config: {e}"), }) })?; for (id, mut conf) in conf.into_iter() { diff --git a/rslib/src/storage/mod.rs b/rslib/src/storage/mod.rs index f240555eb..948bc30e4 100644 --- a/rslib/src/storage/mod.rs +++ b/rslib/src/storage/mod.rs @@ -52,7 +52,7 @@ where { let mut trailing_sep = false; for id in ids { - write!(buf, "{},", id).unwrap(); + write!(buf, "{id},").unwrap(); trailing_sep = true; } if trailing_sep { diff --git a/rslib/src/storage/notetype/mod.rs b/rslib/src/storage/notetype/mod.rs index 88c4074ac..692b68887 100644 --- a/rslib/src/storage/notetype/mod.rs +++ b/rslib/src/storage/notetype/mod.rs @@ -345,7 +345,7 @@ impl SqliteStorage { let nts = self .get_schema11_notetypes() .map_err(|e| AnkiError::JsonError { - info: format!("decoding models: {:?}", e), + info: format!("decoding models: {e:?}"), })?; let mut names = HashSet::new(); for (mut ntid, nt) in nts { diff --git a/rslib/src/storage/sqlite.rs b/rslib/src/storage/sqlite.rs index e31fdd46a..e9ae55a3b 100644 --- a/rslib/src/storage/sqlite.rs +++ b/rslib/src/storage/sqlite.rs @@ -587,7 +587,7 @@ impl SqliteStorage { }) { Ok(corrupt) => corrupt, Err(e) => { - println!("error: {:?}", e); + println!("error: {e:?}"); true } } diff --git a/rslib/src/storage/sync.rs b/rslib/src/storage/sync.rs index 4bd0e5242..256566d68 100644 --- a/rslib/src/storage/sync.rs +++ b/rslib/src/storage/sync.rs @@ -54,7 +54,7 @@ impl SqliteStorage { if let Some(new_usn) = server_usn_if_client { let mut stmt = self .db - .prepare_cached(&format!("update {} set usn=? where id=?", table))?; + .prepare_cached(&format!("update {table} set usn=? where id=?"))?; for id in ids { stmt.execute(params![new_usn, id])?; } diff --git a/rslib/src/storage/sync_check.rs b/rslib/src/storage/sync_check.rs index 50e92f7d0..7693a5921 100644 --- a/rslib/src/storage/sync_check.rs +++ b/rslib/src/storage/sync_check.rs @@ -11,7 +11,7 @@ impl SqliteStorage { fn table_has_usn(&self, table: &str) -> Result { Ok(self .db - .prepare(&format!("select null from {} where usn=-1", table))? + .prepare(&format!("select null from {table} where usn=-1"))? .query([])? .next()? .is_some()) @@ -19,7 +19,7 @@ impl SqliteStorage { fn table_count(&self, table: &str) -> Result { self.db - .query_row(&format!("select count() from {}", table), [], |r| r.get(0)) + .query_row(&format!("select count() from {table}"), [], |r| r.get(0)) .map_err(Into::into) } @@ -36,7 +36,7 @@ impl SqliteStorage { ] { if self.table_has_usn(table)? { return Err(AnkiError::sync_error( - format!("table had usn=-1: {}", table), + format!("table had usn=-1: {table}"), SyncErrorKind::Other, )); } diff --git a/rslib/src/sync/collection/tests.rs b/rslib/src/sync/collection/tests.rs index abf82262f..a7aa6cc8d 100644 --- a/rslib/src/sync/collection/tests.rs +++ b/rslib/src/sync/collection/tests.rs @@ -100,7 +100,7 @@ where _lock = LOCK.lock().await; endpoint } else { - format!("http://{}/", addr) + format!("http://{addr}/") }; let endpoint = Url::try_from(endpoint.as_str()).unwrap(); let auth = SyncAuth { @@ -734,7 +734,7 @@ async fn regular_sync(ctx: &SyncTestContext) -> Result<()> { for table in &["cards", "notes", "decks"] { assert_eq!( col1.storage - .db_scalar::(&format!("select count() from {}", table))?, + .db_scalar::(&format!("select count() from {table}"))?, 2 ); } @@ -754,7 +754,7 @@ async fn regular_sync(ctx: &SyncTestContext) -> Result<()> { for table in &["cards", "notes", "decks"] { assert_eq!( col2.storage - .db_scalar::(&format!("select count() from {}", table))?, + .db_scalar::(&format!("select count() from {table}"))?, 1 ); } diff --git a/rslib/src/sync/media/database/client/mod.rs b/rslib/src/sync/media/database/client/mod.rs index 5fe493679..f9c6e5ed1 100644 --- a/rslib/src/sync/media/database/client/mod.rs +++ b/rslib/src/sync/media/database/client/mod.rs @@ -285,7 +285,7 @@ fn row_to_name_and_checksum(row: &Row) -> error::Result<(String, Sha1Hash)> { fn trace(event: rusqlite::trace::TraceEvent) { if let rusqlite::trace::TraceEvent::Stmt(_, sql) = event { - println!("sql: {}", sql); + println!("sql: {sql}"); } } diff --git a/rslib/src/tags/findreplace.rs b/rslib/src/tags/findreplace.rs index 5db6e3ed2..b60b5ed88 100644 --- a/rslib/src/tags/findreplace.rs +++ b/rslib/src/tags/findreplace.rs @@ -35,7 +35,7 @@ impl Collection { }; if !match_case { - search = format!("(?i){}", search).into(); + search = format!("(?i){search}").into(); } self.transact(Op::UpdateTag, |col| { diff --git a/rslib/src/tags/matcher.rs b/rslib/src/tags/matcher.rs index b4961015e..d3c6ad88b 100644 --- a/rslib/src/tags/matcher.rs +++ b/rslib/src/tags/matcher.rs @@ -33,7 +33,7 @@ impl TagMatcher { (?:^|\ ) # 1: the tag prefix ( - {} + {tags} ) (?: # 2: an optional child separator @@ -41,8 +41,7 @@ impl TagMatcher { # or a space/end of string the end of the string |\ |$ ) - "#, - tags + "# ))?; Ok(Self { @@ -61,7 +60,7 @@ impl TagMatcher { let out = self.regex.replace(tag, |caps: &Captures| { // if we captured the child separator, add it to the replacement if caps.get(2).is_some() { - Cow::Owned(format!("{}::", replacement)) + Cow::Owned(format!("{replacement}::")) } else { Cow::Borrowed(replacement) } @@ -92,7 +91,7 @@ impl TagMatcher { let replacement = replacer(caps.get(1).unwrap().as_str()); // if we captured the child separator, add it to the replacement if caps.get(2).is_some() { - format!("{}::", replacement) + format!("{replacement}::") } else { replacement } diff --git a/rslib/src/tags/reparent.rs b/rslib/src/tags/reparent.rs index cbab806ff..4976b760e 100644 --- a/rslib/src/tags/reparent.rs +++ b/rslib/src/tags/reparent.rs @@ -109,7 +109,7 @@ fn reparented_name(existing_name: &str, new_parent: Option<&str>) -> Option baz::bar - let new_name = format!("{}::{}", new_parent, existing_base); + let new_name = format!("{new_parent}::{existing_base}"); if new_name != existing_name { Some(new_name) } else { diff --git a/rslib/src/template.rs b/rslib/src/template.rs index e3a900a2b..4895cc162 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -265,10 +265,8 @@ fn template_error_to_anki_error( }; let details = htmlescape::encode_minimal(&localized_template_error(tr, err)); let more_info = tr.card_template_rendering_more_info(); - let source = format!( - "{}
{}
{}", - header, details, TEMPLATE_ERROR_LINK, more_info - ); + let source = + format!("{header}
{details}
{more_info}"); AnkiError::TemplateError { info: source } } @@ -279,32 +277,29 @@ fn localized_template_error(tr: &I18n, err: TemplateError) -> String { .card_template_rendering_no_closing_brackets("}}", tag) .into(), TemplateError::ConditionalNotClosed(tag) => tr - .card_template_rendering_conditional_not_closed(format!("{{{{/{}}}}}", tag)) + .card_template_rendering_conditional_not_closed(format!("{{{{/{tag}}}}}")) .into(), TemplateError::ConditionalNotOpen { closed, currently_open, } => if let Some(open) = currently_open { tr.card_template_rendering_wrong_conditional_closed( - format!("{{{{/{}}}}}", closed), - format!("{{{{/{}}}}}", open), + format!("{{{{/{closed}}}}}"), + format!("{{{{/{open}}}}}"), ) } else { tr.card_template_rendering_conditional_not_open( - format!("{{{{/{}}}}}", closed), - format!("{{{{#{}}}}}", closed), - format!("{{{{^{}}}}}", closed), + format!("{{{{/{closed}}}}}"), + format!("{{{{#{closed}}}}}"), + format!("{{{{^{closed}}}}}"), ) } .into(), TemplateError::FieldNotFound { field, filters } => tr - .card_template_rendering_no_such_field(format!("{{{{{}{}}}}}", filters, field), field) + .card_template_rendering_no_such_field(format!("{{{{{filters}{field}}}}}"), field) .into(), TemplateError::NoSuchConditional(condition) => tr - .card_template_rendering_no_such_field( - format!("{{{{{}}}}}", condition), - &condition[1..], - ) + .card_template_rendering_no_such_field(format!("{{{{{condition}}}}}"), &condition[1..]) .into(), } } @@ -523,10 +518,7 @@ impl RenderContext<'_> { Ok(false ^ negated) } else { let prefix = if negated { "^" } else { "#" }; - Err(TemplateError::NoSuchConditional(format!( - "{}{}", - prefix, key - ))) + Err(TemplateError::NoSuchConditional(format!("{prefix}{key}"))) } } } @@ -858,14 +850,14 @@ fn nodes_to_string(buf: &mut String, nodes: &[ParsedNode]) { .unwrap(); } ParsedNode::Conditional { key, children } => { - write!(buf, "{{{{#{}}}}}", key).unwrap(); + write!(buf, "{{{{#{key}}}}}").unwrap(); nodes_to_string(buf, children); - write!(buf, "{{{{/{}}}}}", key).unwrap(); + write!(buf, "{{{{/{key}}}}}").unwrap(); } ParsedNode::NegatedConditional { key, children } => { - write!(buf, "{{{{^{}}}}}", key).unwrap(); + write!(buf, "{{{{^{key}}}}}").unwrap(); nodes_to_string(buf, children); - write!(buf, "{{{{/{}}}}}", key).unwrap(); + write!(buf, "{{{{/{key}}}}}").unwrap(); } } } diff --git a/rslib/src/template_filters.rs b/rslib/src/template_filters.rs index cb3504fe3..4949e756d 100644 --- a/rslib/src/template_filters.rs +++ b/rslib/src/template_filters.rs @@ -165,15 +165,15 @@ fn furigana_filter(text: &str) -> Cow { /// convert to [[type:...]] for the gui code to process fn type_filter<'a>(field_name: &str) -> Cow<'a, str> { - format!("[[type:{}]]", field_name).into() + format!("[[type:{field_name}]]").into() } fn type_cloze_filter<'a>(field_name: &str) -> Cow<'a, str> { - format!("[[type:cloze:{}]]", field_name).into() + format!("[[type:cloze:{field_name}]]").into() } fn type_nc_filter<'a>(field_name: &str) -> Cow<'a, str> { - format!("[[type:nc:{}]]", field_name).into() + format!("[[type:nc:{field_name}]]").into() } fn hint_filter<'a>(text: &'a str, field_name: &str) -> Cow<'a, str> { @@ -191,18 +191,17 @@ fn hint_filter<'a>(text: &'a str, field_name: &str) -> Cow<'a, str> { r##" -{} - -"##, - id, field_name, id, text +{field_name} + +"## ) .into() } fn tts_filter(options: &str, text: &str) -> String { - format!("[anki:tts lang={}]{}[/anki:tts]", options, text) + format!("[anki:tts lang={options}]{text}[/anki:tts]") } // Tests diff --git a/rslib/src/text.rs b/rslib/src/text.rs index f83332ff8..590c05b39 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -484,7 +484,7 @@ pub(crate) fn to_custom_re<'a>(txt: &'a str, wildcard: &str) -> Cow<'a, str> { match s { r"\\" | r"\*" => s.to_string(), r"\_" => "_".to_string(), - "*" => format!("{}*", wildcard), + "*" => format!("{wildcard}*"), "_" => wildcard.to_string(), s => regex::escape(s), } diff --git a/rust-toolchain.toml b/rust-toolchain.toml index fa07f7fa5..8a21ec74e 100644 --- a/rust-toolchain.toml +++ b/rust-toolchain.toml @@ -1,3 +1,3 @@ [toolchain] # older versions may fail to compile; newer versions may fail the clippy tests -channel = "1.87.0" +channel = "1.88.0" diff --git a/tools/minilints/src/main.rs b/tools/minilints/src/main.rs index 2650ec648..37e213570 100644 --- a/tools/minilints/src/main.rs +++ b/tools/minilints/src/main.rs @@ -108,7 +108,7 @@ impl LintContext { LazyCell::force(&self.unstaged_changes); fix_copyright(path)?; } else { - println!("missing standard copyright header: {:?}", path); + println!("missing standard copyright header: {path:?}"); self.found_problems = true; } } @@ -241,7 +241,7 @@ License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html .write(true) .open(path) .with_context(|| format!("opening {path}"))?; - write!(file, "{}{}", header, data).with_context(|| format!("writing {path}"))?; + write!(file, "{header}{data}").with_context(|| format!("writing {path}"))?; Ok(()) }