Skip to content

Commit 8a2eaf8

Browse files
authored
end of 2024 cleanup (#202)
* changelog * fix paragraphs * missing inline * unexpected cfg * fix docs paragraph * hush clippy * must_use * duplicate attribute * missing inline * use core::mem::take * MSRV note * needless arbitrary type * call core::mem::take
1 parent e4153c8 commit 8a2eaf8

File tree

6 files changed

+36
-23
lines changed

6 files changed

+36
-23
lines changed

.github/workflows/rust.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ jobs:
1111
matrix:
1212
os: [ubuntu-latest]
1313
rust:
14-
- 1.47.0
14+
- 1.47.0 # approximate MSRV is Stable -30
1515
- stable
1616
- beta
1717
- nightly

CHANGELOG.md

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# Changelog
22

3+
## 1.8.1
4+
5+
* [e00E](https://github.com/e00E) updated the rustc features so that they all
6+
correctly depend on the lower version feature.
7+
[pr 199](https://github.com/Lokathor/tinyvec/pull/199)
8+
39
## 1.8
410

511
* [Fuuzetsu](https://github.com/Fuuzetsu) added the `ArrayVec::as_inner` method.
@@ -68,13 +74,13 @@
6874
## 1.1.0
6975

7076
* [slightlyoutofphase](https://github.com/slightlyoutofphase)
71-
added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros.
72-
You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`,
73-
just like normal array initialization allows. Same goes for `tiny_vec!`.
74-
([pr 118](https://github.com/Lokathor/tinyvec/pull/118))
77+
added "array splat" style syntax to the `array_vec!` and `tiny_vec!` macros.
78+
You can now write `array_vec![true; 5]` and get a length 5 array vec full of `true`,
79+
just like normal array initialization allows. Same goes for `tiny_vec!`.
80+
([pr 118](https://github.com/Lokathor/tinyvec/pull/118))
7581
* [not-a-seagull](https://github.com/not-a-seagull)
76-
added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`.
77-
([pr 124](https://github.com/Lokathor/tinyvec/pull/124))
82+
added `ArrayVec::into_inner` so that you can get the array out of an `ArrayVec`.
83+
([pr 124](https://github.com/Lokathor/tinyvec/pull/124))
7884

7985
## 1.0.2
8086

src/arrayvec.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,8 +52,8 @@ macro_rules! array_vec {
5252
/// An array-backed, vector-like data structure.
5353
///
5454
/// * `ArrayVec` has a fixed capacity, equal to the minimum of the array size
55-
/// and `u16::MAX`. Note that not all capacities are necessarily supported by
56-
/// default. See comments in [`Array`].
55+
/// and `u16::MAX`. Note that not all capacities are necessarily supported by
56+
/// default. See comments in [`Array`].
5757
/// * `ArrayVec` has a variable length, as you add and remove elements. Attempts
5858
/// to fill the vec beyond its capacity will cause a panic.
5959
/// * All of the vec's array slots are always initialized in terms of Rust's
@@ -572,6 +572,7 @@ impl<A: Array> ArrayVec<A> {
572572
}
573573

574574
let target = &mut self.as_mut_slice()[index..];
575+
#[allow(clippy::needless_range_loop)]
575576
for i in 0..target.len() {
576577
core::mem::swap(&mut item, &mut target[i]);
577578
}
@@ -1857,6 +1858,7 @@ impl<A: Array> ArrayVec<A> {
18571858
/// assert_eq!(v, &[1, 2, 3]);
18581859
/// assert_eq!(v.capacity(), 13);
18591860
/// ```
1861+
#[inline]
18601862
pub fn drain_to_vec_and_reserve(&mut self, n: usize) -> Vec<A::Item> {
18611863
let cap = n + self.len();
18621864
let mut v = Vec::with_capacity(cap);
@@ -1902,6 +1904,7 @@ impl<A: Array> ArrayVec<A> {
19021904
/// assert_eq!(v, &[1, 2, 3]);
19031905
/// assert_eq!(v.capacity(), 3);
19041906
/// ```
1907+
#[inline]
19051908
pub fn drain_to_vec(&mut self) -> Vec<A::Item> {
19061909
self.drain_to_vec_and_reserve(0)
19071910
}

src/lib.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
feature(debugger_visualizer),
1010
debugger_visualizer(natvis_file = "../debug_metadata/tinyvec.natvis")
1111
)]
12-
#![cfg_attr(docs_rs, feature(doc_cfg))]
12+
#![cfg_attr(docsrs, feature(doc_cfg))]
1313
#![warn(clippy::missing_inline_in_public_items)]
1414
#![warn(clippy::must_use_candidate)]
1515
#![warn(missing_docs)]

src/slicevec.rs

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -655,6 +655,7 @@ impl<'s, T> SliceVec<'s, T> {
655655
/// sv.push(13);
656656
/// assert_eq!(sv.grab_spare_slice().len(), 0);
657657
/// ```
658+
#[must_use]
658659
#[inline(always)]
659660
pub fn grab_spare_slice(&self) -> &[T] {
660661
&self.data[self.len..]

src/tinyvec.rs

Lines changed: 16 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
#![cfg(feature = "alloc")]
2-
31
use super::*;
42

53
use alloc::vec::{self, Vec};
@@ -35,7 +33,7 @@ use serde::ser::{Serialize, SerializeSeq, Serializer};
3533
/// let many_ints: TinyVec<[i32; 4]> = tiny_vec!(1, 2, 3, 4, 5, 6, 7, 8, 9, 10);
3634
/// ```
3735
#[macro_export]
38-
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
36+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
3937
macro_rules! tiny_vec {
4038
($array_type:ty => $($elem:expr),* $(,)?) => {
4139
{
@@ -94,7 +92,7 @@ pub enum TinyVecConstructor<A: Array> {
9492
/// let empty_tv = tiny_vec!([u8; 16]);
9593
/// let some_ints = tiny_vec!([i32; 4] => 1, 2, 3);
9694
/// ```
97-
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
95+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
9896
pub enum TinyVec<A: Array> {
9997
#[allow(missing_docs)]
10098
Inline(ArrayVec<A>),
@@ -266,6 +264,7 @@ impl<A: Array> TinyVec<A> {
266264
/// tv.shrink_to_fit();
267265
/// assert!(tv.is_inline());
268266
/// ```
267+
#[inline]
269268
pub fn shrink_to_fit(&mut self) {
270269
let vec = match self {
271270
TinyVec::Inline(_) => return,
@@ -276,7 +275,7 @@ impl<A: Array> TinyVec<A> {
276275
return vec.shrink_to_fit();
277276
}
278277

279-
let moved_vec = core::mem::replace(vec, Vec::new());
278+
let moved_vec = core::mem::take(vec);
280279

281280
let mut av = ArrayVec::default();
282281
let mut rest = av.fill(moved_vec);
@@ -339,6 +338,7 @@ impl<A: Array> TinyVec<A> {
339338
/// assert!(tv.is_heap());
340339
/// assert!(tv.capacity() >= 35);
341340
/// ```
341+
#[inline]
342342
pub fn move_to_the_heap_and_reserve(&mut self, n: usize) {
343343
let arr = match self {
344344
TinyVec::Heap(h) => return h.reserve(n),
@@ -388,6 +388,7 @@ impl<A: Array> TinyVec<A> {
388388
/// assert!(tv.is_heap());
389389
/// assert!(tv.capacity() >= 5);
390390
/// ```
391+
#[inline]
391392
pub fn reserve(&mut self, n: usize) {
392393
let arr = match self {
393394
TinyVec::Heap(h) => return h.reserve(n),
@@ -451,6 +452,7 @@ impl<A: Array> TinyVec<A> {
451452
/// assert!(tv.is_heap());
452453
/// assert!(tv.capacity() >= 5);
453454
/// ```
455+
#[inline]
454456
pub fn reserve_exact(&mut self, n: usize) {
455457
let arr = match self {
456458
TinyVec::Heap(h) => return h.reserve_exact(n),
@@ -640,7 +642,7 @@ impl<A: Array> TinyVec<A> {
640642
/// assert_eq!(tv.as_slice(), &[2, 4][..]);
641643
/// ```
642644
#[inline]
643-
pub fn retain<F: FnMut(&A::Item) -> bool>(self: &mut Self, acceptable: F) {
645+
pub fn retain<F: FnMut(&A::Item) -> bool>(&mut self, acceptable: F) {
644646
match self {
645647
TinyVec::Inline(i) => i.retain(acceptable),
646648
TinyVec::Heap(h) => h.retain(acceptable),
@@ -671,14 +673,14 @@ impl<A: Array> TinyVec<A> {
671673
/// Helper for getting the mut slice.
672674
#[inline(always)]
673675
#[must_use]
674-
pub fn as_mut_slice(self: &mut Self) -> &mut [A::Item] {
676+
pub fn as_mut_slice(&mut self) -> &mut [A::Item] {
675677
self.deref_mut()
676678
}
677679

678680
/// Helper for getting the shared slice.
679681
#[inline(always)]
680682
#[must_use]
681-
pub fn as_slice(self: &Self) -> &[A::Item] {
683+
pub fn as_slice(&self) -> &[A::Item] {
682684
self.deref()
683685
}
684686

@@ -838,8 +840,7 @@ impl<A: Array> TinyVec<A> {
838840

839841
if let Some(x) = arr.try_insert(index, item) {
840842
let mut v = Vec::with_capacity(arr.len() * 2);
841-
let mut it =
842-
arr.iter_mut().map(|r| core::mem::replace(r, Default::default()));
843+
let mut it = arr.iter_mut().map(core::mem::take);
843844
v.extend(it.by_ref().take(index));
844845
v.push(x);
845846
v.extend(it);
@@ -1061,7 +1062,7 @@ impl<A: Array> TinyVec<A> {
10611062
/// Draining iterator for `TinyVecDrain`
10621063
///
10631064
/// See [`TinyVecDrain::drain`](TinyVecDrain::<A>::drain)
1064-
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
1065+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
10651066
pub enum TinyVecDrain<'p, A: Array> {
10661067
#[allow(missing_docs)]
10671068
Inline(ArrayVecDrain<'p, A::Item>),
@@ -1110,7 +1111,7 @@ impl<'p, A: Array> DoubleEndedIterator for TinyVecDrain<'p, A> {
11101111

11111112
/// Splicing iterator for `TinyVec`
11121113
/// See [`TinyVec::splice`](TinyVec::<A>::splice)
1113-
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
1114+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
11141115
pub struct TinyVecSplice<'p, A: Array, I: Iterator<Item = A::Item>> {
11151116
parent: &'p mut TinyVec<A>,
11161117
removal_start: usize,
@@ -1205,6 +1206,7 @@ where
12051206
impl<'p, A: Array, I: Iterator<Item = A::Item>> Drop
12061207
for TinyVecSplice<'p, A, I>
12071208
{
1209+
#[inline]
12081210
fn drop(&mut self) {
12091211
for _ in self.by_ref() {}
12101212

@@ -1286,6 +1288,7 @@ impl<A: Array> From<ArrayVec<A>> for TinyVec<A> {
12861288
}
12871289

12881290
impl<A: Array> From<A> for TinyVec<A> {
1291+
#[inline]
12891292
fn from(array: A) -> Self {
12901293
TinyVec::Inline(ArrayVec::from(array))
12911294
}
@@ -1330,7 +1333,7 @@ impl<A: Array> FromIterator<A::Item> for TinyVec<A> {
13301333
}
13311334

13321335
/// Iterator for consuming an `TinyVec` and returning owned elements.
1333-
#[cfg_attr(docs_rs, doc(cfg(feature = "alloc")))]
1336+
#[cfg_attr(docsrs, doc(cfg(feature = "alloc")))]
13341337
pub enum TinyVecIterator<A: Array> {
13351338
#[allow(missing_docs)]
13361339
Inline(ArrayVecIterator<A>),

0 commit comments

Comments
 (0)