fix/allow clippy lints

This commit is contained in:
Noah Hellman 2023-02-11 21:21:48 +01:00
parent a6ad7a9d58
commit 413fecfe6a
3 changed files with 12 additions and 10 deletions

View file

@ -27,6 +27,7 @@ pub fn valid<I: Iterator<Item = char>>(chars: I) -> (usize, bool) {
/// A collection of attributes, i.e. a key-value map. /// A collection of attributes, i.e. a key-value map.
// Attributes are relatively rare, we choose to pay 8 bytes always and sometimes an extra // Attributes are relatively rare, we choose to pay 8 bytes always and sometimes an extra
// indirection instead of always 24 bytes. // indirection instead of always 24 bytes.
#[allow(clippy::box_vec)]
#[derive(Debug, Clone, PartialEq, Eq, Default)] #[derive(Debug, Clone, PartialEq, Eq, Default)]
pub struct Attributes<'s>(Option<Box<Vec<(&'s str, CowStr<'s>)>>>); pub struct Attributes<'s>(Option<Box<Vec<(&'s str, CowStr<'s>)>>>);

View file

@ -351,13 +351,13 @@ impl<'s> TreeParser<'s> {
}); });
if let ListItem(ty) = c { if let ListItem(ty) = c {
if self let same_depth = self
.open_lists .open_lists
.last() .last()
.map_or(true, |OpenList { depth, .. }| { .map_or(true, |OpenList { depth, .. }| {
usize::from(*depth) < self.tree.depth() usize::from(*depth) < self.tree.depth()
}) });
{ if same_depth {
let tight = true; let tight = true;
let node = self.tree.enter( let node = self.tree.enter(
Node::Container(Container::List(ListKind { ty, tight })), Node::Container(Container::List(ListKind { ty, tight })),

View file

@ -442,11 +442,10 @@ impl<I: Iterator<Item = char> + Clone> Parser<I> {
if matches!(dir, Dir::Open) { if matches!(dir, Dir::Open) {
return None; return None;
} }
if matches!(dir, Dir::Both) let whitespace_after = self.events.back().map_or(false, |ev| {
&& self.events.back().map_or(false, |ev| { matches!(ev.kind, EventKind::Whitespace | EventKind::Atom(Softbreak))
matches!(ev.kind, EventKind::Whitespace | EventKind::Atom(Softbreak)) });
}) if matches!(dir, Dir::Both) && whitespace_after {
{
return None; return None;
} }
@ -791,6 +790,7 @@ impl<I: Iterator<Item = char> + Clone> Iterator for Parser<I> {
type Item = Event; type Item = Event;
fn next(&mut self) -> Option<Self::Item> { fn next(&mut self) -> Option<Self::Item> {
#[allow(clippy::blocks_in_if_conditions)]
while self.events.is_empty() while self.events.is_empty()
|| !self.openers.is_empty() || !self.openers.is_empty()
|| self // for merge or attributes || self // for merge or attributes
@ -813,12 +813,13 @@ impl<I: Iterator<Item = char> + Clone> Iterator for Parser<I> {
EventKind::Str | EventKind::Whitespace => { EventKind::Str | EventKind::Whitespace => {
// merge str events // merge str events
let mut span = e.span; let mut span = e.span;
while self.events.front().map_or(false, |e| { let should_merge = |e: &Event, span: Span| {
matches!( matches!(
e.kind, e.kind,
EventKind::Str | EventKind::Whitespace | EventKind::Placeholder EventKind::Str | EventKind::Whitespace | EventKind::Placeholder
) && span.end() == e.span.start() ) && span.end() == e.span.start()
}) { };
while self.events.front().map_or(false, |e| should_merge(e, span)) {
let ev = self.events.pop_front().unwrap(); let ev = self.events.pop_front().unwrap();
span = span.union(ev.span); span = span.union(ev.span);
} }