cargo fmt hasn't been used in a while it seems.

This commit is contained in:
Lokathor
2020-01-19 13:02:54 -07:00
parent 11b8f629f2
commit 032ac155c9
8 changed files with 141 additions and 127 deletions
+48 -45
View File
@@ -1,61 +1,64 @@
use arbitrary::{Arbitrary, Unstructured};
use std::ops::{Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo, RangeToInclusive, Bound};
use std::ops::{
Bound, Range, RangeBounds, RangeFrom, RangeInclusive, RangeTo,
RangeToInclusive,
};
#[derive(Debug, Clone, Eq, PartialEq)]
pub enum ArbRange<T> {
Range(Range<T>),
RangeFrom(RangeFrom<T>),
RangeInclusive(RangeInclusive<T>),
RangeTo(RangeTo<T>),
RangeToInclusive(RangeToInclusive<T>),
Range(Range<T>),
RangeFrom(RangeFrom<T>),
RangeInclusive(RangeInclusive<T>),
RangeTo(RangeTo<T>),
RangeToInclusive(RangeToInclusive<T>),
}
impl<T> RangeBounds<T> for ArbRange<T> {
fn start_bound(&self) -> Bound<&T> {
match self {
ArbRange::Range(range) => range.start_bound(),
ArbRange::RangeFrom(range) => range.start_bound(),
ArbRange::RangeInclusive(range) => range.start_bound(),
ArbRange::RangeTo(range) => range.start_bound(),
ArbRange::RangeToInclusive(range) => range.start_bound(),
}
fn start_bound(&self) -> Bound<&T> {
match self {
ArbRange::Range(range) => range.start_bound(),
ArbRange::RangeFrom(range) => range.start_bound(),
ArbRange::RangeInclusive(range) => range.start_bound(),
ArbRange::RangeTo(range) => range.start_bound(),
ArbRange::RangeToInclusive(range) => range.start_bound(),
}
}
fn end_bound(&self) -> Bound<&T> {
match self {
ArbRange::Range(range) => range.end_bound(),
ArbRange::RangeFrom(range) => range.end_bound(),
ArbRange::RangeInclusive(range) => range.end_bound(),
ArbRange::RangeTo(range) => range.end_bound(),
ArbRange::RangeToInclusive(range) => range.end_bound(),
}
fn end_bound(&self) -> Bound<&T> {
match self {
ArbRange::Range(range) => range.end_bound(),
ArbRange::RangeFrom(range) => range.end_bound(),
ArbRange::RangeInclusive(range) => range.end_bound(),
ArbRange::RangeTo(range) => range.end_bound(),
ArbRange::RangeToInclusive(range) => range.end_bound(),
}
}
fn contains<U: ?Sized>(&self, item: &U) -> bool
where
T: PartialOrd<U>,
U: PartialOrd<T>,
{
match self {
ArbRange::Range(range) => range.contains(item),
ArbRange::RangeFrom(range) => range.contains(item),
ArbRange::RangeInclusive(range) => range.contains(item),
ArbRange::RangeTo(range) => range.contains(item),
ArbRange::RangeToInclusive(range) => range.contains(item),
}
fn contains<U: ?Sized>(&self, item: &U) -> bool
where
T: PartialOrd<U>,
U: PartialOrd<T>,
{
match self {
ArbRange::Range(range) => range.contains(item),
ArbRange::RangeFrom(range) => range.contains(item),
ArbRange::RangeInclusive(range) => range.contains(item),
ArbRange::RangeTo(range) => range.contains(item),
ArbRange::RangeToInclusive(range) => range.contains(item),
}
}
}
impl<T: Arbitrary> Arbitrary for ArbRange<T> {
fn arbitrary<U: Unstructured + ?Sized>(u: &mut U) -> Result<Self, U::Error> {
let variant = u8::arbitrary(u)? % 5;
Ok(match variant {
0 => ArbRange::Range(T::arbitrary(u)?..T::arbitrary(u)?),
1 => ArbRange::RangeFrom(T::arbitrary(u)?..),
2 => ArbRange::RangeInclusive(T::arbitrary(u)?..=T::arbitrary(u)?),
3 => ArbRange::RangeTo(..T::arbitrary(u)?),
4 => ArbRange::RangeToInclusive(..=T::arbitrary(u)?),
_ => unreachable!(),
})
}
fn arbitrary<U: Unstructured + ?Sized>(u: &mut U) -> Result<Self, U::Error> {
let variant = u8::arbitrary(u)? % 5;
Ok(match variant {
0 => ArbRange::Range(T::arbitrary(u)?..T::arbitrary(u)?),
1 => ArbRange::RangeFrom(T::arbitrary(u)?..),
2 => ArbRange::RangeInclusive(T::arbitrary(u)?..=T::arbitrary(u)?),
3 => ArbRange::RangeTo(..T::arbitrary(u)?),
4 => ArbRange::RangeToInclusive(..=T::arbitrary(u)?),
_ => unreachable!(),
})
}
}
+25 -19
View File
@@ -1,7 +1,11 @@
use derive_arbitrary::Arbitrary;
use arbitrary_model_tests::arbitrary_stateful_operations;
use derive_arbitrary::Arbitrary;
use honggfuzz::fuzz;
use std::{fmt::Debug, iter::FromIterator, ops::{RangeBounds, Bound}};
use std::{
fmt::Debug,
iter::FromIterator,
ops::{Bound, RangeBounds},
};
use tinyvec::ArrayVec;
use tinyvec_fuzz::ArbRange;
@@ -83,29 +87,31 @@ arbitrary_stateful_operations! {
const MAX_RING_SIZE: usize = 16_384;
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
use arbitrary::{Arbitrary, FiniteBuffer};
use arbitrary::{Arbitrary, FiniteBuffer};
let mut ring = FiniteBuffer::new(&data, MAX_RING_SIZE).map_err(|_| ())?;
let mut ring = FiniteBuffer::new(&data, MAX_RING_SIZE).map_err(|_| ())?;
let mut model = Vec::<u16>::default();
let mut tested: ArrayVec<[u16; 32]> = ArrayVec::new();
let mut model = Vec::<u16>::default();
let mut tested: ArrayVec<[u16; 32]> = ArrayVec::new();
let mut _op_trace = String::new();
while let Ok(op) = <op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring) {
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
op.execute_and_compare(&mut model, &mut tested);
}
let mut _op_trace = String::new();
while let Ok(op) =
<op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring)
{
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
op.execute_and_compare(&mut model, &mut tested);
}
Ok(())
Ok(())
}
fn main() -> Result<(), ()> {
better_panic::install();
better_panic::install();
loop {
fuzz!(|data: &[u8]| {
let _ = fuzz_cycle(data);
});
}
loop {
fuzz!(|data: &[u8]| {
let _ = fuzz_cycle(data);
});
}
}
+25 -19
View File
@@ -1,7 +1,11 @@
use derive_arbitrary::Arbitrary;
use arbitrary_model_tests::arbitrary_stateful_operations;
use derive_arbitrary::Arbitrary;
use honggfuzz::fuzz;
use std::{fmt::Debug, iter::FromIterator, ops::{RangeBounds, Bound}};
use std::{
fmt::Debug,
iter::FromIterator,
ops::{Bound, RangeBounds},
};
use tinyvec::TinyVec;
use tinyvec_fuzz::ArbRange;
@@ -81,29 +85,31 @@ arbitrary_stateful_operations! {
const MAX_RING_SIZE: usize = 16_384;
fn fuzz_cycle(data: &[u8]) -> Result<(), ()> {
use arbitrary::{Arbitrary, FiniteBuffer};
use arbitrary::{Arbitrary, FiniteBuffer};
let mut ring = FiniteBuffer::new(&data, MAX_RING_SIZE).map_err(|_| ())?;
let mut ring = FiniteBuffer::new(&data, MAX_RING_SIZE).map_err(|_| ())?;
let mut model = Vec::<u16>::default();
let mut tested: TinyVec<[u16; 32]> = TinyVec::new();
let mut model = Vec::<u16>::default();
let mut tested: TinyVec<[u16; 32]> = TinyVec::new();
let mut _op_trace = String::new();
while let Ok(op) = <op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring) {
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
op.execute_and_compare(&mut model, &mut tested);
}
let mut _op_trace = String::new();
while let Ok(op) =
<op::Op<u16, ArbRange<usize>> as Arbitrary>::arbitrary(&mut ring)
{
#[cfg(fuzzing_debug)]
_op_trace.push_str(&format!("{}\n", op.to_string()));
op.execute_and_compare(&mut model, &mut tested);
}
Ok(())
Ok(())
}
fn main() -> Result<(), ()> {
better_panic::install();
better_panic::install();
loop {
fuzz!(|data: &[u8]| {
let _ = fuzz_cycle(data);
});
}
loop {
fuzz!(|data: &[u8]| {
let _ = fuzz_cycle(data);
});
}
}
+1 -1
View File
@@ -28,7 +28,7 @@ pub trait Array {
fn as_slice(&self) -> &[Self::Item];
/// Gives a unique slice over the whole thing.
///
///
/// A correct implementation will return a slice with a length equal to the
/// `CAPACITY` value.
fn as_slice_mut(&mut self) -> &mut [Self::Item];
+2 -5
View File
@@ -4,10 +4,7 @@
feature = "nightly_slice_partition_dedup",
feature(slice_partition_dedup)
)]
#![cfg_attr(
feature = "nightly_const_generics",
feature(const_generics)
)]
#![cfg_attr(feature = "nightly_const_generics", feature(const_generics))]
#![warn(clippy::missing_inline_in_public_items)]
#![warn(clippy::must_use_candidate)]
#![warn(missing_docs)]
@@ -91,5 +88,5 @@ pub use tinyvec::*;
// Replace with mem::take as soon as MSRV allows it
fn take<T: Default>(from: &mut T) -> T {
replace(from, T::default())
replace(from, T::default())
}
+38 -36
View File
@@ -14,9 +14,9 @@ use alloc::vec::Vec;
///
/// ```rust
/// use tinyvec::*;
///
///
/// let empty_av = tiny_vec!([u8; 16]);
///
///
/// let some_ints = tiny_vec!([i32; 4], 1, 2, 3);
/// ```
#[macro_export]
@@ -51,7 +51,7 @@ pub enum TinyVec<A: Array> {
#[allow(missing_docs)]
Inline(ArrayVec<A>),
#[allow(missing_docs)]
Heap(Vec<A::Item>)
Heap(Vec<A::Item>),
}
impl<A: Array + Default> Default for TinyVec<A> {
#[inline]
@@ -127,9 +127,9 @@ impl<A: Array> TinyVec<A> {
}
/// A mutable pointer to the backing array.
///
///
/// ## Safety
///
///
/// This pointer has provenance over the _entire_ backing array/buffer.
#[inline(always)]
#[must_use]
@@ -148,9 +148,9 @@ impl<A: Array> TinyVec<A> {
}
/// A const pointer to the backing array.
///
///
/// ## Safety
///
///
/// This pointer has provenance over the _entire_ backing array/buffer.
#[inline(always)]
#[must_use]
@@ -169,7 +169,7 @@ impl<A: Array> TinyVec<A> {
}
/// The capacity of the `TinyVec`.
///
///
/// When not heap allocated this is fixed based on the array type.
/// Otherwise its the result of the underlying Vec::capacity.
#[inline(always)]
@@ -186,7 +186,7 @@ impl<A: Array> TinyVec<A> {
pub fn clear(&mut self) {
self.truncate(0)
}
/// De-duplicates the vec.
#[cfg(feature = "nightly_slice_partition_dedup")]
#[inline(always)]
@@ -325,12 +325,14 @@ impl<A: Array> TinyVec<A> {
#[inline]
pub fn insert(&mut self, index: usize, item: A::Item) {
match self {
TinyVec::Inline(a) => if a.len() == A::CAPACITY {
self.move_to_the_heap();
self.insert(index, item)
} else {
a.insert(index, item);
},
TinyVec::Inline(a) => {
if a.len() == A::CAPACITY {
self.move_to_the_heap();
self.insert(index, item)
} else {
a.insert(index, item);
}
}
TinyVec::Heap(v) => v.insert(index, item),
}
}
@@ -363,7 +365,7 @@ impl<A: Array> TinyVec<A> {
}
/// Remove and return the last element of the vec, if there is one.
///
///
/// ## Failure
/// * If the vec is empty you get `None`.
#[inline]
@@ -380,12 +382,14 @@ impl<A: Array> TinyVec<A> {
#[inline(always)]
pub fn push(&mut self, val: A::Item) {
match self {
TinyVec::Inline(a) => if a.len() == A::CAPACITY {
self.move_to_the_heap();
self.push(val)
} else {
a.push(val);
},
TinyVec::Inline(a) => {
if a.len() == A::CAPACITY {
self.move_to_the_heap();
self.push(val)
} else {
a.push(val);
}
}
TinyVec::Heap(v) => v.push(val),
}
}
@@ -440,12 +444,14 @@ impl<A: Array> TinyVec<A> {
A::Item: Clone,
{
match self {
TinyVec::Inline(a) => if new_len > A::CAPACITY {
self.move_to_the_heap();
self.resize(new_len, new_val);
} else {
a.resize(new_len, new_val);
},
TinyVec::Inline(a) => {
if new_len > A::CAPACITY {
self.move_to_the_heap();
self.resize(new_len, new_val);
} else {
a.resize(new_len, new_val);
}
}
TinyVec::Heap(v) => v.resize(new_len, new_val),
}
}
@@ -473,11 +479,7 @@ impl<A: Array> TinyVec<A> {
/// assert_eq!(tv.as_slice(), &[2, 4, 8, 16][..]);
/// ```
#[inline]
pub fn resize_with<F: FnMut() -> A::Item>(
&mut self,
new_len: usize,
f: F,
) {
pub fn resize_with<F: FnMut() -> A::Item>(&mut self, new_len: usize, f: F) {
match self {
TinyVec::Inline(a) => a.resize_with(new_len, f),
TinyVec::Heap(v) => v.resize_with(new_len, f),
@@ -558,7 +560,7 @@ impl<A: Array> TinyVec<A> {
}
/// Reduces the vec's length to the given value.
///
///
/// If the vec is already shorter than the input, nothing happens.
#[inline]
pub fn truncate(&mut self, new_len: usize) {
@@ -585,7 +587,7 @@ impl<A: Array> TinyVec<A> {
}
/// Draining iterator for `TinyVecDrain`
///
///
/// See [`TinyVecDrain::drain`](TinyVecDrain::<A>::drain)
pub struct TinyVecDrain<'p, A: Array> {
parent: &'p mut TinyVec<A>,
@@ -680,7 +682,7 @@ pub enum TinyVecIterator<A: Array> {
#[allow(missing_docs)]
Inline(ArrayVecIterator<A>),
#[allow(missing_docs)]
Heap(alloc::vec::IntoIter<A::Item>)
Heap(alloc::vec::IntoIter<A::Item>),
}
impl<A: Array> Iterator for TinyVecIterator<A> {
type Item = A::Item;
+1 -1
View File
@@ -1,7 +1,7 @@
#![allow(bad_style)]
use tinyvec::*;
use std::iter::FromIterator;
use tinyvec::*;
#[test]
fn test_a_vec() {
+1 -1
View File
@@ -1,8 +1,8 @@
#![allow(bad_style)]
#![allow(clippy::redundant_clone)]
use tinyvec::*;
use std::iter::FromIterator;
use tinyvec::*;
#[test]
fn TinyVec_swap_remove() {