Skip to content

Commit

Permalink
Always set #![no_std] and remove redundant imports
Browse files Browse the repository at this point in the history
```
error: the item `Box` is imported redundantly
 --> crossbeam-epoch/src/atomic.rs:1:5
  |
1 | use alloc::boxed::Box;
  |     ^^^^^^^^^^^^^^^^^
 --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:125:13
  |
  = note: the item `Box` is already defined here
  |
  = note: `-D unused-imports` implied by `-D warnings`
  = help: to override `-D warnings` add `#[allow(unused_imports)]`

error: the item `Box` is imported redundantly
 --> crossbeam-epoch/src/deferred.rs:1:5
  |
1 | use alloc::boxed::Box;
  |     ^^^^^^^^^^^^^^^^^
 --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:125:13
  |
  = note: the item `Box` is already defined here
```
  • Loading branch information
taiki-e committed Feb 25, 2024
1 parent 2e7f9b1 commit 26b6078
Show file tree
Hide file tree
Showing 25 changed files with 50 additions and 15 deletions.
2 changes: 1 addition & 1 deletion crossbeam-channel/src/context.rs
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ impl Context {
where
F: FnOnce(&Self) -> R,
{
thread_local! {
std::thread_local! {
/// Cached thread-local context.
static CONTEXT: Cell<Option<Context>> = Cell::new(Some(Context::new()));
}
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/src/counter.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Reference counter for channels.

use std::boxed::Box;
use std::isize;
use std::ops;
use std::process;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/src/flavors/array.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
//! - <http://www.1024cores.net/home/lock-free-algorithms/queues/bounded-mpmc-queue>
//! - <https://docs.google.com/document/d/1yIAYmbvL3JxOKOjuCyon7JhW4cSv1wy5hC0ApeGMV9s/pub>

use std::boxed::Box;
use std::cell::UnsafeCell;
use std::mem::{self, MaybeUninit};
use std::ptr;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/src/flavors/list.rs
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
//! Unbounded channel implemented as a linked list.

use std::boxed::Box;
use std::cell::UnsafeCell;
use std::marker::PhantomData;
use std::mem::MaybeUninit;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/src/flavors/zero.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
//!
//! This kind of channel is also known as *rendezvous* channel.

use std::boxed::Box;
use std::cell::UnsafeCell;
use std::marker::PhantomData;
use std::sync::atomic::{AtomicBool, Ordering};
Expand Down
5 changes: 4 additions & 1 deletion crossbeam-channel/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,7 @@
//! [`iter`]: Receiver::iter
//! [`try_iter`]: Receiver::try_iter

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -333,7 +334,9 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
mod channel;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-channel/src/select.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::fmt;
use std::marker::PhantomData;
use std::mem;
use std::time::{Duration, Instant};
use std::vec::Vec;

use crossbeam_utils::Backoff;

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-channel/src/utils.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ pub(crate) fn shuffle<T>(v: &mut [T]) {
return;
}

thread_local! {
std::thread_local! {
static RNG: Cell<Wrapping<u32>> = const { Cell::new(Wrapping(1_406_868_647)) };
}

Expand Down
3 changes: 2 additions & 1 deletion crossbeam-channel/src/waker.rs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ use std::ptr;
use std::sync::atomic::{AtomicBool, Ordering};
use std::sync::Mutex;
use std::thread::{self, ThreadId};
use std::vec::Vec;

use crate::context::Context;
use crate::select::{Operation, Selected};
Expand Down Expand Up @@ -275,7 +276,7 @@ impl Drop for SyncWaker {
/// Returns the id of the current thread.
#[inline]
fn current_thread_id() -> ThreadId {
thread_local! {
std::thread_local! {
/// Cached thread-local id.
static THREAD_ID: ThreadId = thread::current().id();
}
Expand Down
3 changes: 1 addition & 2 deletions crossbeam-channel/tests/mpsc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ mod channel_tests {

use std::env;
use std::thread;
use std::time::{Duration, Instant};
use std::time::Instant;

fn stress_factor() -> usize {
match env::var("RUST_TEST_STRESS") {
Expand Down Expand Up @@ -969,7 +969,6 @@ mod sync_channel_tests {

use std::env;
use std::thread;
use std::time::Duration;

fn stress_factor() -> usize {
match env::var("RUST_TEST_STRESS") {
Expand Down
1 change: 1 addition & 0 deletions crossbeam-deque/src/deque.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::boxed::Box;
use std::cell::{Cell, UnsafeCell};
use std::cmp;
use std::fmt;
Expand Down
5 changes: 4 additions & 1 deletion crossbeam-deque/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -82,6 +82,7 @@
//! [`steal_batch()`]: Stealer::steal_batch
//! [`steal_batch_and_pop()`]: Stealer::steal_batch_and_pop

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -90,7 +91,9 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(feature = "std")]
mod deque;
Expand Down
1 change: 1 addition & 0 deletions crossbeam-epoch/src/collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ impl fmt::Debug for LocalHandle {
mod tests {
use std::mem::ManuallyDrop;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::vec::Vec;

use crossbeam_utils::thread;

Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/src/default.rs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ mod tests {
}
}

thread_local! {
std::thread_local! {
static FOO: Foo = const { Foo };
}

Expand Down
3 changes: 3 additions & 0 deletions crossbeam-epoch/src/deferred.rs
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,11 @@ impl Deferred {
#[cfg(all(test, not(crossbeam_loom)))]
mod tests {
use super::Deferred;
use std::boxed::Box;
use std::cell::Cell;
use std::convert::identity;
use std::string::ToString;
use std::vec;

#[test]
fn on_stack() {
Expand Down
2 changes: 1 addition & 1 deletion crossbeam-epoch/src/internal.rs
Original file line number Diff line number Diff line change
Expand Up @@ -558,7 +558,7 @@ impl IsElement<Self> for Local {

#[cfg(all(test, not(crossbeam_loom)))]
mod tests {
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::atomic::AtomicUsize;

use super::*;

Expand Down
4 changes: 3 additions & 1 deletion crossbeam-epoch/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
//! For majority of use cases, just use the default garbage collector by invoking [`pin`]. If you
//! want to create your own garbage collector, use the [`Collector`] API.

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -56,10 +57,11 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(crossbeam_loom)]
extern crate loom_crate as loom;
#[cfg(feature = "std")]
extern crate std;

#[cfg(crossbeam_loom)]
#[allow(unused_imports, dead_code)]
Expand Down
1 change: 1 addition & 0 deletions crossbeam-epoch/src/sync/list.rs
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ mod tests {
use crate::{Collector, Owned};
use crossbeam_utils::thread;
use std::sync::Barrier;
use std::vec::Vec;

impl IsElement<Self> for Entry {
fn entry_of(entry: &Self) -> &Entry {
Expand Down
1 change: 1 addition & 0 deletions crossbeam-epoch/src/sync/queue.rs
Original file line number Diff line number Diff line change
Expand Up @@ -219,6 +219,7 @@ mod test {
use super::*;
use crate::pin;
use crossbeam_utils::thread;
use std::vec;

struct Queue<T> {
queue: super::Queue<T>,
Expand Down
4 changes: 3 additions & 1 deletion crossbeam-queue/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
//! * [`ArrayQueue`], a bounded MPMC queue that allocates a fixed-capacity buffer on construction.
//! * [`SegQueue`], an unbounded MPMC queue that allocates small buffers, segments, on demand.

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -13,10 +14,11 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
mod array_queue;
Expand Down
4 changes: 3 additions & 1 deletion crossbeam-skiplist/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,7 @@
//! }
//! ```

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -236,10 +237,11 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;

