Always set #![no_std] and remove redundant imports

```
error: the item `Box` is imported redundantly
  --> futures-core/src/future.rs:89:9
   |
89 |     use alloc::boxed::Box;
   |         ^^^^^^^^^^^^^^^^^
  --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:115: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
   --> futures-core/src/stream.rs:203:9
    |
203 |     use alloc::boxed::Box;
    |         ^^^^^^^^^^^^^^^^^
   --> /rustc/381d69953bb7c3390cec0fee200f24529cb6320f/library/std/src/prelude/mod.rs:115:13
    |
    = note: the item `Box` is already defined here
```
This commit is contained in:
Taiki Endo
2024-02-25 17:45:38 +09:00
parent 021241badc
commit 79785ec41d
31 changed files with 78 additions and 33 deletions

View File

@@ -11,8 +11,7 @@
//! All items are only available when the `std` or `alloc` feature of this
//! library is activated, and it is activated by default.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -20,11 +19,14 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![allow(clippy::arc_with_non_send_sync)] // false positive https://github.com/rust-lang/rust-clippy/issues/11076
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
#[cfg_attr(target_os = "none", cfg(target_has_atomic = "ptr"))]
#[cfg(feature = "alloc")]

View File

@@ -43,6 +43,7 @@
pub(super) use self::PopResult::*;
use std::boxed::Box;
use std::cell::UnsafeCell;
use std::ptr;
use std::sync::atomic::{AtomicPtr, Ordering};

View File

@@ -1,7 +1,6 @@
//! Core traits and types for asynchronous operations in Rust.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -9,9 +8,12 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
pub mod future;
#[doc(no_inline)]

View File

@@ -1,7 +1,7 @@
use std::cell::Cell;
use std::fmt;
thread_local!(static ENTERED: Cell<bool> = Cell::new(false));
std::thread_local!(static ENTERED: Cell<bool> = Cell::new(false));
/// Represents an executor context.
///

View File

@@ -36,8 +36,7 @@
//! [`spawn_obj`]: https://docs.rs/futures/0.3/futures/task/trait.Spawn.html#tymethod.spawn_obj
//! [`spawn_local_obj`]: https://docs.rs/futures/0.3/futures/task/trait.LocalSpawn.html#tymethod.spawn_local_obj
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -45,9 +44,13 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::thread_local_initializer_can_be_made_const)] // clippy bug: this lint doesn't consider MSRV
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
mod local_pool;
#[cfg(feature = "std")]

View File

