From b46fae331bea5fc6dd047a996bd81476009f292f Mon Sep 17 00:00:00 2001 From: Tom Alexander Date: Thu, 11 Apr 2024 20:57:11 -0400 Subject: [PATCH] Fix clippy errors. --- src/error/error.rs | 6 ++-- src/parser/comment.rs | 1 - src/parser/headline.rs | 6 ++-- src/parser/keyword.rs | 1 - src/parser/radio_link.rs | 2 -- src/types/mod.rs | 1 - src/types/remove_trailing.rs | 56 ------------------------------------ 7 files changed, 6 insertions(+), 67 deletions(-) delete mode 100644 src/types/remove_trailing.rs diff --git a/src/error/error.rs b/src/error/error.rs index a6714a6f..9f44796e 100644 --- a/src/error/error.rs +++ b/src/error/error.rs @@ -6,9 +6,9 @@ pub(crate) type Res = IResult; #[derive(Debug)] pub enum CustomError { - Static(&'static str), - IO(std::io::Error), - Parser(ErrorKind), + Static(#[allow(dead_code)] &'static str), + IO(#[allow(dead_code)] std::io::Error), + Parser(#[allow(dead_code)] ErrorKind), } impl ParseError for CustomError { diff --git a/src/parser/comment.rs b/src/parser/comment.rs index 80bf16a6..cd9a7024 100644 --- a/src/parser/comment.rs +++ b/src/parser/comment.rs @@ -106,7 +106,6 @@ mod tests { use super::*; use crate::context::bind_context; use crate::context::Context; - use crate::context::ContextElement; use crate::context::GlobalSettings; use crate::context::List; diff --git a/src/parser/headline.rs b/src/parser/headline.rs index a836f3cf..4dabec31 100644 --- a/src/parser/headline.rs +++ b/src/parser/headline.rs @@ -77,9 +77,9 @@ fn _heading<'b, 'g, 'r, 's>( // If the section has a planning then the timestamp values are copied to the heading. if let DocumentElement::Section(inner_section) = §ion { if let Some(Element::Planning(planning)) = inner_section.children.first() { - scheduled = planning.scheduled.clone(); - deadline = planning.deadline.clone(); - closed = planning.closed.clone(); + scheduled.clone_from(&planning.scheduled); + deadline.clone_from(&planning.deadline); + closed.clone_from(&planning.closed); } } children.insert(0, section); diff --git a/src/parser/keyword.rs b/src/parser/keyword.rs index e2c67b72..83361691 100644 --- a/src/parser/keyword.rs +++ b/src/parser/keyword.rs @@ -224,7 +224,6 @@ mod tests { use test::Bencher; use super::*; - use crate::parser::OrgSource; #[bench] fn bench_affiliated_keyword(b: &mut Bencher) { diff --git a/src/parser/radio_link.rs b/src/parser/radio_link.rs index c1af7eec..fd8adfbf 100644 --- a/src/parser/radio_link.rs +++ b/src/parser/radio_link.rs @@ -175,9 +175,7 @@ pub(crate) trait RematchObject<'x> { #[cfg(test)] mod tests { use super::*; - use crate::context::Context; use crate::context::GlobalSettings; - use crate::context::List; use crate::parser::element_parser::element; use crate::types::Bold; use crate::types::Element; diff --git a/src/types/mod.rs b/src/types/mod.rs index 26533947..e142dcef 100644 --- a/src/types/mod.rs +++ b/src/types/mod.rs @@ -6,7 +6,6 @@ mod greater_element; mod lesser_element; mod macros; mod object; -mod remove_trailing; mod standard_properties; mod util; pub use affiliated_keyword::AffiliatedKeyword; diff --git a/src/types/remove_trailing.rs b/src/types/remove_trailing.rs deleted file mode 100644 index 822c64c0..00000000 --- a/src/types/remove_trailing.rs +++ /dev/null @@ -1,56 +0,0 @@ -pub(crate) trait RemoveTrailing: Iterator + Sized { - fn remove_trailing>(self, amount_to_remove: R) -> RemoveTrailingIter; -} - -impl RemoveTrailing for I -where - I: Iterator, -{ - fn remove_trailing>(self, amount_to_remove: R) -> RemoveTrailingIter { - RemoveTrailingIter { - inner: self, - buffer: Vec::new(), - next_to_pop: 0, - amount_to_remove: amount_to_remove.into(), - } - } -} - -pub(crate) struct RemoveTrailingIter { - inner: I, - buffer: Vec, - next_to_pop: usize, - amount_to_remove: usize, -} - -impl Iterator for RemoveTrailingIter { - type Item = I::Item; - - fn next(&mut self) -> Option { - if self.buffer.len() < self.amount_to_remove { - self.buffer.reserve_exact(self.amount_to_remove); - } - while self.buffer.len() < self.amount_to_remove { - if let Some(elem) = self.inner.next() { - self.buffer.push(elem); - } else { - // The inner was smaller than amount_to_remove, so never return anything. - return None; - } - } - - let new_value = self.inner.next(); - if self.amount_to_remove == 0 { - return new_value; - } - - if let Some(new_value) = new_value { - let ret = std::mem::replace(&mut self.buffer[self.next_to_pop], new_value); - self.next_to_pop = (self.next_to_pop + 1) % self.amount_to_remove; - Some(ret) - } else { - // We have exactly the amount in the buffer than we wanted to cut off, so stop returning values. - None - } - } -}