Skip to content

Commit

Permalink
Remove crate-wide allow for dead_code
Browse files Browse the repository at this point in the history
This was meant to be removed when enough of the library was implemented.
With suggestions fully implemented it can now be removed. The only
dead_code which is left to resolve is compound pattern replacements
which is a TODO in the checker.
  • Loading branch information
the-mikedavis committed Nov 11, 2024
1 parent 6c2e068 commit 808ae1f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 118 deletions.
18 changes: 4 additions & 14 deletions src/aff.rs
Original file line number Diff line number Diff line change
Expand Up @@ -948,16 +948,6 @@ impl StrPair {
}
}

#[inline]
pub fn left(&self) -> &str {
&self.inner[..self.partition]
}

#[inline]
pub fn right(&self) -> &str {
&self.inner[self.partition..]
}

#[inline]
pub fn full_str(&self) -> &str {
&self.inner
Expand All @@ -972,6 +962,8 @@ impl StrPair {
#[derive(Debug, Clone)]
pub(crate) struct CompoundPattern {
pub begin_end_chars: StrPair,
// TODO: unimplemented. See Checker::check_compound_with_pattern_replacements.
#[allow(dead_code)]
pub replacement: Option<Box<str>>,
pub first_word_flag: Option<Flag>,
pub second_word_flag: Option<Flag>,
Expand Down Expand Up @@ -1456,12 +1448,10 @@ mod test {
#[test]
fn string_pair() {
let pair = StrPair::new("foo", "bar");
assert_eq!(pair.left(), "foo");
assert_eq!(pair.right(), "bar");
assert_eq!(pair.full_str(), "foobar");

let pair = StrPair::new("", "");
assert_eq!(pair.left(), "");
assert_eq!(pair.right(), "");
assert_eq!(pair.full_str(), "")
}

#[test]
Expand Down
20 changes: 11 additions & 9 deletions src/hash_bag.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,6 @@ pub struct HashBag<K, V, S> {
build_hasher: S,
}

impl<K, V, S: BuildHasher + Default> HashBag<K, V, S> {
pub fn new() -> Self {
Self {
table: HashTable::new(),
build_hasher: S::default(),
}
}
}

impl<K, V, S> HashBag<K, V, S> {
/// Returns an iterator over the key-value pairs in the bag.
///
Expand Down Expand Up @@ -185,9 +176,20 @@ where

#[cfg(test)]
mod test {
use core::hash::BuildHasher;

use crate::alloc::{string::ToString, vec::Vec};
use crate::DefaultHashBuilder;

impl<K, V, S: BuildHasher + Default> super::HashBag<K, V, S> {
pub fn new() -> Self {
Self {
table: super::HashTable::new(),
build_hasher: S::default(),
}
}
}

type HashBag<K, V> = super::HashBag<K, V, DefaultHashBuilder>;

#[test]
Expand Down
95 changes: 0 additions & 95 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,6 @@
//! [`hashbrown`]: https://github.com/rust-lang/hashbrown
// TODO: more.

// TODO: remove.
#![allow(dead_code)]
#![no_std]

extern crate alloc;
Expand Down Expand Up @@ -333,11 +331,6 @@ impl FlagSet {
self.as_slice().iter()
}

#[inline]
pub fn len(&self) -> usize {
self.0.len()
}

#[inline]
pub fn is_empty(&self) -> bool {
self.0.is_empty()
Expand All @@ -364,67 +357,6 @@ impl FlagSet {
}
}

pub fn intersection(&self, other: &Self) -> Self {
let mut intersection = Vec::new();
let mut xs = self.iter().peekable();
let mut ys = other.iter().peekable();

while let Some((x, y)) = xs.peek().zip(ys.peek()) {
match x.cmp(y) {
Ordering::Equal => {
intersection.push(**x);
xs.next();
ys.next();
}
Ordering::Greater => {
ys.next();
}
Ordering::Less => {
xs.next();
}
}
}

Self(intersection.as_slice().try_into().unwrap())
}

pub fn union(&self, other: &Self) -> Self {
let mut union = Vec::new();
let mut xs = self.iter().peekable();
let mut ys = other.iter().peekable();

loop {
match (xs.peek(), ys.peek()) {
(Some(x), Some(y)) => match x.cmp(y) {
Ordering::Equal => {
union.push(**x);
xs.next();
ys.next();
}
Ordering::Greater => {
union.push(**y);
ys.next();
}
Ordering::Less => {
union.push(**x);
xs.next();
}
},
(Some(_), None) => {
union.extend(xs.copied());
break;
}
(None, Some(_)) => {
union.extend(ys.copied());
break;
}
(None, None) => break,
}
}

Self(union.as_slice().try_into().unwrap())
}

/// Checks whether the given flag is contained in the flagset.
#[inline]
pub fn contains(&self, flag: &Flag) -> bool {
Expand Down Expand Up @@ -588,33 +520,6 @@ mod test {
assert!(!flagset![].has_intersection(&flagset![]));
}

#[test]
fn flagset_intersection() {
assert_eq!(flagset![], flagset![].intersection(&flagset![]));
assert_eq!(flagset![], flagset![1, 3].intersection(&flagset![2]));
assert_eq!(flagset![], flagset![2].intersection(&flagset![1, 3]));
assert_eq!(flagset![2], flagset![1, 2, 3].intersection(&flagset![2]));
assert_eq!(
flagset![1, 3],
flagset![1, 2, 3].intersection(&flagset![1, 3])
);
assert_eq!(
flagset![1, 2, 3],
flagset![1, 2, 3].intersection(&flagset![1, 2, 3])
);
}

#[test]
fn flagset_union() {
assert_eq!(flagset![], flagset![].union(&flagset![]));
assert_eq!(flagset![1, 2, 3], flagset![1, 3].union(&flagset![2]));
assert_eq!(flagset![1, 2, 3], flagset![2].union(&flagset![1, 3]));
assert_eq!(
flagset![1, 2, 3],
flagset![1, 2, 3].union(&flagset![1, 2, 3])
);
}

#[test]
fn flagset_contains() {
assert!(flagset![1, 2, 3].contains(&flag!(1)));
Expand Down

0 comments on commit 808ae1f

Please sign in to comment.