From a371d5fcb405d4066020b049d6ce91dcb5575441 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:33:13 -0700 Subject: [PATCH 01/13] changelog --- CHANGELOG.md | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/CHANGELOG.md b/CHANGELOG.md index 6430aa3..505ab13 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,5 +1,11 @@ # Changelog +## 1.8.1 + +* [e00E](https://github.com/e00E) updated the rustc features so that they all + correctly depend on the lower version feature. + [pr 199](https://github.com/Lokathor/tinyvec/pull/199) + ## 1.8 * [Fuuzetsu](https://github.com/Fuuzetsu) added the `ArrayVec::as_inner` method. From b6c80ed040b7accdacfbbac4f8e1e51e76ebb868 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:35:05 -0700 Subject: [PATCH 02/13] fix paragraphs --- CHANGELOG.md | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 505ab13..b40a48d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -74,13 +74,13 @@ ## 1.1.0 * [slightlyoutofphase](https://github.com/slightlyoutofphase) -added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros. -You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`, -just like normal array initialization allows. Same goes for `tiny_vec!`. -([pr 118](https://github.com/Lokathor/tinyvec/pull/118)) + added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros. + You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`, + just like normal array initialization allows. Same goes for `tiny_vec!`. + ([pr 118](https://github.com/Lokathor/tinyvec/pull/118)) * [not-a-seagull](https://github.com/not-a-seagull) -added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`. -([pr 124](https://github.com/Lokathor/tinyvec/pull/124)) + added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`. + ([pr 124](https://github.com/Lokathor/tinyvec/pull/124)) ## 1.0.2 From b9c255975e90630804ae2fc35cbaae1224d9e9b2 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:36:45 -0700 Subject: [PATCH 03/13] missing inline --- src/arrayvec.rs | 2 ++ src/tinyvec.rs | 5 +++++ 2 files changed, 7 insertions(+) diff --git a/src/arrayvec.rs b/src/arrayvec.rs index f40b617..a1039cf 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -1857,6 +1857,7 @@ impl ArrayVec { /// assert_eq!(v, &[1, 2, 3]); /// assert_eq!(v.capacity(), 13); /// ``` + #[inline] pub fn drain_to_vec_and_reserve(&mut self, n: usize) -> Vec { let cap = n + self.len(); let mut v = Vec::with_capacity(cap); @@ -1902,6 +1903,7 @@ impl ArrayVec { /// assert_eq!(v, &[1, 2, 3]); /// assert_eq!(v.capacity(), 3); /// ``` + #[inline] pub fn drain_to_vec(&mut self) -> Vec { self.drain_to_vec_and_reserve(0) } diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 974d0a8..d9ab44e 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -339,6 +339,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 35); /// ``` + #[inline] pub fn move_to_the_heap_and_reserve(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve(n), @@ -388,6 +389,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] pub fn reserve(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve(n), @@ -451,6 +453,7 @@ impl TinyVec { /// assert!(tv.is_heap()); /// assert!(tv.capacity() >= 5); /// ``` + #[inline] pub fn reserve_exact(&mut self, n: usize) { let arr = match self { TinyVec::Heap(h) => return h.reserve_exact(n), @@ -1205,6 +1208,7 @@ where impl<'p, A: Array, I: Iterator> Drop for TinyVecSplice<'p, A, I> { + #[inline] fn drop(&mut self) { for _ in self.by_ref() {} @@ -1286,6 +1290,7 @@ impl From> for TinyVec { } impl From for TinyVec { + #[inline] fn from(array: A) -> Self { TinyVec::Inline(ArrayVec::from(array)) } From 2a1731f03881a03537795ac056ab503b67da8445 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:37:49 -0700 Subject: [PATCH 04/13] unexpected cfg --- src/lib.rs | 2 +- src/tinyvec.rs | 10 +++++----- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/lib.rs b/src/lib.rs index 8970878..8ecd771 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -9,7 +9,7 @@ feature(debugger_visualizer), debugger_visualizer(natvis_file = "../debug_metadata/tinyvec.natvis") )] -#![cfg_attr(docs_rs, feature(doc_cfg))] +#![cfg_attr(docsrs, feature(doc_cfg))] #![warn(clippy::missing_inline_in_public_items)] #![warn(clippy::must_use_candidate)] #![warn(missing_docs)] diff --git a/src/tinyvec.rs b/src/tinyvec.rs index d9ab44e..e6d1c53 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -35,7 +35,7 @@ use serde::ser::{Serialize, SerializeSeq, Serializer}; /// let many_ints: TinyVec<[i32; 4]> = tiny_vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10); /// ``` #[macro_export] -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] macro_rules! tiny_vec { ($array_type:ty => $($elem:expr),* $(,)?) => { { @@ -94,7 +94,7 @@ pub enum TinyVecConstructor { /// let empty_tv = tiny_vec!([u8; 16]); /// let some_ints = tiny_vec!([i32; 4] => 1, 2, 3); /// ``` -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVec { #[allow(missing_docs)] Inline(ArrayVec), @@ -1064,7 +1064,7 @@ impl TinyVec { /// Draining iterator for `TinyVecDrain` /// /// See [`TinyVecDrain::drain`](TinyVecDrain::::drain) -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVecDrain<'p, A: Array> { #[allow(missing_docs)] Inline(ArrayVecDrain<'p, A::Item>), @@ -1113,7 +1113,7 @@ impl<'p, A: Array> DoubleEndedIterator for TinyVecDrain<'p, A> { /// Splicing iterator for `TinyVec` /// See [`TinyVec::splice`](TinyVec::::splice) -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub struct TinyVecSplice<'p, A: Array, I: Iterator> { parent: &'p mut TinyVec, removal_start: usize, @@ -1335,7 +1335,7 @@ impl FromIterator for TinyVec { } /// Iterator for consuming an `TinyVec` and returning owned elements. -#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))] +#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))] pub enum TinyVecIterator { #[allow(missing_docs)] Inline(ArrayVecIterator), From dbdc9b5864ae53c529bb1046403f59f1d935a83b Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:38:20 -0700 Subject: [PATCH 05/13] fix docs paragraph --- src/arrayvec.rs | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/arrayvec.rs b/src/arrayvec.rs index a1039cf..24562c5 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -52,8 +52,8 @@ macro_rules! array_vec { /// An array-backed, vector-like data structure. /// /// * `ArrayVec` has a fixed capacity, equal to the minimum of the array size -/// and `u16::MAX`. Note that not all capacities are necessarily supported by -/// default. See comments in [`Array`]. +/// and `u16::MAX`. Note that not all capacities are necessarily supported by +/// default. See comments in [`Array`]. /// * `ArrayVec` has a variable length, as you add and remove elements. Attempts /// to fill the vec beyond its capacity will cause a panic. /// * All of the vec's array slots are always initialized in terms of Rust's From 4d25bfdc730c2d9991e22e68033e07f0dff63f36 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:39:08 -0700 Subject: [PATCH 06/13] hush clippy --- src/arrayvec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/arrayvec.rs b/src/arrayvec.rs index 24562c5..94b6fc7 100644 --- a/src/arrayvec.rs +++ b/src/arrayvec.rs @@ -572,6 +572,7 @@ impl ArrayVec { } let target = &mut self.as_mut_slice()[index..]; + #[allow(clippy::needless_range_loop)] for i in 0..target.len() { core::mem::swap(&mut item, &mut target[i]); } From a0fe02fc2f756836d47b377d2a52dde120cea1d2 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:39:35 -0700 Subject: [PATCH 07/13] must_use --- src/slicevec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/slicevec.rs b/src/slicevec.rs index 8856b53..90b8e9e 100644 --- a/src/slicevec.rs +++ b/src/slicevec.rs @@ -655,6 +655,7 @@ impl<'s, T> SliceVec<'s, T> { /// sv.push(13); /// assert_eq!(sv.grab_spare_slice().len(), 0); /// ``` + #[must_use] #[inline(always)] pub fn grab_spare_slice(&self) -> &[T] { &self.data[self.len..] From da961d76a026ffee8e54dc8f606f0ffc2f807bde Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:39:50 -0700 Subject: [PATCH 08/13] duplicate attribute --- src/tinyvec.rs | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index e6d1c53..dbd7ad6 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -1,5 +1,3 @@ -#![cfg(feature = "alloc")] - use super::*; use alloc::vec::{self, Vec}; From ac8057bfcb2401f0848480cf0cb88cfdafd29750 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:40:05 -0700 Subject: [PATCH 09/13] missing inline --- src/tinyvec.rs | 1 + 1 file changed, 1 insertion(+) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index dbd7ad6..091193b 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -264,6 +264,7 @@ impl TinyVec { /// tv.shrink_to_fit(); /// assert!(tv.is_inline()); /// ``` + #[inline] pub fn shrink_to_fit(&mut self) { let vec = match self { TinyVec::Inline(_) => return, From ba4dda30a69a686c269a231e9e4f00970ad2496b Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:40:29 -0700 Subject: [PATCH 10/13] use core::mem::take --- src/tinyvec.rs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 091193b..8e282aa 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -275,7 +275,7 @@ impl TinyVec { return vec.shrink_to_fit(); } - let moved_vec = core::mem::replace(vec, Vec::new()); + let moved_vec = core::mem::take(vec); let mut av = ArrayVec::default(); let mut rest = av.fill(moved_vec); From 5ab51232ef01ad980a2cd6b1acf639df686e5eef Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:43:39 -0700 Subject: [PATCH 11/13] MSRV note --- .github/workflows/rust.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/rust.yml b/.github/workflows/rust.yml index 35645fd..985dea0 100644 --- a/.github/workflows/rust.yml +++ b/.github/workflows/rust.yml @@ -11,7 +11,7 @@ jobs: matrix: os: [ubuntu-latest] rust: - - 1.47.0 + - 1.47.0 # approximate MSRV is Stable -30 - stable - beta - nightly From 023a973c6ad44ad96bae1ca3e19ef335db3210b2 Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:44:48 -0700 Subject: [PATCH 12/13] needless arbitrary type --- src/tinyvec.rs | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 8e282aa..658202b 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -642,7 +642,7 @@ impl TinyVec { /// assert_eq!(tv.as_slice(), &[2, 4][..]); /// ``` #[inline] - pub fn retain bool>(self: &mut Self, acceptable: F) { + pub fn retain bool>(&mut self, acceptable: F) { match self { TinyVec::Inline(i) => i.retain(acceptable), TinyVec::Heap(h) => h.retain(acceptable), @@ -673,14 +673,14 @@ impl TinyVec { /// Helper for getting the mut slice. #[inline(always)] #[must_use] - pub fn as_mut_slice(self: &mut Self) -> &mut [A::Item] { + pub fn as_mut_slice(&mut self) -> &mut [A::Item] { self.deref_mut() } /// Helper for getting the shared slice. #[inline(always)] #[must_use] - pub fn as_slice(self: &Self) -> &[A::Item] { + pub fn as_slice(&self) -> &[A::Item] { self.deref() } From 09240257055fc4b352a7cfb4143c37455e5230eb Mon Sep 17 00:00:00 2001 From: Lokathor Date: Fri, 20 Dec 2024 12:45:30 -0700 Subject: [PATCH 13/13] call core::mem::take --- src/tinyvec.rs | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/tinyvec.rs b/src/tinyvec.rs index 658202b..953a47a 100644 --- a/src/tinyvec.rs +++ b/src/tinyvec.rs @@ -840,8 +840,7 @@ impl TinyVec { if let Some(x) = arr.try_insert(index, item) { let mut v = Vec::with_capacity(arr.len() * 2); - let mut it = - arr.iter_mut().map(|r| core::mem::replace(r, Default::default())); + let mut it = arr.iter_mut().map(core::mem::take); v.extend(it.by_ref().take(index)); v.push(x); v.extend(it);