From 3982e0c8fe691d3e84deceb7555f2d2fd0a8fbe6 Mon Sep 17 00:00:00 2001 From: Damien Elmes Date: Fri, 5 Jan 2024 14:28:23 +1000 Subject: [PATCH] Update to Rust 1.75 --- rslib/src/cloze.rs | 2 +- rslib/src/import_export/text/csv/metadata.rs | 2 +- rslib/src/import_export/text/import.rs | 8 ++++---- rslib/src/notes/mod.rs | 2 +- rslib/src/notetype/mod.rs | 8 ++++---- rslib/src/notetype/render.rs | 2 +- rslib/src/revlog/mod.rs | 5 ++--- rslib/src/scheduler/new.rs | 18 +++++++++--------- rslib/src/scheduler/queue/mod.rs | 2 +- rslib/src/template.rs | 2 +- rust-toolchain.toml | 2 +- 11 files changed, 26 insertions(+), 27 deletions(-) diff --git a/rslib/src/cloze.rs b/rslib/src/cloze.rs index cc6111ba9..c1f73b15f 100644 --- a/rslib/src/cloze.rs +++ b/rslib/src/cloze.rs @@ -146,7 +146,7 @@ impl ExtractedCloze<'_> { /// If cloze starts with image-occlusion:, return the text following that. fn image_occlusion(&self) -> Option<&str> { - let Some(first_node) = self.nodes.get(0) else { + let Some(first_node) = self.nodes.first() else { return None; }; let TextOrCloze::Text(text) = first_node else { diff --git a/rslib/src/import_export/text/csv/metadata.rs b/rslib/src/import_export/text/csv/metadata.rs index f39fce71d..17db20eae 100644 --- a/rslib/src/import_export/text/csv/metadata.rs +++ b/rslib/src/import_export/text/csv/metadata.rs @@ -460,7 +460,7 @@ fn ensure_first_field_is_mapped( fn maybe_set_fallback_columns(metadata: &mut CsvMetadata) -> Result<()> { if metadata.column_labels.is_empty() { metadata.column_labels = - vec![String::new(); metadata.preview.get(0).map_or(0, |row| row.vals.len())]; + vec![String::new(); metadata.preview.first().map_or(0, |row| row.vals.len())]; } Ok(()) } diff --git a/rslib/src/import_export/text/import.rs b/rslib/src/import_export/text/import.rs index b194b27d3..b9105ec24 100644 --- a/rslib/src/import_export/text/import.rs +++ b/rslib/src/import_export/text/import.rs @@ -483,7 +483,7 @@ impl DuplicateUpdateResult { impl NoteContext<'_> { fn is_guid_dupe(&self) -> bool { self.dupes - .get(0) + .first() .map_or(false, |d| d.note.guid == self.note.guid) } @@ -570,11 +570,11 @@ impl ForeignNote { } fn first_field_is_the_empty_string(&self) -> bool { - matches!(self.fields.get(0), Some(Some(s)) if s.is_empty()) + matches!(self.fields.first(), Some(Some(s)) if s.is_empty()) } fn first_field_is_unempty(&self) -> bool { - matches!(self.fields.get(0), Some(Some(s)) if !s.is_empty()) + matches!(self.fields.first(), Some(Some(s)) if !s.is_empty()) } fn normalize_fields(&mut self, normalize_text: bool) { @@ -595,7 +595,7 @@ impl ForeignNote { fn first_field_stripped(&self) -> Option> { self.fields - .get(0) + .first() .and_then(|s| s.as_ref()) .map(|field| strip_html_preserving_media_filenames(field.as_str())) } diff --git a/rslib/src/notes/mod.rs b/rslib/src/notes/mod.rs index 1efd1c2ba..81ef08948 100644 --- a/rslib/src/notes/mod.rs +++ b/rslib/src/notes/mod.rs @@ -564,7 +564,7 @@ impl Collection { /// notetypes, check if there is a cloze in a non-cloze field or if there's /// no cloze at all. For other notetypes, just check if there's a cloze. pub fn note_fields_check(&mut self, note: &Note) -> Result { - Ok(if let Some(text) = note.fields.get(0) { + Ok(if let Some(text) = note.fields.first() { let field1 = if self.get_config_bool(BoolKey::NormalizeNoteText) { normalize_to_nfc(text) } else { diff --git a/rslib/src/notetype/mod.rs b/rslib/src/notetype/mod.rs index c62a58e2e..da85d89ac 100644 --- a/rslib/src/notetype/mod.rs +++ b/rslib/src/notetype/mod.rs @@ -132,7 +132,7 @@ impl Notetype { /// always return the first and only template. pub fn get_template(&self, card_ord: u16) -> Result<&CardTemplate> { let template = if self.config.kind() == NotetypeKind::Cloze { - self.templates.get(0) + self.templates.first() } else { self.templates.get(card_ord as usize) }; @@ -553,7 +553,7 @@ impl Notetype { fields: HashMap>, parsed: &mut [(Option, Option)], ) { - let first_remaining_field_name = &self.fields.get(0).unwrap().name; + let first_remaining_field_name = &self.fields.first().unwrap().name; let is_cloze = self.is_cloze(); for (idx, (q_opt, a_opt)) in parsed.iter_mut().enumerate() { if let Some(q) = q_opt { @@ -616,7 +616,7 @@ impl Notetype { pub(crate) fn cloze_fields(&self) -> HashSet { if !self.is_cloze() { HashSet::new() - } else if let Some((Some(front), _)) = self.parsed_templates().get(0) { + } else if let Some((Some(front), _)) = self.parsed_templates().first() { front .all_referenced_cloze_field_names() .iter() @@ -647,7 +647,7 @@ fn missing_cloze_filter( parsed_templates: &[(Option, Option)], ) -> bool { parsed_templates - .get(0) + .first() .map_or(true, |t| !has_cloze(&t.0) || !has_cloze(&t.1)) } diff --git a/rslib/src/notetype/render.rs b/rslib/src/notetype/render.rs index 9c80c7fbf..ffbd5eb5c 100644 --- a/rslib/src/notetype/render.rs +++ b/rslib/src/notetype/render.rs @@ -58,7 +58,7 @@ impl Collection { .or_invalid("no such notetype")?; let template = match nt.config.kind() { NotetypeKind::Normal => nt.templates.get(card.template_idx as usize), - NotetypeKind::Cloze => nt.templates.get(0), + NotetypeKind::Cloze => nt.templates.first(), } .or_invalid("missing template")?; diff --git a/rslib/src/revlog/mod.rs b/rslib/src/revlog/mod.rs index f1ca93d12..128beab64 100644 --- a/rslib/src/revlog/mod.rs +++ b/rslib/src/revlog/mod.rs @@ -92,12 +92,11 @@ impl Collection { original_interval: u32, usn: Usn, ) -> Result<()> { - let ease_factor = u32::try_from( + let ease_factor = u32::from( card.memory_state .map(|s| ((s.difficulty_shifted() * 1000.) as u16)) .unwrap_or(card.ease_factor), - ) - .unwrap_or_default(); + ); let entry = RevlogEntry { id: RevlogId::new(), cid: card.id, diff --git a/rslib/src/scheduler/new.rs b/rslib/src/scheduler/new.rs index 7b6f7e9a0..73b7abf5f 100644 --- a/rslib/src/scheduler/new.rs +++ b/rslib/src/scheduler/new.rs @@ -299,6 +299,15 @@ impl Collection { } } +impl From for NewCardDueOrder { + fn from(o: NewCardInsertOrder) -> Self { + match o { + NewCardInsertOrder::Due => NewCardDueOrder::NoteId, + NewCardInsertOrder::Random => NewCardDueOrder::Random, + } + } +} + #[cfg(test)] mod test { use super::*; @@ -374,12 +383,3 @@ mod test { assert_eq!((card.due, card.reps, card.lapses), (1, 0, 0)); } } - -impl From for NewCardDueOrder { - fn from(o: NewCardInsertOrder) -> Self { - match o { - NewCardInsertOrder::Due => NewCardDueOrder::NoteId, - NewCardInsertOrder::Random => NewCardDueOrder::Random, - } - } -} diff --git a/rslib/src/scheduler/queue/mod.rs b/rslib/src/scheduler/queue/mod.rs index ff19aac72..bef612814 100644 --- a/rslib/src/scheduler/queue/mod.rs +++ b/rslib/src/scheduler/queue/mod.rs @@ -80,7 +80,7 @@ pub(crate) struct BuryMode { impl Collection { pub fn get_next_card(&mut self) -> Result> { self.get_queued_cards(1, false) - .map(|queued| queued.cards.get(0).cloned()) + .map(|queued| queued.cards.first().cloned()) } pub fn get_queued_cards( diff --git a/rslib/src/template.rs b/rslib/src/template.rs index 39a59d9fc..9304250fb 100644 --- a/rslib/src/template.rs +++ b/rslib/src/template.rs @@ -647,7 +647,7 @@ pub fn render_card( context.frontside = if context.partial_for_python { Some("") } else { - let Some(RenderedNode::Text { text }) = &qnodes.get(0) else { + let Some(RenderedNode::Text { text }) = &qnodes.first() else { invalid_input!("should not happen: first node not text"); }; Some(text) diff --git a/rust-toolchain.toml b/rust-toolchain.toml index f826eaea0..72c4f87ee 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.74" +channel = "1.75"