diff --git a/rslib/i18n/src/lib.rs b/rslib/i18n/src/lib.rs index 38a1fd49d..0000738cc 100644 --- a/rslib/i18n/src/lib.rs +++ b/rslib/i18n/src/lib.rs @@ -3,16 +3,18 @@ mod generated; +use std::{ + borrow::Cow, + sync::{Arc, Mutex}, +}; + use fluent::{types::FluentNumber, FluentArgs, FluentResource, FluentValue}; use fluent_bundle::bundle::FluentBundle as FluentBundleOrig; +use generated::{KEYS_BY_MODULE, STRINGS}; use num_format::Locale; use serde::Serialize; -use std::borrow::Cow; -use std::sync::{Arc, Mutex}; use unic_langid::LanguageIdentifier; -use generated::{KEYS_BY_MODULE, STRINGS}; - type FluentBundle = FluentBundleOrig; pub use fluent::fluent_args as tr_args; @@ -26,10 +28,7 @@ impl Number for u64 {} impl Number for usize {} fn remapped_lang_name(lang: &LanguageIdentifier) -> &str { - let region = match &lang.region { - Some(region) => Some(region.as_str()), - None => None, - }; + let region = lang.region.as_ref().map(|v| v.as_str()); match lang.language.as_str() { "en" => { match region { @@ -425,13 +424,14 @@ pub struct ResourcesForJavascript { #[cfg(test)] mod test { - use super::*; use unic_langid::langid; + use super::*; + #[test] fn numbers() { - assert_eq!(want_comma_as_decimal_separator(&[langid!("en-US")]), false); - assert_eq!(want_comma_as_decimal_separator(&[langid!("pl-PL")]), true); + assert!(!want_comma_as_decimal_separator(&[langid!("en-US")])); + assert!(want_comma_as_decimal_separator(&[langid!("pl-PL")])); } #[test] diff --git a/rslib/src/backend/cardrendering.rs b/rslib/src/backend/cardrendering.rs index ca37684fe..9528b7895 100644 --- a/rslib/src/backend/cardrendering.rs +++ b/rslib/src/backend/cardrendering.rs @@ -36,8 +36,8 @@ impl CardRenderingService for Backend { field_text, lang, voices, - other_args, speed, + other_args, })), }, }) diff --git a/rslib/src/backend/dbproxy.rs b/rslib/src/backend/dbproxy.rs index 125fb1585..3a798443b 100644 --- a/rslib/src/backend/dbproxy.rs +++ b/rslib/src/backend/dbproxy.rs @@ -50,7 +50,7 @@ impl ToSql for SqlValue { SqlValue::String(v) => ValueRef::Text(v.as_bytes()), SqlValue::Int(v) => ValueRef::Integer(*v), SqlValue::Double(v) => ValueRef::Real(*v), - SqlValue::Blob(v) => ValueRef::Blob(&v), + SqlValue::Blob(v) => ValueRef::Blob(v), }; Ok(ToSqlOutput::Borrowed(val)) } diff --git a/rslib/src/backend/progress.rs b/rslib/src/backend/progress.rs index b7ec45911..e4e334559 100644 --- a/rslib/src/backend/progress.rs +++ b/rslib/src/backend/progress.rs @@ -99,8 +99,8 @@ pub(super) fn progress_to_proto(progress: Option, tr: &I18n) -> pb::Pr .to_string(); pb::progress::Value::DatabaseCheck(pb::progress::DatabaseCheck { stage, - stage_current, stage_total, + stage_current, }) } } diff --git a/rslib/src/card/mod.rs b/rslib/src/card/mod.rs index 26486754b..27ad0253a 100644 --- a/rslib/src/card/mod.rs +++ b/rslib/src/card/mod.rs @@ -150,8 +150,8 @@ impl Card { pub fn new(note_id: NoteId, template_idx: u16, deck_id: DeckId, due: i32) -> Self { Card { note_id, - template_idx, deck_id, + template_idx, due, ..Default::default() } diff --git a/rslib/src/config/undo.rs b/rslib/src/config/undo.rs index 8da36e007..6efc00fc7 100644 --- a/rslib/src/config/undo.rs +++ b/rslib/src/config/undo.rs @@ -82,35 +82,35 @@ mod test { let key = BoolKey::NormalizeNoteText; // not set by default, but defaults to true - assert_eq!(col.get_config_bool(key), true); + assert!(col.get_config_bool(key)); // first set adds the key col.transact(op.clone(), |col| col.set_config_bool_inner(key, false))?; - assert_eq!(col.get_config_bool(key), false); + assert!(!col.get_config_bool(key)); // mutate it twice col.transact(op.clone(), |col| col.set_config_bool_inner(key, true))?; - assert_eq!(col.get_config_bool(key), true); + assert!(col.get_config_bool(key)); col.transact(op.clone(), |col| col.set_config_bool_inner(key, false))?; - assert_eq!(col.get_config_bool(key), false); + assert!(!col.get_config_bool(key)); // when we remove it, it goes back to its default col.transact(op, |col| col.remove_config_inner(key))?; - assert_eq!(col.get_config_bool(key), true); + assert!(col.get_config_bool(key)); // undo the removal col.undo()?; - assert_eq!(col.get_config_bool(key), false); + assert!(!col.get_config_bool(key)); // undo the mutations col.undo()?; - assert_eq!(col.get_config_bool(key), true); + assert!(col.get_config_bool(key)); col.undo()?; - assert_eq!(col.get_config_bool(key), false); + assert!(!col.get_config_bool(key)); // and undo the initial add col.undo()?; - assert_eq!(col.get_config_bool(key), true); + assert!(col.get_config_bool(key)); Ok(()) } diff --git a/rslib/src/dbcheck.rs b/rslib/src/dbcheck.rs index 08b547268..173c7473a 100644 --- a/rslib/src/dbcheck.rs +++ b/rslib/src/dbcheck.rs @@ -260,7 +260,7 @@ impl Collection { CardGenContext::new(&nt, self.get_last_deck_added_to_for_notetype(nt.id), usn) }); self.update_note_inner_generating_cards( - &ctx, &mut note, &original, false, norm, true, + ctx, &mut note, &original, false, norm, true, )?; } } @@ -480,11 +480,9 @@ mod test { ..Default::default() } ); - assert_eq!( - col.storage - .db_scalar::("select ivl = lastIvl = 1 from revlog")?, - true - ); + assert!(col + .storage + .db_scalar::("select ivl = lastIvl = 1 from revlog")?); Ok(()) } @@ -625,8 +623,8 @@ mod test { col.check_database(progress_fn)?; - assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true); - assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false); + assert!(col.storage.get_tag("one")?.unwrap().expanded); + assert!(!col.storage.get_tag("two")?.unwrap().expanded); Ok(()) } diff --git a/rslib/src/deckconfig/update.rs b/rslib/src/deckconfig/update.rs index 70d656881..66df07e72 100644 --- a/rslib/src/deckconfig/update.rs +++ b/rslib/src/deckconfig/update.rs @@ -229,17 +229,14 @@ mod test { removed_config_ids: vec![], apply_to_children: false, }; - assert_eq!( - col.update_deck_configs(input.clone())?.changes.had_change(), - false - ); + assert!(!col.update_deck_configs(input.clone())?.changes.had_change()); // modifying a value should update the config, but not the deck input.configs[0].inner.new_per_day += 1; let changes = col.update_deck_configs(input.clone())?.changes.changes; - assert_eq!(changes.deck, false); - assert_eq!(changes.deck_config, true); - assert_eq!(changes.card, false); + assert!(!changes.deck); + assert!(changes.deck_config); + assert!(!changes.card); // adding a new config will update the deck as well let new_config = DeckConfig { @@ -248,9 +245,9 @@ mod test { }; input.configs.push(new_config); let changes = col.update_deck_configs(input.clone())?.changes.changes; - assert_eq!(changes.deck, true); - assert_eq!(changes.deck_config, true); - assert_eq!(changes.card, false); + assert!(changes.deck); + assert!(changes.deck_config); + assert!(!changes.card); let allocated_id = col.get_deck(DeckId(1))?.unwrap().normal()?.config_id; assert_ne!(allocated_id, 0); assert_ne!(allocated_id, 1); @@ -260,10 +257,7 @@ mod test { reset_card1_pos(&mut col); assert_eq!(card1_pos(&mut col), 0); input.configs[1].inner.new_card_insert_order = NewCardInsertOrder::Random as i32; - assert_eq!( - col.update_deck_configs(input.clone())?.changes.changes.card, - true - ); + assert!(col.update_deck_configs(input.clone())?.changes.changes.card); assert_ne!(card1_pos(&mut col), 0); // removing the config will assign the selected config (default in this case), diff --git a/rslib/src/decks/tree.rs b/rslib/src/decks/tree.rs index 917ab47c0..8e1922cf6 100644 --- a/rslib/src/decks/tree.rs +++ b/rslib/src/decks/tree.rs @@ -271,13 +271,8 @@ impl Collection { } if let Some(now) = now { - let limit = top_deck_id.and_then(|did| { - if let Some(deck) = decks_map.get(&did) { - Some(deck.name.as_native_str()) - } else { - None - } - }); + let limit = top_deck_id + .and_then(|did| decks_map.get(&did).map(|deck| deck.name.as_native_str())); let days_elapsed = self.timing_for_timestamp(now)?.days_elapsed; let learn_cutoff = (now.0 as u32) + self.learn_ahead_secs(); let sched_ver = self.scheduler_version(); diff --git a/rslib/src/error/mod.rs b/rslib/src/error/mod.rs index b89619fc8..d0014e114 100644 --- a/rslib/src/error/mod.rs +++ b/rslib/src/error/mod.rs @@ -80,7 +80,7 @@ impl AnkiError { format!("{}
{}", header, details) } AnkiError::DbError(err) => err.localized_description(tr), - AnkiError::SearchError(kind) => kind.localized_description(&tr), + AnkiError::SearchError(kind) => kind.localized_description(tr), AnkiError::InvalidInput(info) => { if info.is_empty() { tr.errors_invalid_input_empty().into() diff --git a/rslib/src/media/changetracker.rs b/rslib/src/media/changetracker.rs index 0742be006..6db3e94f9 100644 --- a/rslib/src/media/changetracker.rs +++ b/rslib/src/media/changetracker.rs @@ -114,7 +114,7 @@ where }; // make sure the filename is normalized - let fname = match filename_if_normalized(&disk_fname) { + let fname = match filename_if_normalized(disk_fname) { Some(fname) => fname, None => { // not normalized; skip it diff --git a/rslib/src/media/check.rs b/rslib/src/media/check.rs index 534bc38f4..2d1f4492f 100644 --- a/rslib/src/media/check.rs +++ b/rslib/src/media/check.rs @@ -227,7 +227,7 @@ where } else { match data_for_file(&self.mgr.media_folder, disk_fname)? { Some(data) => { - let norm_name = self.normalize_file(ctx, &disk_fname, data)?; + let norm_name = self.normalize_file(ctx, disk_fname, data)?; out.renamed .insert(disk_fname.to_string(), norm_name.to_string()); out.files.push(norm_name.into_owned()); diff --git a/rslib/src/media/mod.rs b/rslib/src/media/mod.rs index dd493a256..351befa1f 100644 --- a/rslib/src/media/mod.rs +++ b/rslib/src/media/mod.rs @@ -106,7 +106,7 @@ impl MediaManager { { let pre_remove_folder_mtime = mtime_as_i64(&self.media_folder)?; - remove_files(&self.media_folder, &filenames)?; + remove_files(&self.media_folder, filenames)?; let post_remove_folder_mtime = mtime_as_i64(&self.media_folder)?; diff --git a/rslib/src/media/sync.rs b/rslib/src/media/sync.rs index 365d06e8b..da50eda88 100644 --- a/rslib/src/media/sync.rs +++ b/rslib/src/media/sync.rs @@ -260,7 +260,7 @@ where let resp = self .client .get(&url) - .query(&[("k", hkey), ("v", &sync_client_version())]) + .query(&[("k", hkey), ("v", sync_client_version())]) .send() .await? .error_for_status()?; diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index d00c3502d..9a9152e99 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -135,7 +135,7 @@ impl Note { } } - #[allow(clippy::clippy::too_many_arguments)] + #[allow(clippy::too_many_arguments)] pub(crate) fn new_from_storage( id: NoteId, guid: String, @@ -323,7 +323,7 @@ fn invalid_char_for_field(c: char) -> bool { impl Collection { fn canonify_note_tags(&mut self, note: &mut Note, usn: Usn) -> Result<()> { if !note.tags.is_empty() { - let tags = std::mem::replace(&mut note.tags, vec![]); + let tags = std::mem::take(&mut note.tags); note.tags = self.canonify_tags(tags, usn)?.0; } Ok(()) @@ -337,7 +337,7 @@ impl Collection { normalize_text: bool, ) -> Result<()> { self.canonify_note_tags(note, ctx.usn)?; - note.prepare_for_update(&ctx.notetype, normalize_text)?; + note.prepare_for_update(ctx.notetype, normalize_text)?; note.set_modified(ctx.usn); self.add_note_only_undoable(note)?; self.generate_cards_for_new_note(ctx, note, did)?; @@ -415,7 +415,7 @@ impl Collection { } // TODO: refactor into struct - #[allow(clippy::clippy::too_many_arguments)] + #[allow(clippy::too_many_arguments)] pub(crate) fn update_note_inner_without_cards( &mut self, note: &mut Note, @@ -504,7 +504,7 @@ impl Collection { ) }); self.update_note_inner_generating_cards( - &ctx, + ctx, &mut note, &original, out.mark_modified, @@ -559,7 +559,7 @@ impl Collection { } fn is_duplicate(&self, first_field: &str, note: &Note) -> Result { - let csum = field_checksum(&first_field); + let csum = field_checksum(first_field); Ok(self .storage .note_fields_by_checksum(note.notetype_id, csum)? @@ -735,7 +735,7 @@ mod test { col.storage.db_scalar::("select count() from graves")?, 0 ); - assert_eq!(col.get_next_card()?.is_some(), false); + assert!(!col.get_next_card()?.is_some()); Ok(()) }; @@ -746,7 +746,7 @@ mod test { col.storage.db_scalar::("select count() from graves")?, 0 ); - assert_eq!(col.get_next_card()?.is_some(), true); + assert!(col.get_next_card()?.is_some()); Ok(()) }; @@ -774,7 +774,7 @@ mod test { col.storage.db_scalar::("select count() from graves")?, 3 ); - assert_eq!(col.get_next_card()?.is_some(), false); + assert!(!col.get_next_card()?.is_some()); Ok(()) }; diff --git a/rslib/src/notetype/cardgen.rs b/rslib/src/notetype/cardgen.rs index 00a5e62a7..721e0728c 100644 --- a/rslib/src/notetype/cardgen.rs +++ b/rslib/src/notetype/cardgen.rs @@ -58,7 +58,7 @@ impl CardGenContext<'_> { CardGenContext { usn, last_deck, - notetype: &nt, + notetype: nt, cards: nt .templates .iter() @@ -82,7 +82,7 @@ impl CardGenContext<'_> { } }; - template.renders_with_fields(&nonempty_fields) + template.renders_with_fields(nonempty_fields) } /// Returns the cards that need to be generated for the provided note. @@ -239,7 +239,7 @@ impl Collection { target_deck_id: Option, cache: &mut CardGenCache, ) -> Result<()> { - let cards = ctx.new_cards_required(note, &existing, true); + let cards = ctx.new_cards_required(note, existing, true); if cards.is_empty() { return Ok(()); } @@ -337,13 +337,9 @@ impl Collection { /// If deck exists and and is a normal deck, return its ID and config fn deck_conf_if_normal(&mut self, did: DeckId) -> Result> { - Ok(self.get_deck(did)?.and_then(|d| { - if let Some(conf_id) = d.config_id() { - Some((did, conf_id)) - } else { - None - } - })) + Ok(self + .get_deck(did)? + .and_then(|d| d.config_id().map(|conf_id| (did, conf_id)))) } } diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index ab5590a12..178fb66cc 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -99,7 +99,7 @@ impl Default for Notetype { impl Notetype { pub fn new_note(&self) -> Note { - Note::new(&self) + Note::new(self) } /// Return the template for the given card ordinal. Cloze notetypes @@ -200,7 +200,7 @@ impl Collection { return Err(AnkiError::NotFound); } - let nids_node: Node = SearchNode::NoteIds(comma_separated_ids(¬e_ids)).into(); + let nids_node: Node = SearchNode::NoteIds(comma_separated_ids(note_ids)).into(); let note1 = self .storage .get_note(*note_ids.first().unwrap())? @@ -663,7 +663,7 @@ impl Collection { // adding with existing id for old undo code, bypass undo self.state.notetype_cache.remove(¬etype.id); self.storage - .add_or_update_notetype_with_existing_id(¬etype)?; + .add_or_update_notetype_with_existing_id(notetype)?; } Ok(()) diff --git a/rslib/src/notetype/notetypechange.rs b/rslib/src/notetype/notetypechange.rs index 802bf4e08..a0904dfb9 100644 --- a/rslib/src/notetype/notetypechange.rs +++ b/rslib/src/notetype/notetypechange.rs @@ -56,7 +56,7 @@ impl TemplateMap { .collect(); let removed: Vec<_> = (0..old_template_count) - .filter(|idx| !seen.contains(&idx)) + .filter(|idx| !seen.contains(idx)) .collect(); TemplateMap { removed, remapped } diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index b5538c16c..10edf844e 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -96,7 +96,7 @@ impl Collection { let mut field_map = note.fields_map(&nt.fields); let card_num; - self.add_special_fields(&mut field_map, note, card, &nt, template)?; + self.add_special_fields(&mut field_map, note, card, nt, template)?; // due to lifetime restrictions we need to add card number here card_num = format!("c{}", card.template_idx + 1); field_map.entry(&card_num).or_insert_with(|| "1".into()); diff --git a/rslib/src/notetype/schemachange.rs b/rslib/src/notetype/schemachange.rs index 0893e9607..b940f401f 100644 --- a/rslib/src/notetype/schemachange.rs +++ b/rslib/src/notetype/schemachange.rs @@ -48,7 +48,7 @@ impl TemplateOrdChanges { } } - changes.removed = removed.into_iter().filter_map(|v| v).collect(); + changes.removed = removed.into_iter().flatten().collect(); changes } @@ -83,11 +83,10 @@ impl Collection { false, )?; } - return Ok(()); } else { // nothing to do - return Ok(()); } + return Ok(()); } // fields have changed @@ -192,11 +191,11 @@ mod test { #[test] fn ord_changes() { - assert_eq!(ords_changed(&[Some(0), Some(1)], 2), false); - assert_eq!(ords_changed(&[Some(0), Some(1)], 1), true); - assert_eq!(ords_changed(&[Some(1), Some(0)], 2), true); - assert_eq!(ords_changed(&[None, Some(1)], 2), true); - assert_eq!(ords_changed(&[Some(0), Some(1), None], 2), true); + assert!(!ords_changed(&[Some(0), Some(1)], 2)); + assert!(ords_changed(&[Some(0), Some(1)], 1)); + assert!(ords_changed(&[Some(1), Some(0)], 2)); + assert!(ords_changed(&[None, Some(1)], 2)); + assert!(ords_changed(&[Some(0), Some(1), None], 2)); } #[test] diff --git a/rslib/src/scheduler/answering/mod.rs b/rslib/src/scheduler/answering/mod.rs index 5053530db..3fe117f3b 100644 --- a/rslib/src/scheduler/answering/mod.rs +++ b/rslib/src/scheduler/answering/mod.rs @@ -259,9 +259,9 @@ impl Collection { ))); } if let Some(revlog_partial) = updater.apply_study_state(current_state, answer.new_state)? { - self.add_partial_revlog(revlog_partial, usn, &answer)?; + self.add_partial_revlog(revlog_partial, usn, answer)?; } - self.update_deck_stats_from_answer(usn, &answer, &updater, original.queue)?; + self.update_deck_stats_from_answer(usn, answer, &updater, original.queue)?; self.maybe_bury_siblings(&original, &updater.config)?; let timing = updater.timing; let mut card = updater.into_card(); diff --git a/rslib/src/scheduler/queue/undo.rs b/rslib/src/scheduler/queue/undo.rs index ca1564d57..9d18a27c6 100644 --- a/rslib/src/scheduler/queue/undo.rs +++ b/rslib/src/scheduler/queue/undo.rs @@ -147,12 +147,12 @@ mod test { let note = col.storage.get_note(nid)?.unwrap(); assert_eq!(note.tags, vec!["leech".to_string()]); - assert_eq!(col.storage.all_tags()?.is_empty(), false); + assert!(!col.storage.all_tags()?.is_empty()); let deck = col.get_deck(DeckId(1))?.unwrap(); assert_eq!(deck.common.review_studied, 1); - assert_eq!(col.get_next_card()?.is_some(), false); + assert!(!col.get_next_card()?.is_some()); Ok(()) }; @@ -172,12 +172,12 @@ mod test { // the note should no longer be tagged as a leech let note = col.storage.get_note(nid)?.unwrap(); - assert_eq!(note.tags.is_empty(), true); - assert_eq!(col.storage.all_tags()?.is_empty(), true); + assert!(note.tags.is_empty()); + assert!(col.storage.all_tags()?.is_empty()); let deck = col.get_deck(DeckId(1))?.unwrap(); assert_eq!(deck.common.review_studied, 0); - assert_eq!(col.get_next_card()?.is_some(), true); + assert!(col.get_next_card()?.is_some()); assert_eq!(col.counts(), [0, 0, 1]); Ok(()) diff --git a/rslib/src/scheduler/states/mod.rs b/rslib/src/scheduler/states/mod.rs index d9ffde031..74450c4b7 100644 --- a/rslib/src/scheduler/states/mod.rs +++ b/rslib/src/scheduler/states/mod.rs @@ -49,8 +49,8 @@ impl CardState { pub(crate) fn next_states(self, ctx: &StateContext) -> NextCardStates { match self { - CardState::Normal(state) => state.next_states(&ctx), - CardState::Filtered(state) => state.next_states(&ctx), + CardState::Normal(state) => state.next_states(ctx), + CardState::Filtered(state) => state.next_states(ctx), } } diff --git a/rslib/src/scheduler/states/rescheduling_filter.rs b/rslib/src/scheduler/states/rescheduling_filter.rs index 1993031c4..8a2216eea 100644 --- a/rslib/src/scheduler/states/rescheduling_filter.rs +++ b/rslib/src/scheduler/states/rescheduling_filter.rs @@ -21,7 +21,7 @@ impl ReschedulingFilterState { } pub(crate) fn next_states(self, ctx: &StateContext) -> NextCardStates { - let normal = self.original_state.next_states(&ctx); + let normal = self.original_state.next_states(ctx); if ctx.in_filtered_deck { NextCardStates { current: self.into(), diff --git a/rslib/src/scheduler/states/review.rs b/rslib/src/scheduler/states/review.rs index ebc7f7c4c..76806b8ce 100644 --- a/rslib/src/scheduler/states/review.rs +++ b/rslib/src/scheduler/states/review.rs @@ -237,30 +237,30 @@ mod test { #[test] fn leech_threshold() { - assert_eq!(leech_threshold_met(0, 3), false); - assert_eq!(leech_threshold_met(1, 3), false); - assert_eq!(leech_threshold_met(2, 3), false); - assert_eq!(leech_threshold_met(3, 3), true); - assert_eq!(leech_threshold_met(4, 3), false); - assert_eq!(leech_threshold_met(5, 3), true); - assert_eq!(leech_threshold_met(6, 3), false); - assert_eq!(leech_threshold_met(7, 3), true); + assert!(!leech_threshold_met(0, 3)); + assert!(!leech_threshold_met(1, 3)); + assert!(!leech_threshold_met(2, 3)); + assert!(leech_threshold_met(3, 3)); + assert!(!leech_threshold_met(4, 3)); + assert!(leech_threshold_met(5, 3)); + assert!(!leech_threshold_met(6, 3)); + assert!(leech_threshold_met(7, 3)); - assert_eq!(leech_threshold_met(7, 8), false); - assert_eq!(leech_threshold_met(8, 8), true); - assert_eq!(leech_threshold_met(9, 8), false); - assert_eq!(leech_threshold_met(10, 8), false); - assert_eq!(leech_threshold_met(11, 8), false); - assert_eq!(leech_threshold_met(12, 8), true); - assert_eq!(leech_threshold_met(13, 8), false); + assert!(!leech_threshold_met(7, 8)); + assert!(leech_threshold_met(8, 8)); + assert!(!leech_threshold_met(9, 8)); + assert!(!leech_threshold_met(10, 8)); + assert!(!leech_threshold_met(11, 8)); + assert!(leech_threshold_met(12, 8)); + assert!(!leech_threshold_met(13, 8)); // 0 means off - assert_eq!(leech_threshold_met(0, 0), false); + assert!(!leech_threshold_met(0, 0)); // no div by zero; half of 1 is 1 - assert_eq!(leech_threshold_met(0, 1), false); - assert_eq!(leech_threshold_met(1, 1), true); - assert_eq!(leech_threshold_met(2, 1), true); - assert_eq!(leech_threshold_met(3, 1), true); + assert!(!leech_threshold_met(0, 1)); + assert!(leech_threshold_met(1, 1)); + assert!(leech_threshold_met(2, 1)); + assert!(leech_threshold_met(3, 1)); } } diff --git a/rslib/src/search/parser.rs b/rslib/src/search/parser.rs index 22ca55db9..c36e8fa14 100644 --- a/rslib/src/search/parser.rs +++ b/rslib/src/search/parser.rs @@ -705,7 +705,7 @@ fn unescape(txt: &str) -> ParseResult { lazy_static! { static ref RE: Regex = Regex::new(r#"\\[\\":()-]"#).unwrap(); } - RE.replace_all(&txt, |caps: &Captures| match &caps[0] { + RE.replace_all(txt, |caps: &Captures| match &caps[0] { r"\\" => r"\\", "\\\"" => "\"", r"\:" => ":", diff --git a/rslib/src/search/sqlwriter.rs b/rslib/src/search/sqlwriter.rs index 8c392cf3e..50c0d4827 100644 --- a/rslib/src/search/sqlwriter.rs +++ b/rslib/src/search/sqlwriter.rs @@ -53,7 +53,7 @@ impl SqlWriter<'_> { ) -> Result<(String, Vec)> { self.table = self.table.combine(table.combine(node.required_table())); self.write_table_sql(); - self.write_node_to_sql(&node)?; + self.write_node_to_sql(node)?; Ok((self.sql, self.args)) } diff --git a/rslib/src/storage/note/mod.rs b/rslib/src/storage/note/mod.rs index 69b99102e..88bf735d4 100644 --- a/rslib/src/storage/note/mod.rs +++ b/rslib/src/storage/note/mod.rs @@ -51,7 +51,7 @@ impl super::SqliteStorage { note.mtime, note.usn, join_tags(¬e.tags), - join_fields(¬e.fields()), + join_fields(note.fields()), note.sort_field.as_ref().unwrap(), note.checksum.unwrap(), note.id @@ -69,7 +69,7 @@ impl super::SqliteStorage { note.mtime, note.usn, join_tags(¬e.tags), - join_fields(¬e.fields()), + join_fields(note.fields()), note.sort_field.as_ref().unwrap(), note.checksum.unwrap(), ])?; @@ -87,7 +87,7 @@ impl super::SqliteStorage { note.mtime, note.usn, join_tags(¬e.tags), - join_fields(¬e.fields()), + join_fields(note.fields()), note.sort_field.as_ref().unwrap(), note.checksum.unwrap(), ])?; diff --git a/rslib/src/sync/http_client.rs b/rslib/src/sync/http_client.rs index 2dc88b03f..7d340f39f 100644 --- a/rslib/src/sync/http_client.rs +++ b/rslib/src/sync/http_client.rs @@ -428,7 +428,7 @@ mod test { syncer.set_full_sync_progress_fn(Some(Box::new(|progress, _throttle| { println!("progress {:?}", progress); }))); - syncer.full_upload(&out_path.path(), false).await?; + syncer.full_upload(out_path.path(), false).await?; Ok(()) } diff --git a/rslib/src/tags/bulkadd.rs b/rslib/src/tags/bulkadd.rs index 33dabf126..acc7b0ea6 100644 --- a/rslib/src/tags/bulkadd.rs +++ b/rslib/src/tags/bulkadd.rs @@ -84,6 +84,6 @@ mod test { assert_eq!(&add_to(""), " abc DEF xyz "); assert_eq!(&add_to("XYZ deF aaa"), " aaa abc deF XYZ "); - assert_eq!(add_missing_tags("def xyz abc", &desired).is_none(), true); + assert!(add_missing_tags("def xyz abc", &desired).is_none()); } } diff --git a/rslib/src/tags/matcher.rs b/rslib/src/tags/matcher.rs index e74a49f37..3f7ded47e 100644 --- a/rslib/src/tags/matcher.rs +++ b/rslib/src/tags/matcher.rs @@ -131,17 +131,17 @@ mod test { #[test] fn regex() -> Result<()> { let re = TagMatcher::new("one two")?; - assert_eq!(re.is_match(" foo "), false); - assert_eq!(re.is_match(" foo one "), true); - assert_eq!(re.is_match(" two foo "), true); + assert!(!re.is_match(" foo ")); + assert!(re.is_match(" foo one ")); + assert!(re.is_match(" two foo ")); let mut re = TagMatcher::new("foo")?; - assert_eq!(re.is_match("foo"), true); - assert_eq!(re.is_match(" foo "), true); - assert_eq!(re.is_match(" bar foo baz "), true); - assert_eq!(re.is_match(" bar FOO baz "), true); - assert_eq!(re.is_match(" bar foof baz "), false); - assert_eq!(re.is_match(" barfoo "), false); + assert!(re.is_match("foo")); + assert!(re.is_match(" foo ")); + assert!(re.is_match(" bar foo baz ")); + assert!(re.is_match(" bar FOO baz ")); + assert!(!re.is_match(" bar foof baz ")); + assert!(!re.is_match(" barfoo ")); let mut as_xxx = |text| re.replace(text, "xxx"); diff --git a/rslib/src/tags/register.rs b/rslib/src/tags/register.rs index 829bf718b..608a9622e 100644 --- a/rslib/src/tags/register.rs +++ b/rslib/src/tags/register.rs @@ -65,7 +65,7 @@ impl Collection { pub(crate) fn register_tag(&mut self, tag: &mut Tag) -> Result { let is_new = self.prepare_tag_for_registering(tag)?; if is_new { - self.register_tag_undoable(&tag)?; + self.register_tag_undoable(tag)?; } Ok(is_new) } @@ -100,7 +100,7 @@ impl Collection { impl Collection { /// If parent tag(s) exist and differ in case, return a rewritten tag. fn adjusted_case_for_parents(&self, tag: &str) -> Result> { - if let Some(parent_tag) = self.first_existing_parent_tag(&tag)? { + if let Some(parent_tag) = self.first_existing_parent_tag(tag)? { let child_split: Vec<_> = tag.split("::").collect(); let parent_count = parent_tag.matches("::").count() + 1; Ok(Some(format!( diff --git a/rslib/src/tags/remove.rs b/rslib/src/tags/remove.rs index 227533e58..d43b401d7 100644 --- a/rslib/src/tags/remove.rs +++ b/rslib/src/tags/remove.rs @@ -109,8 +109,8 @@ mod test { col.set_tag_collapsed("one", false)?; col.clear_unused_tags()?; - assert_eq!(col.storage.get_tag("one")?.unwrap().expanded, true); - assert_eq!(col.storage.get_tag("two")?.unwrap().expanded, false); + assert!(col.storage.get_tag("one")?.unwrap().expanded); + assert!(!col.storage.get_tag("two")?.unwrap().expanded); // tag children are also cleared when clearing their parent col.storage.clear_all_tags()?; diff --git a/rslib/src/tags/reparent.rs b/rslib/src/tags/reparent.rs index ffc758791..bdedd38b0 100644 --- a/rslib/src/tags/reparent.rs +++ b/rslib/src/tags/reparent.rs @@ -82,12 +82,8 @@ fn old_to_new_names( .iter() // generate resulting names and filter out invalid ones .flat_map(|source_tag| { - if let Some(output_name) = reparented_name(source_tag, new_parent.as_deref()) { - Some((source_tag.as_str(), output_name)) - } else { - // invalid rename, ignore this tag - None - } + reparented_name(source_tag, new_parent.as_deref()) + .map(|output_name| (source_tag.as_str(), output_name)) }) .collect() } diff --git a/rslib/src/tags/tree.rs b/rslib/src/tags/tree.rs index 3c2e0b63b..20ed15524 100644 --- a/rslib/src/tags/tree.rs +++ b/rslib/src/tags/tree.rs @@ -36,7 +36,7 @@ impl Collection { fn update_tag_inner(&mut self, tag: &mut Tag, original: Tag, usn: Usn) -> Result<()> { tag.set_modified(usn); - self.update_tag_undoable(&tag, original) + self.update_tag_undoable(tag, original) } } diff --git a/rslib/src/tags/undo.rs b/rslib/src/tags/undo.rs index ac97a48ac..554b42878 100644 --- a/rslib/src/tags/undo.rs +++ b/rslib/src/tags/undo.rs @@ -36,7 +36,7 @@ impl Collection { /// Caller is responsible for setting usn. pub(super) fn register_tag_undoable(&mut self, tag: &Tag) -> Result<()> { self.save_undo(UndoableTagChange::Added(Box::new(tag.clone()))); - self.storage.register_tag(&tag) + self.storage.register_tag(tag) } /// Remove a single tag from the tag list, saving an undo entry. Does not alter notes. diff --git a/rslib/src/template.rs b/rslib/src/template.rs index e6994f4fd..1bde79f3d 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -656,7 +656,7 @@ impl ParsedTemplate { /// Given a map of old to new field names, update references to the new names. /// Returns true if any changes made. pub(crate) fn rename_and_remove_fields(&mut self, fields: &HashMap>) { - let old_nodes = std::mem::replace(&mut self.0, vec![]); + let old_nodes = std::mem::take(&mut self.0); self.0 = rename_and_remove_fields(old_nodes, fields); } } @@ -746,12 +746,12 @@ fn nodes_to_string(buf: &mut String, nodes: &[ParsedNode]) { } ParsedNode::Conditional { key, children } => { write!(buf, "{{{{#{}}}}}", key).unwrap(); - nodes_to_string(buf, &children); + nodes_to_string(buf, children); write!(buf, "{{{{/{}}}}}", key).unwrap(); } ParsedNode::NegatedConditional { key, children } => { write!(buf, "{{{{^{}}}}}", key).unwrap(); - nodes_to_string(buf, &children); + nodes_to_string(buf, children); write!(buf, "{{{{/{}}}}}", key).unwrap(); } } @@ -794,10 +794,10 @@ fn find_fields_with_filter<'a>( } } ParsedNode::Conditional { children, .. } => { - find_fields_with_filter(&children, fields, filter); + find_fields_with_filter(children, fields, filter); } ParsedNode::NegatedConditional { children, .. } => { - find_fields_with_filter(&children, fields, filter); + find_fields_with_filter(children, fields, filter); } } } @@ -819,13 +819,13 @@ mod test { #[test] fn field_empty() { - assert_eq!(field_is_empty(""), true); - assert_eq!(field_is_empty(" "), true); - assert_eq!(field_is_empty("x"), false); - assert_eq!(field_is_empty("
"), true); - assert_eq!(field_is_empty("
"), true); - assert_eq!(field_is_empty("

\n"), true); - assert_eq!(field_is_empty("
x
\n"), false); + assert!(field_is_empty("")); + assert!(field_is_empty(" ")); + assert!(!field_is_empty("x")); + assert!(field_is_empty("
")); + assert!(field_is_empty("
")); + assert!(field_is_empty("

\n")); + assert!(!field_is_empty("
x
\n")); } #[test] @@ -891,17 +891,17 @@ mod test { fn nonempty() { let fields = vec!["1", "3"].into_iter().collect(); let mut tmpl = PT::from_text("{{2}}{{1}}").unwrap(); - assert_eq!(tmpl.renders_with_fields(&fields), true); + assert!(tmpl.renders_with_fields(&fields)); tmpl = PT::from_text("{{2}}").unwrap(); - assert_eq!(tmpl.renders_with_fields(&fields), false); + assert!(!tmpl.renders_with_fields(&fields)); tmpl = PT::from_text("{{2}}{{4}}").unwrap(); - assert_eq!(tmpl.renders_with_fields(&fields), false); + assert!(!tmpl.renders_with_fields(&fields)); tmpl = PT::from_text("{{#3}}{{^2}}{{1}}{{/2}}{{/3}}").unwrap(); - assert_eq!(tmpl.renders_with_fields(&fields), true); + assert!(tmpl.renders_with_fields(&fields)); tmpl = PT::from_text("{{^1}}{{3}}{{/1}}").unwrap(); - assert_eq!(tmpl.renders_with_fields(&fields), false); - assert_eq!(tmpl.renders_with_fields_for_reqs(&fields), true); + assert!(!tmpl.renders_with_fields(&fields)); + assert!(tmpl.renders_with_fields_for_reqs(&fields)); } #[test] diff --git a/rslib/src/text.rs b/rslib/src/text.rs index 96ecdbdab..04f5c65b9 100644 --- a/rslib/src/text.rs +++ b/rslib/src/text.rs @@ -359,7 +359,7 @@ pub(crate) fn to_custom_re<'a>(txt: &'a str, wildcard: &str) -> Cow<'a, str> { lazy_static! { static ref RE: Regex = Regex::new(r"\\?.").unwrap(); } - RE.replace_all(&txt, |caps: &Captures| { + RE.replace_all(txt, |caps: &Captures| { let s = &caps[0]; match s { r"\\" | r"\*" => s.to_string(), @@ -377,7 +377,7 @@ pub(crate) fn to_sql(txt: &str) -> Cow { lazy_static! { static ref RE: Regex = Regex::new(r"\\[\\*]|[*%]").unwrap(); } - RE.replace_all(&txt, |caps: &Captures| { + RE.replace_all(txt, |caps: &Captures| { let s = &caps[0]; match s { r"\\" => r"\\", @@ -394,7 +394,7 @@ pub(crate) fn to_text(txt: &str) -> Cow { lazy_static! { static ref RE: Regex = Regex::new(r"\\(.)").unwrap(); } - RE.replace_all(&txt, "$1") + RE.replace_all(txt, "$1") } /// Escape Anki wildcards and the backslash for escaping them: \*_ @@ -402,7 +402,7 @@ pub(crate) fn escape_anki_wildcards(txt: &str) -> String { lazy_static! { static ref RE: Regex = Regex::new(r"[\\*_]").unwrap(); } - RE.replace_all(&txt, r"\$0").into() + RE.replace_all(txt, r"\$0").into() } /// Escape Anki wildcards unless it's _* diff --git a/rslib/src/undo/mod.rs b/rslib/src/undo/mod.rs index 3d4cc97bf..ed16cd5cf 100644 --- a/rslib/src/undo/mod.rs +++ b/rslib/src/undo/mod.rs @@ -498,8 +498,8 @@ mod test { // merge subsequent changes into our restore point let op = col.merge_undoable_ops(restore_point)?; - assert_eq!(op.changes.card, true); - assert_eq!(op.changes.config, true); + assert!(op.changes.card); + assert!(op.changes.config); // the last undo action should be at the end of the step list, // before the modtime bump @@ -535,7 +535,7 @@ mod test { col.storage.get_collection_timestamps()?.collection_change.0, 0 ); - assert_eq!(out.changes.had_change(), false); + assert!(!out.changes.had_change()); // if there is an undoable step, mtime should change let out = col.set_config_bool(BoolKey::AddingDefaultsToCurrentDeck, false, true)?; @@ -543,7 +543,7 @@ mod test { col.storage.get_collection_timestamps()?.collection_change.0, 0 ); - assert_eq!(out.changes.had_change(), true); + assert!(out.changes.had_change()); // when skipping undo, mtime should still only be bumped on a change col.storage.db.execute_batch("update col set mod = 0")?; @@ -552,7 +552,7 @@ mod test { col.storage.get_collection_timestamps()?.collection_change.0, 0 ); - assert_eq!(out.changes.had_change(), false); + assert!(!out.changes.had_change()); // op output won't reflect changes were made let out = col.set_config_bool(BoolKey::AddingDefaultsToCurrentDeck, true, false)?; @@ -560,7 +560,7 @@ mod test { col.storage.get_collection_timestamps()?.collection_change.0, 0 ); - assert_eq!(out.changes.had_change(), false); + assert!(!out.changes.had_change()); Ok(()) }