fix Clippy lints in Rust 1.57

This commit is contained in:
Damien Elmes 2021-12-03 19:53:37 +10:00
parent 763932cbed
commit 8de3eaea65
12 changed files with 12 additions and 49 deletions

View file

@ -192,7 +192,7 @@ fn normalized_deck_name_component(comp: &str) -> Cow<str> {
} }
pub(crate) fn immediate_parent_name(machine_name: &str) -> Option<&str> { pub(crate) fn immediate_parent_name(machine_name: &str) -> Option<&str> {
machine_name.rsplitn(2, '\x1f').nth(1) machine_name.rsplit_once('\x1f').map(|t| t.0)
} }
#[cfg(test)] #[cfg(test)]

View file

@ -377,7 +377,7 @@ impl Collection {
let mut missing = 0; let mut missing = 0;
for (_id, name) in names { for (_id, name) in names {
parents.insert(UniCase::new(name.as_str())); parents.insert(UniCase::new(name.as_str()));
if let Some(immediate_parent) = name.rsplitn(2, "::").nth(1) { if let Some((immediate_parent, _)) = name.rsplit_once("::") {
let immediate_parent_uni = UniCase::new(immediate_parent); let immediate_parent_uni = UniCase::new(immediate_parent);
if !parents.contains(&immediate_parent_uni) { if !parents.contains(&immediate_parent_uni) {
self.get_or_create_normal_deck(immediate_parent)?; self.get_or_create_normal_deck(immediate_parent)?;

View file

@ -57,15 +57,9 @@ pub struct NotetypeSchema11 {
pub(crate) other: HashMap<String, Value>, pub(crate) other: HashMap<String, Value>,
} }
#[derive(Serialize, Deserialize, Debug, Clone)] #[derive(Serialize, Deserialize, Debug, Default, Clone)]
pub(crate) struct CardRequirementsSchema11(pub(crate) Vec<CardRequirementSchema11>); pub(crate) struct CardRequirementsSchema11(pub(crate) Vec<CardRequirementSchema11>);
impl Default for CardRequirementsSchema11 {
fn default() -> Self {
CardRequirementsSchema11(vec![])
}
}
#[derive(Serialize_tuple, Deserialize, Debug, Clone)] #[derive(Serialize_tuple, Deserialize, Debug, Clone)]
pub(crate) struct CardRequirementSchema11 { pub(crate) struct CardRequirementSchema11 {
pub(crate) card_ord: u16, pub(crate) card_ord: u16,

View file

@ -25,8 +25,6 @@ pub(crate) struct DueCard {
pub note_id: NoteId, pub note_id: NoteId,
pub mtime: TimestampSecs, pub mtime: TimestampSecs,
pub due: i32, pub due: i32,
pub interval: u32,
pub hash: u64,
pub current_deck_id: DeckId, pub current_deck_id: DeckId,
pub original_deck_id: DeckId, pub original_deck_id: DeckId,
pub kind: DueCardKind, pub kind: DueCardKind,
@ -122,7 +120,6 @@ impl QueueBuilder {
mut self, mut self,
top_deck_limits: RemainingLimits, top_deck_limits: RemainingLimits,
learn_ahead_secs: i64, learn_ahead_secs: i64,
selected_deck: DeckId,
current_day: u32, current_day: u32,
) -> CardQueues { ) -> CardQueues {
self.sort_new(); self.sort_new();
@ -164,7 +161,6 @@ impl QueueBuilder {
main: main_iter.collect(), main: main_iter.collect(),
intraday_learning, intraday_learning,
learn_ahead_secs, learn_ahead_secs,
selected_deck,
current_day, current_day,
build_time: TimestampMillis::now(), build_time: TimestampMillis::now(),
current_learning_cutoff: now, current_learning_cutoff: now,
@ -333,7 +329,6 @@ impl Collection {
let queues = queues.build( let queues = queues.build(
final_limits, final_limits,
self.learn_ahead_secs() as i64, self.learn_ahead_secs() as i64,
deck_id,
timing.days_elapsed, timing.days_elapsed,
); );

View file

@ -1,8 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors // Copyright: Ankitects Pty Ltd and contributors
// License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html // License: GNU AGPL, version 3 or later; http://www.gnu.org/licenses/agpl.html
use std::{cmp::Ordering, collections::VecDeque};
use super::{undo::CutoffSnapshot, CardQueues}; use super::{undo::CutoffSnapshot, CardQueues};
use crate::{prelude::*, scheduler::timing::SchedTimingToday}; use crate::{prelude::*, scheduler::timing::SchedTimingToday};
@ -139,7 +137,9 @@ impl CardQueues {
self.counts.learning += 1; self.counts.learning += 1;
} }
let target_idx = binary_search_by(&self.intraday_learning, |e| e.due.cmp(&entry.due)) let target_idx = self
.intraday_learning
.binary_search_by(|e| e.due.cmp(&entry.due))
.unwrap_or_else(|e| e); .unwrap_or_else(|e| e);
self.intraday_learning.insert(target_idx, entry); self.intraday_learning.insert(target_idx, entry);
} }
@ -171,20 +171,3 @@ impl CardQueues {
.adding_secs(self.learn_ahead_secs) .adding_secs(self.learn_ahead_secs)
} }
} }
/// Adapted from the Rust stdlib VecDeque implementation; we can drop this after updating
/// to Rust 1.54.0
fn binary_search_by<'a, F, T>(deque: &'a VecDeque<T>, mut f: F) -> Result<usize, usize>
where
F: FnMut(&'a T) -> Ordering,
{
let (front, back) = deque.as_slices();
match back.first().map(|elem| f(elem)) {
Some(Ordering::Less) | Some(Ordering::Equal) => back
.binary_search_by(f)
.map(|idx| idx + front.len())
.map_err(|idx| idx + front.len()),
_ => front.binary_search_by(f),
}
}

View file

@ -23,7 +23,6 @@ pub(crate) struct CardQueues {
counts: Counts, counts: Counts,
main: VecDeque<MainQueueEntry>, main: VecDeque<MainQueueEntry>,
intraday_learning: VecDeque<LearningQueueEntry>, intraday_learning: VecDeque<LearningQueueEntry>,
selected_deck: DeckId,
current_day: u32, current_day: u32,
learn_ahead_secs: i64, learn_ahead_secs: i64,
build_time: TimestampMillis, build_time: TimestampMillis,

View file

@ -66,7 +66,7 @@ pub fn replace_search_node(mut existing: Vec<Node>, replacement: Node) -> String
} }
pub fn write_nodes(nodes: &[Node]) -> String { pub fn write_nodes(nodes: &[Node]) -> String {
nodes.iter().map(|node| write_node(node)).collect() nodes.iter().map(write_node).collect()
} }
fn write_node(node: &Node) -> String { fn write_node(node: &Node) -> String {

View file

@ -43,11 +43,7 @@ impl Collection {
total_secs, total_secs,
card_type: nt.get_template(card.template_idx)?.name.clone(), card_type: nt.get_template(card.template_idx)?.name.clone(),
notetype: nt.name.clone(), notetype: nt.name.clone(),
revlog: revlog revlog: revlog.iter().rev().map(stats_revlog_entry).collect(),
.iter()
.rev()
.map(|entry| stats_revlog_entry(entry))
.collect(),
}) })
} }

View file

@ -182,8 +182,6 @@ impl super::SqliteStorage {
mtime: row.get(3)?, mtime: row.get(3)?,
current_deck_id: row.get(4)?, current_deck_id: row.get(4)?,
original_deck_id: row.get(5)?, original_deck_id: row.get(5)?,
interval: 0,
hash: 0,
kind: DueCardKind::Learning, kind: DueCardKind::Learning,
}) })
} }
@ -219,11 +217,9 @@ impl super::SqliteStorage {
id: row.get(0)?, id: row.get(0)?,
note_id: row.get(1)?, note_id: row.get(1)?,
due: row.get(2).ok().unwrap_or_default(), due: row.get(2).ok().unwrap_or_default(),
interval: row.get(3)?,
mtime: row.get(4)?, mtime: row.get(4)?,
current_deck_id: row.get(5)?, current_deck_id: row.get(5)?,
original_deck_id: row.get(6)?, original_deck_id: row.get(6)?,
hash: 0,
kind, kind,
}) { }) {
break; break;

View file

@ -305,7 +305,7 @@ impl SqliteStorage {
self.db self.db
.prepare_cached(sql)? .prepare_cached(sql)?
.query_and_then(&*params, |row| row_to_due_counts(row))? .query_and_then(&*params, row_to_due_counts)?
.collect() .collect()
} }

