Skip to content

Commit

Permalink
Removed compile tests in favor of static assertions.
Browse files Browse the repository at this point in the history
  • Loading branch information
orium committed Aug 13, 2024
1 parent 7ab5369 commit 17d4a00
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 120 deletions.
11 changes: 5 additions & 6 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ version = "1.2.1-pre"
authors = ["Diogo Sousa <[email protected]>"]

edition = "2021"
rust-version = "1.60.0"
rust-version = "1.66.0"

homepage = "https://github.com/orium/archery"
repository = "https://github.com/orium/archery"
Expand Down Expand Up @@ -45,20 +45,19 @@ triomphe = { version = "0.1.13", optional = true, default-features = false }
serde = { version = "1.0.204", optional = true, default-features = false }

[dev-dependencies]
bincode = "1.3.3"
criterion = { version = "0.5.1", features = ["html_reports"] }
pretty_assertions = "1.4.0"
compiletest_rs = "0.11.0"
bincode = "1.3.3"

[features]
fatal-warnings = []
triomphe = ["dep:triomphe"]
serde = ["dep:serde"]

[lints.clippy]
all = { level = "warn", priority = -1 }
pedantic = { level = "warn", priority = -1 }
correctness = "deny"
all = { level = "warn", priority = -2 }
pedantic = { level = "warn", priority = -2 }
correctness = { level = "deny", priority = -1 }

explicit-deref-methods = "allow"
if-not-else = "allow"
Expand Down
2 changes: 1 addition & 1 deletion src/shared_pointer/kind/arc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ArcK {
impl ArcK {
#[inline(always)]
fn new_from_inner<T>(arc: Arc<T>) -> ArcK {
ArcK { inner: ManuallyDrop::new(unsafe { mem::transmute(arc) }) }
ArcK { inner: ManuallyDrop::new(unsafe { mem::transmute::<Arc<T>, UntypedArc>(arc) }) }
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/shared_pointer/kind/arct/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct ArcTK {
impl ArcTK {
#[inline(always)]
fn new_from_inner<T>(arc: Arc<T>) -> ArcTK {
ArcTK { inner: ManuallyDrop::new(unsafe { mem::transmute(arc) }) }
ArcTK { inner: ManuallyDrop::new(unsafe { mem::transmute::<Arc<T>, UntypedArc>(arc) }) }
}

#[inline(always)]
Expand Down
2 changes: 1 addition & 1 deletion src/shared_pointer/kind/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ use core::fmt::Debug;
/// - `&mut T` is only exposed through the trait methods returning `&mut T`.
///
/// - The implementor must not move out the contained `T` unless the semantics
/// of trait methods demands that.
/// of trait methods demands that.
///
/// - [`Self::drop`] drops `T` in place.
///
Expand Down
2 changes: 1 addition & 1 deletion src/shared_pointer/kind/rc/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ pub struct RcK {
impl RcK {
#[inline(always)]
fn new_from_inner<T>(rc: Rc<T>) -> RcK {
RcK { inner: ManuallyDrop::new(unsafe { mem::transmute(rc) }) }
RcK { inner: ManuallyDrop::new(unsafe { mem::transmute::<Rc<T>, UntypedRc>(rc) }) }
}

#[inline(always)]
Expand Down
46 changes: 46 additions & 0 deletions src/shared_pointer/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,52 @@ use std::string::ToString;

assert_impl_all!(SharedPointer<i32, ArcK>: Send, Sync);

mod static_check_rc_is_not_send_nor_sync {
use crate::{RcK, SharedPointer};
use static_assertions::*;

assert_impl_all!(i32: Send, Sync);

assert_not_impl_any!(SharedPointer<i32, RcK>: Send);
assert_not_impl_any!(SharedPointer<i32, RcK>: Sync);
}

mod static_check_arc_of_non_send_is_not_send_nor_sync {
use crate::{ArcK, SharedPointer};
use static_assertions::*;
use std::sync::MutexGuard;

assert_not_impl_any!(MutexGuard<'static, ()>: Send);
assert_impl_all!(MutexGuard<'static, ()>: Sync);

assert_not_impl_any!(SharedPointer<MutexGuard<'static, ()>, ArcK>: Send);
assert_not_impl_any!(SharedPointer<MutexGuard<'static, ()>, ArcK>: Sync);
}

mod static_check_arc_of_non_sync_is_not_send_nor_sync {
use crate::{ArcK, SharedPointer};
use static_assertions::*;
use std::cell::Cell;

assert_impl_all!(Cell<()>: Send);
assert_not_impl_any!(Cell<()>: Sync);

assert_not_impl_any!(SharedPointer<Cell<()>, ArcK>: Send);
assert_not_impl_any!(SharedPointer<Cell<()>, ArcK>: Sync);
}

mod static_check_arc_of_non_send_nor_sync_is_not_send_nor_sync {
use crate::{ArcK, SharedPointer};
use alloc::rc::Rc;
use static_assertions::*;

assert_not_impl_any!(Rc<i32>: Send);
assert_not_impl_any!(Rc<i32>: Sync);

assert_not_impl_any!(SharedPointer<Rc<i32>, ArcK>: Send);
assert_not_impl_any!(SharedPointer<Rc<i32>, ArcK>: Sync);
}

#[test]
fn test_as_ptr() {
let x = SharedPointer::<&'static str, RcK>::new("hello");
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

12 changes: 0 additions & 12 deletions tests/compile-fail/shared_pointer_rc_is_not_send_nor_sync.rs

This file was deleted.

63 changes: 0 additions & 63 deletions tests/tests.rs

This file was deleted.

0 comments on commit 17d4a00

Please sign in to comment.