Skip to content

Commit 3b4d5c8

Browse files
authored
Merge pull request #72 from emilio/auto-thin-vec-test
Add some tests for auto_thin_vec.
2 parents 4d59aa3 + f38efdd commit 3b4d5c8

File tree

2 files changed

+38
-2
lines changed

2 files changed

+38
-2
lines changed

.github/workflows/rust.yml

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,11 @@ jobs:
2222
cargo miri setup
2323
- name: Test (default) with Miri
2424
run: MIRIFLAGS=-Zmiri-strict-provenance cargo miri test
25+
- name: Test (default) with Miri + Tree Borrows
26+
run: MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-tree-borrows" cargo miri test
27+
# AutoThinVec needs tree borrows.
2528
- name: Test (gecko-ffi) with Miri
26-
run: MIRIFLAGS=-Zmiri-strict-provenance cargo miri test --features=gecko-ffi
29+
run: MIRIFLAGS="-Zmiri-strict-provenance -Zmiri-tree-borrows" cargo miri test --features=gecko-ffi
2730
- name: Test (unstable features) with Miri
2831
run: MIRIFLAGS=-Zmiri-strict-provenance cargo miri test --features=unstable
2932

src/lib.rs

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2681,6 +2681,7 @@ impl<T, const N: usize> AutoThinVec<T, N> {
26812681
debug_assert!(self.is_singleton());
26822682
let this = unsafe { self.get_unchecked_mut() };
26832683
this.buffer.header.set_len(0);
2684+
// TODO(emilio): Use NonNull::from_mut when msrv allows.
26842685
this.inner.ptr = NonNull::new_unchecked(&mut this.buffer.header);
26852686
}
26862687

@@ -2728,7 +2729,7 @@ impl<T, const N: usize> Deref for AutoThinVec<T, N> {
27282729
#[macro_export]
27292730
macro_rules! auto_thin_vec {
27302731
(let $name:ident : [$ty:ty; $cap:literal]) => {
2731-
let mut auto_vec = $crate::AutoThinVec::<$ty, $cap>::new_unpinned();
2732+
let auto_vec = $crate::AutoThinVec::<$ty, $cap>::new_unpinned();
27322733
let mut $name = core::pin::pin!(auto_vec);
27332734
unsafe { $name.as_mut().shrink_to_fit_known_singleton() };
27342735
};
@@ -4355,6 +4356,38 @@ mod std_tests {
43554356
}
43564357
*/
43574358

4359+
#[cfg(all(feature = "gecko-ffi"))]
4360+
#[test]
4361+
fn auto_t_array_basic() {
4362+
crate::auto_thin_vec!(let t: [u8; 10]);
4363+
assert_eq!(t.capacity(), 10);
4364+
assert!(!t.has_allocation());
4365+
{
4366+
let inner = unsafe { &mut *t.as_mut().as_mut_ptr() };
4367+
for i in 0..30 {
4368+
inner.push(i as u8);
4369+
}
4370+
}
4371+
4372+
assert_eq!(t.len(), 30);
4373+
assert!(t.has_allocation());
4374+
assert_eq!(t[5], 5);
4375+
assert_eq!(t[29], 29);
4376+
assert!(t.capacity() >= 30);
4377+
4378+
{
4379+
let inner = unsafe { &mut *t.as_mut().as_mut_ptr() };
4380+
inner.truncate(5);
4381+
}
4382+
4383+
assert_eq!(t.len(), 5);
4384+
assert!(t.capacity() >= 30);
4385+
assert!(t.has_allocation());
4386+
t.as_mut().shrink_to_fit();
4387+
assert!(!t.has_allocation());
4388+
assert_eq!(t.capacity(), 10);
4389+
}
4390+
43584391
#[test]
43594392
#[cfg_attr(feature = "gecko-ffi", ignore)]
43604393
fn test_header_data() {

0 commit comments

Comments
 (0)