View file

@ -54,9 +54,9 @@ fn is_tag_separator(c: char) -> bool {
} }
fn immediate_parent_name_unicase(tag_name: UniCase<&str>) -> Option<UniCase<&str>> { fn immediate_parent_name_unicase(tag_name: UniCase<&str>) -> Option<UniCase<&str>> {
tag_name.rsplitn(2, '\x1f').nth(1).map(UniCase::new) tag_name.rsplit_once('\x1f').map(|t| t.0).map(UniCase::new)
} }
fn immediate_parent_name_str(tag_name: &str) -> Option<&str> { fn immediate_parent_name_str(tag_name: &str) -> Option<&str> {
tag_name.rsplitn(2, "::").nth(1) tag_name.rsplit_once("::").map(|t| t.0)
} }

View file

@ -195,7 +195,7 @@ return false;">
} }
fn tts_filter(filter_name: &str, text: &str, tr: &I18n) -> Cow<'static, str> { fn tts_filter(filter_name: &str, text: &str, tr: &I18n) -> Cow<'static, str> {
let args = filter_name.splitn(2, ' ').nth(1).unwrap_or(""); let args = filter_name.split_once(' ').map_or("", |t| t.1);
let text = text.replace("[...]", &tr.card_templates_blank()); let text = text.replace("[...]", &tr.card_templates_blank());
format!("[anki:tts][{}]{}[/anki:tts]", args, text).into() format!("[anki:tts][{}]{}[/anki:tts]", args, text).into()