#[cfg(all(feature = "alloc", target_has_atomic = "ptr"))]
pub mod base;
Expand Down
5 changes: 4 additions & 1 deletion crossbeam-utils/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
//! [`WaitGroup`]: sync::WaitGroup
//! [`scope`]: thread::scope

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -32,7 +33,9 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate std;

#[cfg(crossbeam_loom)]
#[allow(unused_imports)]
Expand Down
4 changes: 3 additions & 1 deletion crossbeam-utils/src/sync/sharded_lock.rs
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
use std::boxed::Box;
use std::cell::UnsafeCell;
use std::collections::HashMap;
use std::fmt;
Expand All @@ -8,6 +9,7 @@ use std::panic::{RefUnwindSafe, UnwindSafe};
use std::sync::{LockResult, PoisonError, TryLockError, TryLockResult};
use std::sync::{Mutex, RwLock, RwLockReadGuard, RwLockWriteGuard};
use std::thread::{self, ThreadId};
use std::vec::Vec;

use crate::sync::once_lock::OnceLock;
use crate::CachePadded;
Expand Down Expand Up @@ -613,7 +615,7 @@ impl Drop for Registration {
}
}

thread_local! {
std::thread_local! {
static REGISTRATION: Registration = {
let thread_id = thread::current().id();
let mut indices = thread_indices().lock().unwrap();
Expand Down
3 changes: 3 additions & 0 deletions crossbeam-utils/src/thread.rs
Original file line number Diff line number Diff line change
Expand Up @@ -111,13 +111,16 @@
//! }).unwrap();
//! ```

use std::boxed::Box;
use std::fmt;
use std::io;
use std::marker::PhantomData;
use std::mem;
use std::panic;
use std::string::String;
use std::sync::{Arc, Mutex};
use std::thread;
use std::vec::Vec;

use crate::sync::WaitGroup;

Expand Down
5 changes: 4 additions & 1 deletion src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
//! [`Backoff`]: utils::Backoff
//! [`CachePadded`]: utils::CachePadded

#![no_std]
#![doc(test(
no_crate_inject,
attr(
Expand All @@ -46,7 +47,9 @@
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(not(feature = "std"), no_std)]

#[cfg(feature = "std")]
extern crate std;

pub use crossbeam_utils::atomic;

Expand Down

0 comments on commit 26b6078

Please sign in to comment.