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> {
machine_name.rsplitn(2, '\x1f').nth(1)
machine_name.rsplit_once('\x1f').map(|t| t.0)
}
#[cfg(test)]

View File

@ -377,7 +377,7 @@ impl Collection {
let mut missing = 0;
for (_id, name) in names {
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);
if !parents.contains(&immediate_parent_uni) {
self.get_or_create_normal_deck(immediate_parent)?;

View File

@ -57,15 +57,9 @@ pub struct NotetypeSchema11 {
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>);
impl Default for CardRequirementsSchema11 {
fn default() -> Self {
CardRequirementsSchema11(vec![])
}
}
#[derive(Serialize_tuple, Deserialize, Debug, Clone)]
pub(crate) struct CardRequirementSchema11 {
pub(crate) card_ord: u16,

View File

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

View File

@ -1,8 +1,6 @@
// Copyright: Ankitects Pty Ltd and contributors
// 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 crate::{prelude::*, scheduler::timing::SchedTimingToday};
@ -139,7 +137,9 @@ impl CardQueues {
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);
self.intraday_learning.insert(target_idx, entry);
}
@ -171,20 +171,3 @@ impl CardQueues {
.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,
main: VecDeque<MainQueueEntry>,
intraday_learning: VecDeque<LearningQueueEntry>,
selected_deck: DeckId,
current_day: u32,
learn_ahead_secs: i64,
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 {
nodes.iter().map(|node| write_node(node)).collect()
nodes.iter().map(write_node).collect()
}
fn write_node(node: &Node) -> String {

View File

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

View File

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

View File

@ -305,7 +305,7 @@ impl SqliteStorage {
self.db
.prepare_cached(sql)?
.query_and_then(&*params, |row| row_to_due_counts(row))?
.query_and_then(&*params, row_to_due_counts)?
.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>> {
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> {
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> {
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());
format!("[anki:tts][{}]{}[/anki:tts]", args, text).into()