@@ -15,6 +15,7 @@ use std::sync::{
Arc,
};
use std::thread::{self, Thread};
use std::vec::Vec;
/// A single-threaded task pool for polling futures to completion.
///
@@ -53,7 +54,7 @@ pub(crate) struct ThreadNotify {
unparked: AtomicBool,
}
thread_local! {
std::thread_local! {
static CURRENT_THREAD_NOTIFY: Arc<ThreadNotify> = Arc::new(ThreadNotify {
thread: thread::current(),
unparked: AtomicBool::new(false),

View File

@@ -5,9 +5,12 @@ use futures_core::task::{Context, Poll};
use futures_task::{waker_ref, ArcWake};
use futures_task::{FutureObj, Spawn, SpawnError};
use futures_util::future::FutureExt;
use std::boxed::Box;
use std::cmp;
use std::fmt;
use std::format;
use std::io;
use std::string::String;
use std::sync::atomic::{AtomicUsize, Ordering};
use std::sync::mpsc;
use std::sync::{Arc, Mutex};
@@ -358,7 +361,6 @@ impl ArcWake for WakeHandle {
#[cfg(test)]
mod tests {
use super::*;
use std::sync::mpsc;
#[test]
fn test_drop_after_start() {

View File

@@ -8,8 +8,7 @@
//! All items of this library are only available when the `std` feature of this
//! library is activated, and it is activated by default.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -17,14 +16,20 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(feature = "std")]
extern crate std;
#[cfg(feature = "std")]
mod if_std {
use std::boxed::Box;
use std::io;
use std::ops::DerefMut;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::vec::Vec;
// Re-export some types from `std::io` so that users don't have to deal
// with conflicts when `use`ing `futures::io` and `std::io`.

View File

@@ -3,8 +3,7 @@
//! This crate contains the `Sink` trait which allows values to be sent
//! asynchronously.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -12,9 +11,12 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, /* unsafe_op_in_unsafe_fn */)] // unsafe_op_in_unsafe_fn requires Rust 1.52
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
use core::ops::DerefMut;
use core::pin::Pin;

View File

@@ -1,7 +1,6 @@
//! Tools for working with tasks.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -9,9 +8,12 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
mod spawn;
pub use crate::spawn::{LocalSpawn, Spawn, SpawnError};

View File

@@ -1,6 +1,5 @@
//! Utilities to make testing [`Future`s](futures_core::future::Future) easier
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![doc(test(
no_crate_inject,
attr(
@@ -8,6 +7,7 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![allow(clippy::test_attr_in_doctest)]
#[cfg(not(feature = "std"))]

View File

@@ -25,7 +25,7 @@ fn gen_index(n: usize) -> usize {
///
/// [xorshift*]: https://en.wikipedia.org/wiki/Xorshift#xorshift*
fn random() -> u64 {
thread_local! {
std::thread_local! {
static RNG: Cell<Wrapping<u64>> = Cell::new(Wrapping(prng_seed()));
}

View File

@@ -8,6 +8,7 @@ use futures_01::{AsyncSink as AsyncSink01, Sink as Sink01};
use futures_core::{future::Future as Future03, stream::Stream as Stream03, task as task03};
#[cfg(feature = "sink")]
use futures_sink::Sink as Sink03;
use std::boxed::Box;
use std::pin::Pin;
use std::task::Context;

View File

@@ -201,8 +201,6 @@ where
mod if_std {
use super::*;
use core::pin::Pin;
use core::task::{Context, Poll};
use futures_io::{
AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, Result, SeekFrom,
};

View File

@@ -1,5 +1,6 @@
use core::any::Any;
use core::pin::Pin;
use std::boxed::Box;
use std::panic::{catch_unwind, AssertUnwindSafe, UnwindSafe};
use futures_core::future::Future;

View File

@@ -9,6 +9,7 @@ use {
pin_project_lite::pin_project,
std::{
any::Any,
boxed::Box,
fmt,
panic::{self, AssertUnwindSafe},
pin::Pin,

View File

@@ -1,6 +1,8 @@
use futures_core::task::{Context, Poll};
use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, SeekFrom};
use std::pin::Pin;
use std::string::String;
use std::vec::Vec;
use std::{fmt, io};
/// A simple wrapper type which allows types which implement only

View File

@@ -4,8 +4,10 @@ use futures_core::ready;
use futures_core::task::{Context, Poll};
use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSliceMut, SeekFrom};
use pin_project_lite::pin_project;
use std::boxed::Box;
use std::io::{self, Read};
use std::pin::Pin;
use std::vec;
use std::{cmp, fmt};
pin_project! {

View File

@@ -7,6 +7,7 @@ use std::fmt;
use std::io::{self, Write};
use std::pin::Pin;
use std::ptr;
use std::vec::Vec;
pin_project! {
/// Wraps a writer and buffers its output.

View File

@@ -1,7 +1,9 @@
use futures_core::task::{Context, Poll};
use futures_io::{AsyncBufRead, AsyncRead, AsyncSeek, AsyncWrite, IoSlice, IoSliceMut, SeekFrom};
use std::boxed::Box;
use std::io;
use std::pin::Pin;
use std::vec::Vec;
/// A `Cursor` wraps an in-memory buffer and provides it with a
/// [`AsyncSeek`] implementation.

View File

@@ -7,6 +7,8 @@ use pin_project_lite::pin_project;
use std::io;
use std::mem;
use std::pin::Pin;
use std::string::String;
use std::vec::Vec;
pin_project! {
/// Stream for the [`lines`](super::AsyncBufReadExt::lines) method.

View File

@@ -21,7 +21,7 @@
use crate::compat::Compat;
use crate::future::assert_future;
use crate::stream::assert_stream;
use std::{pin::Pin, ptr};
use std::{pin::Pin, ptr, string::String, vec::Vec};
// Re-export some types from `std::io` so that users don't have to deal
// with conflicts when `use`ing `futures::io` and `std::io`.

View File

@@ -7,6 +7,8 @@ use std::io;
use std::mem;
use std::pin::Pin;
use std::str;
use std::string::String;
use std::vec::Vec;
/// Future for the [`read_line`](super::AsyncBufReadExt::read_line) method.
#[derive(Debug)]

View File

@@ -4,6 +4,7 @@ use futures_core::ready;
use futures_core::task::{Context, Poll};
use futures_io::AsyncRead;
use std::pin::Pin;
use std::string::String;
use std::vec::Vec;
use std::{io, mem, str};

View File

@@ -5,6 +5,7 @@ use futures_io::AsyncBufRead;
use std::io;
use std::mem;
use std::pin::Pin;
use std::vec::Vec;
/// Future for the [`read_until`](super::AsyncBufReadExt::read_until) method.
#[derive(Debug)]

View File

@@ -49,6 +49,8 @@ mod tests {
use std::io;
use std::pin::Pin;
use std::task::{Context, Poll};
use std::vec;
use std::vec::Vec;
use crate::io::{AsyncWrite, AsyncWriteExt, IoSlice};
use crate::task::noop_waker;

View File

@@ -1,9 +1,7 @@
//! Combinators and utilities for working with `Future`s, `Stream`s, `Sink`s,
//! and the `AsyncRead` and `AsyncWrite` traits.
#![cfg_attr(feature = "write-all-vectored", feature(io_slice_advance))]
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -11,6 +9,8 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(feature = "write-all-vectored", feature(io_slice_advance))]
#![cfg_attr(docsrs, feature(doc_cfg))]
#![allow(clippy::needless_borrow)] // https://github.com/rust-lang/futures-rs/pull/2558#issuecomment-1030745203
#![allow(clippy::arc_with_non_send_sync)] // false positive https://github.com/rust-lang/rust-clippy/issues/11076
@@ -20,6 +20,8 @@ compile_error!("The `bilock` feature requires the `unstable` feature as an expli
#[cfg(feature = "alloc")]
extern crate alloc;
#[cfg(feature = "std")]
extern crate std;
// Macro re-exports
pub use futures_core::ready;

View File

@@ -544,11 +544,17 @@ unsafe impl<T: ?Sized + Sync> Sync for OwnedMutexGuard<T> {}
unsafe impl<T: ?Sized + Send, U: ?Sized + Send> Send for MappedMutexGuard<'_, T, U> {}
unsafe impl<T: ?Sized + Sync, U: ?Sized + Sync> Sync for MappedMutexGuard<'_, T, U> {}
#[test]
fn test_mutex_guard_debug_not_recurse() {
#[cfg(test)]
mod tests {
use super::*;
use std::format;
#[test]
fn test_mutex_guard_debug_not_recurse() {
let mutex = Mutex::new(42);
let guard = mutex.try_lock().unwrap();
let _ = format!("{:?}", guard);
let guard = MutexGuard::map(guard, |n| n);
let _ = format!("{:?}", guard);
}
}

View File

@@ -2,6 +2,7 @@ use futures_core::stream::{FusedStream, Stream};
use futures_core::task::{Context, Poll};
use pin_project_lite::pin_project;
use std::any::Any;
use std::boxed::Box;
use std::panic::{catch_unwind, AssertUnwindSafe, UnwindSafe};
use std::pin::Pin;

View File

@@ -160,7 +160,7 @@ impl<T: core::any::Any, Item> std::error::Error for ReuniteError<T, Item> {}
#[cfg(test)]
mod tests {
use super::*;
use crate::{sink::Sink, stream::StreamExt};
use crate::stream::StreamExt;
use core::marker::PhantomData;
struct NopStream<Item> {

View File

@@ -81,8 +81,7 @@
//! The majority of examples and code snippets in this crate assume that they are
//! inside an async block as written above.
#![cfg_attr(not(feature = "std"), no_std)]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![no_std]
#![doc(test(
no_crate_inject,
attr(
@@ -90,6 +89,7 @@
allow(dead_code, unused_assignments, unused_variables)
)
))]
#![warn(missing_docs, unsafe_op_in_unsafe_fn)]
#![cfg_attr(docsrs, feature(doc_cfg))]
#[cfg(all(feature = "bilock", not(feature = "unstable")))]