Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: compilation errors with --no-default-features #59

Merged
merged 12 commits into from
Apr 11, 2022
19 changes: 19 additions & 0 deletions .github/workflows/tests.yml
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,25 @@ env:

name: Tests
jobs:
build_no_std:
name: Check no_std
strategy:
matrix:
feature: [alloc, static]
runs-on: ubuntu-latest
steps:
- uses: actions/checkout@v2
- name: Install toolchain
uses: actions-rs/toolchain@v1
with:
profile: minimal
toolchain: stable
override: true
components: rustfmt
- uses: actions-rs/cargo@v1
with:
command: check
args: --no-default-features --features ${{ matrix.feature }}

tests:
name: Tests
Expand Down
4 changes: 2 additions & 2 deletions src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,7 @@ impl Core {

fn close(&self) -> bool {
test_println!("Core::close");
if std::thread::panicking() {
if crate::util::panic::panicking() {
return false;
}
test_dbg!(self.tail.fetch_or(self.closed, SeqCst) & self.closed == 0)
Expand Down Expand Up @@ -516,7 +516,7 @@ unsafe impl<T: Send> Sync for Ref<'_, T> {}

impl<T> Slot<T> {
#[cfg(feature = "alloc")]
pub(crate) fn make_boxed_array(capacity: usize) -> Box<[Self]> {
pub(crate) fn make_boxed_array(capacity: usize) -> alloc::boxed::Box<[Self]> {
(0..capacity).map(|i| Slot::new(i)).collect()
}

Expand Down
76 changes: 39 additions & 37 deletions src/macros.rs
Original file line number Diff line number Diff line change
@@ -1,19 +1,18 @@
macro_rules! test_println {
($($arg:tt)*) => {
if cfg!(test) || cfg!(all(thingbuf_trace, feature = "std")) {
if crate::util::panic::panicking() {
// getting the thread ID while panicking doesn't seem to play super nicely with loom's
// mock lazy_static...
println!("[PANIC {:>30}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
} else {
crate::loom::traceln(format_args!(
"[{:?} {:>30}:{:<3}] {}",
crate::loom::thread::current().id(),
file!(),
line!(),
format_args!($($arg)*),
));
}
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
if crate::util::panic::panicking() {
// getting the thread ID while panicking doesn't seem to play super nicely with loom's
// mock lazy_static...
println!("[PANIC {:>30}:{:<3}] {}", file!(), line!(), format_args!($($arg)*))
} else {
crate::loom::traceln(format_args!(
"[{:?} {:>30}:{:<3}] {}",
crate::loom::thread::current().id(),
file!(),
line!(),
format_args!($($arg)*),
));
}
}
}
Expand All @@ -22,7 +21,7 @@ macro_rules! test_dbg {
($e:expr) => {
match $e {
e => {
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("{} = {:?}", stringify!($e), &e);
e
}
Expand All @@ -40,7 +39,7 @@ macro_rules! assert_dbg {
};
(@$e:expr, $($msg:tt)+) => {
{
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("ASSERT: {}{}", stringify!($e), format_args!($($msg)*));
assert!($e, $($msg)*);
test_println!("-> ok");
Expand All @@ -58,7 +57,7 @@ macro_rules! assert_eq_dbg {
};
(@ $a:expr, $b:expr, $($msg:tt)+) => {
{
#[cfg(any(test, all(thingbuf_trace, feature = "std")))]
#[cfg(all(feature = "std", any(thingbuf_trace, test)))]
test_println!("ASSERT: {} == {}{}", stringify!($a), stringify!($b), format_args!($($msg)*));
assert_eq!($a, $b, $($msg)*);
test_println!("-> ok");
Expand Down Expand Up @@ -96,29 +95,32 @@ macro_rules! fmt_bits {

#[allow(unused_macros)]
macro_rules! unreachable_unchecked {
($($arg:tt)+) => {
crate::unreachable_unchecked!(@inner , format_args!(": {}", format_args!($($arg)*)))
(@inner $msg:expr) => {
{
#[cfg(debug_assertions)] {
panic!(
"internal error: entered unreachable code{}\n\n\
/!\\ EXTREMELY SERIOUS WARNING /!\\\n
This code should NEVER be entered; in release mode, this would \
have been an `unreachable_unchecked` hint. The fact that this \
occurred means something VERY bad is going on. \n\
Please contact the `thingbuf` maintainers immediately. Sorry!",
$msg,
);
}
#[cfg(not(debug_assertions))]
unsafe {
core::hint::unreachable_unchecked();
}

}
};

() => {
crate::unreachable_unchecked!(@inner ".")
($($arg:tt)+) => {
unreachable_unchecked!(@inner format_args!(": {}", format_args!($($arg)*)))
};

(@inner $msg:expr) => {
#[cfg(debug_assertions)] {
panic!(
"internal error: entered unreachable code{}\n\n\
/!\\ EXTREMELY SERIOUS WARNING /!\\\n
This code should NEVER be entered; in release mode, this would \
have been an `unreachable_unchecked` hint. The fact that this \
occurred means something VERY bad is going on. \n\
Please contact the `thingbuf` maintainers immediately. Sorry!",
$msg,
);
}
#[cfg(not(debug_assertions))]
unsafe {
core::hint::unreachable_unchecked();
}
() => {
unreachable_unchecked!(@inner ".")
};
}
1 change: 1 addition & 0 deletions src/mpsc/async_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ feature! {
#![feature = "alloc"]

use crate::loom::sync::Arc;
use alloc::boxed::Box;

/// Returns a new asynchronous multi-producer, single consumer (MPSC)
/// channel with the provided capacity.
Expand Down
1 change: 1 addition & 0 deletions src/util/mutex/spin_impl.rs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ pub(crate) const fn const_mutex<T>(data: T) -> Mutex<T> {
}

impl<T> Mutex<T> {
#[cfg(loom)]
pub(crate) fn new(data: T) -> Self {
Self {
locked: AtomicBool::new(false),
Expand Down
2 changes: 1 addition & 1 deletion src/util/panic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ mod inner {
Ok(f())
}

pub(crate) fn resume_unwind(payload: ()) -> ! {
pub(crate) fn resume_unwind(_: ()) -> ! {
unreachable_unchecked!("code compiled with no_std cannot unwind!")
}
}