Skip to content

Commit 7bb2f71

Browse files
committed
Use static_assertions instead of trybuild.
1 parent 6dbefb4 commit 7bb2f71

File tree

12 files changed

+77
-195
lines changed

12 files changed

+77
-195
lines changed

Cargo.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,7 @@ stable_deref_trait = { version = "1", default-features = false }
5252

5353
[dev-dependencies]
5454
ufmt = "0.2"
55+
static_assertions = "1.1.0"
5556

5657
[package.metadata.docs.rs]
5758
features = ["ufmt", "serde", "defmt-03", "mpmc_large", "portable-atomic-critical-section"]

cfail/ui/not-send.rs

Lines changed: 0 additions & 24 deletions
This file was deleted.

cfail/ui/not-send.stderr

Lines changed: 0 additions & 159 deletions
This file was deleted.

src/deque.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -745,7 +745,12 @@ where
745745

746746
#[cfg(test)]
747747
mod tests {
748-
use crate::Deque;
748+
use static_assertions::assert_not_impl_any;
749+
750+
use super::Deque;
751+
752+
// Ensure a `Deque` containing `!Send` values stays `!Send` itself.
753+
assert_not_impl_any!(Deque<*const (), 4>: Send);
749754

750755
#[test]
751756
fn static_new() {

src/histbuf.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -433,10 +433,16 @@ impl<'a, T, const N: usize> Iterator for OldestOrdered<'a, T, N> {
433433

434434
#[cfg(test)]
435435
mod tests {
436-
use crate::HistoryBuffer;
437436
use core::fmt::Debug;
438437
use core::sync::atomic::{AtomicUsize, Ordering};
439438

439+
use static_assertions::assert_not_impl_any;
440+
441+
use super::HistoryBuffer;
442+
443+
// Ensure a `HistoryBuffer` containing `!Send` values stays `!Send` itself.
444+
assert_not_impl_any!(HistoryBuffer<*const (), 4>: Send);
445+
440446
#[test]
441447
fn new() {
442448
let x: HistoryBuffer<u8, 4> = HistoryBuffer::new_with(1);

src/indexmap.rs

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1262,10 +1262,17 @@ where
12621262

12631263
#[cfg(test)]
12641264
mod tests {
1265-
use crate::{indexmap::Entry, FnvIndexMap};
1266-
12671265
use core::mem;
12681266

1267+
use static_assertions::assert_not_impl_any;
1268+
1269+
use super::{BuildHasherDefault, Entry, FnvIndexMap, IndexMap};
1270+
1271+
// Ensure a `IndexMap` containing `!Send` keys stays `!Send` itself.
1272+
assert_not_impl_any!(IndexMap<*const (), (), BuildHasherDefault<()>, 4>: Send);
1273+
// Ensure a `IndexMap` containing `!Send` values stays `!Send` itself.
1274+
assert_not_impl_any!(IndexMap<(), *const (), BuildHasherDefault<()>, 4>: Send);
1275+
12691276
#[test]
12701277
fn size() {
12711278
const CAP: usize = 4;

src/indexset.rs

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,13 @@
1-
use crate::indexmap::{self, IndexMap};
21
use core::{
32
borrow::Borrow,
43
fmt,
54
hash::{BuildHasher, Hash},
65
};
6+
77
use hash32::{BuildHasherDefault, FnvHasher};
88

9+
use crate::indexmap::{self, IndexMap};
10+
911
/// An [`IndexSet`] using the default FNV hasher.
1012
///
1113
/// A list of all Methods and Traits available for `FnvIndexSet` can be found in
@@ -659,3 +661,13 @@ where
659661
}
660662
}
661663
}
664+
665+
#[cfg(test)]
666+
mod tests {
667+
use static_assertions::assert_not_impl_any;
668+
669+
use super::{BuildHasherDefault, IndexSet};
670+
671+
// Ensure a `IndexSet` containing `!Send` values stays `!Send` itself.
672+
assert_not_impl_any!(IndexSet<*const (), BuildHasherDefault<()>, 4>: Send);
673+
}

src/linear_map.rs

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
use crate::Vec;
21
use core::{borrow::Borrow, fmt, mem, ops, slice};
32

3+
use crate::Vec;
4+
45
/// A fixed capacity map/dictionary that performs lookups via linear search.
56
///
67
/// Note that as this map doesn't use hashing so most operations are *O*(n) instead of *O*(1).
@@ -492,7 +493,14 @@ where
492493

493494
#[cfg(test)]
494495
mod test {
495-
use crate::LinearMap;
496+
use static_assertions::assert_not_impl_any;
497+
498+
use super::LinearMap;
499+
500+
// Ensure a `LinearMap` containing `!Send` keys stays `!Send` itself.
501+
assert_not_impl_any!(LinearMap<*const (), (), 4>: Send);
502+
// Ensure a `LinearMap` containing `!Send` values stays `!Send` itself.
503+
assert_not_impl_any!(LinearMap<(), *const (), 4>: Send);
496504

497505
#[test]
498506
fn static_new() {

src/mpmc.rs

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -294,7 +294,12 @@ unsafe fn enqueue<T>(
294294

295295
#[cfg(test)]
296296
mod tests {
297-
use super::Q2;
297+
use static_assertions::assert_not_impl_any;
298+
299+
use super::{MpMcQueue, Q2};
300+
301+
// Ensure a `MpMcQueue` containing `!Send` values stays `!Send` itself.
302+
assert_not_impl_any!(MpMcQueue<*const (), 4>: Send);
298303

299304
#[test]
300305
fn sanity() {

src/sorted_linked_list.rs

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -743,8 +743,13 @@ where
743743

744744
#[cfg(test)]
745745
mod tests {
746+
use static_assertions::assert_not_impl_any;
747+
746748
use super::*;
747749

750+
// Ensure a `SortedLinkedList` containing `!Send` values stays `!Send` itself.
751+
assert_not_impl_any!(SortedLinkedList<*const (), LinkedIndexU8, (), 4>: Send);
752+
748753
#[test]
749754
fn const_new() {
750755
static mut _V1: SortedLinkedList<u32, LinkedIndexU8, Max, 100> = SortedLinkedList::new_u8();

0 commit comments

Comments
 (0)