diff --git a/tracing-core/src/callsite.rs b/tracing-core/src/callsite.rs index 5e48473e15..7991dde640 100644 --- a/tracing-core/src/callsite.rs +++ b/tracing-core/src/callsite.rs @@ -1,11 +1,11 @@ //! Callsites represent the source locations from which spans or events //! originate. -use crate::stdlib::{ +use core::{ fmt, hash::{Hash, Hasher}, - sync::Mutex, - vec::Vec, }; +use alloc::vec::Vec; +use crate::sync::Mutex; use crate::{ dispatcher::{self, Dispatch}, metadata::{LevelFilter, Metadata}, diff --git a/tracing-core/src/dispatcher.rs b/tracing-core/src/dispatcher.rs index 658463584e..ad9e8676f9 100644 --- a/tracing-core/src/dispatcher.rs +++ b/tracing-core/src/dispatcher.rs @@ -138,17 +138,17 @@ use crate::{ Event, LevelFilter, Metadata, }; -use crate::stdlib::{ +use core::{ any::Any, fmt, sync::{ atomic::{AtomicBool, AtomicUsize, Ordering}, - Arc, Weak, }, }; +use alloc::sync::{Arc, Weak}; #[cfg(feature = "std")] -use crate::stdlib::{ +use std::{ cell::{Cell, RefCell, RefMut}, error, }; @@ -784,8 +784,6 @@ impl Drop for DefaultGuard { #[cfg(test)] mod test { use super::*; - #[cfg(feature = "std")] - use crate::stdlib::sync::atomic::{AtomicUsize, Ordering}; use crate::{ callsite::Callsite, metadata::{Kind, Level, Metadata}, diff --git a/tracing-core/src/field.rs b/tracing-core/src/field.rs index 1cda8d9cb8..fa54897148 100644 --- a/tracing-core/src/field.rs +++ b/tracing-core/src/field.rs @@ -39,7 +39,7 @@ //! [`Value::record`]: trait.Value.html#method.record //! [`Visit`]: trait.Visit.html use crate::callsite; -use crate::stdlib::{ +use core::{ borrow::Borrow, fmt, hash::{Hash, Hasher}, @@ -833,7 +833,7 @@ impl_valid_len! { mod test { use super::*; use crate::metadata::{Kind, Level, Metadata}; - use crate::stdlib::{borrow::ToOwned, string::String}; + use alloc::{borrow::ToOwned, string::String}; struct TestCallsite1; static TEST_CALLSITE_1: TestCallsite1 = TestCallsite1; @@ -934,7 +934,7 @@ mod test { struct MyVisitor; impl Visit for MyVisitor { - fn record_debug(&mut self, field: &Field, _: &dyn (crate::stdlib::fmt::Debug)) { + fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) { assert_eq!(field.callsite(), TEST_META_1.callsite()) } } @@ -953,7 +953,7 @@ mod test { struct MyVisitor; impl Visit for MyVisitor { - fn record_debug(&mut self, field: &Field, _: &dyn (crate::stdlib::fmt::Debug)) { + fn record_debug(&mut self, field: &Field, _: &dyn (core::fmt::Debug)) { assert_eq!(field.name(), "bar") } } @@ -972,7 +972,7 @@ mod test { let valueset = fields.value_set(values); let mut result = String::new(); valueset.record(&mut |_: &Field, value: &dyn fmt::Debug| { - use crate::stdlib::fmt::Write; + use core::fmt::Write; write!(&mut result, "{:?}", value).unwrap(); }); assert_eq!(result, "123".to_owned()); diff --git a/tracing-core/src/lib.rs b/tracing-core/src/lib.rs index 8c257e864e..ee3043c4b3 100644 --- a/tracing-core/src/lib.rs +++ b/tracing-core/src/lib.rs @@ -114,7 +114,7 @@ unused_parens, while_true )] -#[cfg(not(feature = "std"))] + extern crate alloc; /// Statically constructs an [`Identifier`] for the provided [`Callsite`]. @@ -240,17 +240,27 @@ extern crate lazy_static; #[macro_use] mod lazy_static; -// Trimmed-down vendored version of spin 0.5.2 (0387621) -// Dependency of no_std lazy_static, not required in a std build +// Facade module: `no_std` uses spinlocks, `std` uses the mutexes in the standard library #[cfg(not(feature = "std"))] -pub(crate) mod spin; +mod sync { + #[doc(hidden)] + pub type Once = crate::spin::Once<()>; + pub(crate) use crate::spin::*; +} #[cfg(not(feature = "std"))] -#[doc(hidden)] -pub type Once = self::spin::Once<()>; +// Trimmed-down vendored version of spin 0.5.2 (0387621) +// Dependency of no_std lazy_static, not required in a std build +pub(crate) mod spin; #[cfg(feature = "std")] -pub use stdlib::sync::Once; +mod sync { + pub use std::sync::Once; + pub(crate) use std::sync::Mutex; +} + +#[doc(hidden)] +pub use self::sync::Once; pub mod callsite; pub mod dispatcher; @@ -259,7 +269,6 @@ pub mod field; pub mod metadata; mod parent; pub mod span; -pub(crate) mod stdlib; pub mod subscriber; #[doc(inline)] diff --git a/tracing-core/src/metadata.rs b/tracing-core/src/metadata.rs index 55fa2d64fd..91bfdc5796 100644 --- a/tracing-core/src/metadata.rs +++ b/tracing-core/src/metadata.rs @@ -1,6 +1,6 @@ //! Metadata describing trace data. use super::{callsite, field}; -use crate::stdlib::{ +use core::{ cmp, fmt, str::FromStr, sync::atomic::{AtomicUsize, Ordering}, @@ -299,7 +299,7 @@ impl fmt::Display for Level { #[cfg(feature = "std")] #[cfg_attr(docsrs, doc(cfg(feature = "std")))] -impl crate::stdlib::error::Error for ParseLevelError {} +impl std::error::Error for ParseLevelError {} impl FromStr for Level { type Err = ParseLevelError; @@ -481,7 +481,7 @@ impl LevelFilter { // the inputs to `set_max` to the set of valid discriminants. // Therefore, **as long as `MAX_VALUE` is only ever set by // `set_max`**, this is safe. - crate::stdlib::hint::unreachable_unchecked() + core::hint::unreachable_unchecked() }, } } @@ -799,7 +799,7 @@ impl PartialOrd for LevelFilter { #[cfg(test)] mod tests { use super::*; - use crate::stdlib::mem; + use core::mem; #[test] fn level_from_str() { diff --git a/tracing-core/src/span.rs b/tracing-core/src/span.rs index 27dda2475c..ab1eac4389 100644 --- a/tracing-core/src/span.rs +++ b/tracing-core/src/span.rs @@ -1,6 +1,6 @@ //! Spans represent periods of time in the execution of a program. use crate::parent::Parent; -use crate::stdlib::num::NonZeroU64; +use core::num::NonZeroU64; use crate::{field, Metadata}; /// Identifies a span within the context of a subscriber. diff --git a/tracing-core/src/spin/mutex.rs b/tracing-core/src/spin/mutex.rs index 383a2cd839..9b07322f32 100644 --- a/tracing-core/src/spin/mutex.rs +++ b/tracing-core/src/spin/mutex.rs @@ -49,12 +49,12 @@ impl Mutex { /// /// The returned value may be dereferenced for data access /// and the lock will be dropped when the guard falls out of scope. - pub(crate) fn lock(&self) -> MutexGuard<'_, T> { + pub(crate) fn lock(&self) -> Result, core::convert::Infallible> { self.obtain_lock(); - MutexGuard { + Ok(MutexGuard { lock: &self.lock, data: unsafe { &mut *self.data.get() }, - } + }) } /// Tries to lock the mutex. If it is already locked, it will return None. Otherwise it returns diff --git a/tracing-core/src/stdlib.rs b/tracing-core/src/stdlib.rs deleted file mode 100644 index 4a1c17c2b8..0000000000 --- a/tracing-core/src/stdlib.rs +++ /dev/null @@ -1,78 +0,0 @@ -//! Re-exports either the Rust `std` library or `core` and `alloc` when `std` is -//! disabled. -//! -//! `crate::stdlib::...` should be used rather than `std::` when adding code that -//! will be available with the standard library disabled. -//! -//! Note that this module is called `stdlib` rather than `std`, as Rust 1.34.0 -//! does not permit redefining the name `stdlib` (although this works on the -//! latest stable Rust). -#[cfg(feature = "std")] -pub(crate) use std::*; - -#[cfg(not(feature = "std"))] -pub(crate) use self::no_std::*; - -#[cfg(not(feature = "std"))] -mod no_std { - // We pre-emptively export everything from libcore/liballoc, (even modules - // we aren't using currently) to make adding new code easier. Therefore, - // some of these imports will be unused. - #![allow(unused_imports)] - - pub(crate) use core::{ - any, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, future, hash, - hint, i128, i16, i8, isize, iter, marker, mem, num, ops, option, pin, ptr, result, task, - time, u128, u16, u32, u8, usize, - }; - - pub(crate) use alloc::{boxed, collections, rc, string, vec}; - - pub(crate) mod borrow { - pub(crate) use alloc::borrow::*; - pub(crate) use core::borrow::*; - } - - pub(crate) mod fmt { - pub(crate) use alloc::fmt::*; - pub(crate) use core::fmt::*; - } - - pub(crate) mod slice { - pub(crate) use alloc::slice::*; - pub(crate) use core::slice::*; - } - - pub(crate) mod str { - pub(crate) use alloc::str::*; - pub(crate) use core::str::*; - } - - pub(crate) mod sync { - pub(crate) use crate::spin::MutexGuard; - pub(crate) use alloc::sync::*; - pub(crate) use core::sync::*; - - /// This wraps `spin::Mutex` to return a `Result`, so that it can be - /// used with code written against `std::sync::Mutex`. - /// - /// Since `spin::Mutex` doesn't support poisoning, the `Result` returned - /// by `lock` will always be `Ok`. - #[derive(Debug, Default)] - pub(crate) struct Mutex { - inner: crate::spin::Mutex, - } - - impl Mutex { - pub(crate) fn new(data: T) -> Self { - Self { - inner: crate::spin::Mutex::new(data), - } - } - - pub(crate) fn lock(&self) -> Result, ()> { - Ok(self.inner.lock()) - } - } - } -} diff --git a/tracing-core/src/subscriber.rs b/tracing-core/src/subscriber.rs index cc62ee8584..ffd3004fc4 100644 --- a/tracing-core/src/subscriber.rs +++ b/tracing-core/src/subscriber.rs @@ -1,7 +1,7 @@ //! Subscribers collect and record trace data. use crate::{span, Event, LevelFilter, Metadata}; -use crate::stdlib::any::{Any, TypeId}; +use core::any::{Any, TypeId}; /// Trait representing the functions required to collect trace data. /// diff --git a/tracing-futures/src/executor/futures_preview.rs b/tracing-futures/src/executor/futures_preview.rs index a9fdd6ef6a..ab9178035c 100644 --- a/tracing-futures/src/executor/futures_preview.rs +++ b/tracing-futures/src/executor/futures_preview.rs @@ -1,4 +1,4 @@ -use crate::stdlib::future::Future; +use core::future::Future; use crate::{Instrument, Instrumented, WithDispatch}; use futures_core_preview::{ future::FutureObj, diff --git a/tracing-futures/src/lib.rs b/tracing-futures/src/lib.rs index 1ec82cb3e1..f72cb4b0a3 100644 --- a/tracing-futures/src/lib.rs +++ b/tracing-futures/src/lib.rs @@ -105,10 +105,8 @@ #[cfg(feature = "std-future")] use pin_project::pin_project; -pub(crate) mod stdlib; - #[cfg(feature = "std-future")] -use crate::stdlib::{pin::Pin, task::Context}; +use core::{pin::Pin, task::Context}; #[cfg(feature = "std")] use tracing::{dispatcher, Dispatch}; @@ -274,10 +272,10 @@ impl Instrument for T {} #[cfg(feature = "std-future")] #[cfg_attr(docsrs, doc(cfg(feature = "std-future")))] -impl crate::stdlib::future::Future for Instrumented { +impl core::future::Future for Instrumented { type Output = T::Output; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> crate::stdlib::task::Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> core::task::Poll { let this = self.project(); let _enter = this.span.enter(); this.inner.poll(cx) @@ -445,10 +443,10 @@ impl futures_01::Future for WithDispatch { #[cfg(all(feature = "std-future", feature = "std"))] #[cfg_attr(docsrs, doc(cfg(all(feature = "std-future", feature = "std"))))] -impl crate::stdlib::future::Future for WithDispatch { +impl core::future::Future for WithDispatch { type Output = T::Output; - fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> crate::stdlib::task::Poll { + fn poll(self: Pin<&mut Self>, cx: &mut Context<'_>) -> core::task::Poll { let this = self.project(); let dispatch = this.dispatch; let future = this.inner; diff --git a/tracing-futures/src/stdlib.rs b/tracing-futures/src/stdlib.rs deleted file mode 100644 index 0cd6e7fdc5..0000000000 --- a/tracing-futures/src/stdlib.rs +++ /dev/null @@ -1,44 +0,0 @@ -//! Re-exports either the Rust `std` library or `core` and `alloc` when `std` is -//! disabled. -//! -//! `crate::stdlib::...` should be used rather than `std::` when adding code that -//! will be available with the standard library disabled. -//! -//! Note that this module is called `stdlib` rather than `std`, as Rust 1.34.0 -//! does not permit redefining the name `stdlib` (although this works on the -//! latest stable Rust). -#[cfg(feature = "std")] -pub(crate) use std::*; - -#[cfg(not(feature = "std"))] -pub(crate) use self::no_std::*; - -#[cfg(not(feature = "std"))] -mod no_std { - // We pre-emptively export everything from libcore/liballoc, (even modules - // we aren't using currently) to make adding new code easier. Therefore, - // some of these imports will be unused. - #![allow(unused_imports)] - - pub(crate) use core::{ - any, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, future, hash, - hint, i128, i16, i8, isize, iter, marker, mem, num, ops, option, pin, ptr, result, task, - time, u128, u16, u32, u8, usize, - }; - - pub(crate) mod borrow { - pub(crate) use core::borrow::*; - } - - pub(crate) mod fmt { - pub(crate) use core::fmt::*; - } - - pub(crate) mod slice { - pub(crate) use core::slice::*; - } - - pub(crate) mod str { - pub(crate) use core::str::*; - } -} diff --git a/tracing/src/instrument.rs b/tracing/src/instrument.rs index d1070ba8e2..9cdff1f540 100644 --- a/tracing/src/instrument.rs +++ b/tracing/src/instrument.rs @@ -1,6 +1,6 @@ -use crate::stdlib::pin::Pin; -use crate::stdlib::task::{Context, Poll}; -use crate::stdlib::{future::Future, marker::Sized}; +use core::pin::Pin; +use core::task::{Context, Poll}; +use core::{future::Future, marker::Sized}; use crate::{dispatcher, span::Span, Dispatch}; use pin_project_lite::pin_project; diff --git a/tracing/src/lib.rs b/tracing/src/lib.rs index a592e5de1b..c0814c3938 100644 --- a/tracing/src/lib.rs +++ b/tracing/src/lib.rs @@ -865,9 +865,6 @@ while_true )] -#[cfg(not(feature = "std"))] -extern crate alloc; - #[macro_use] extern crate cfg_if; @@ -911,13 +908,12 @@ pub mod field; pub mod instrument; pub mod level_filters; pub mod span; -pub(crate) mod stdlib; pub mod subscriber; #[doc(hidden)] pub mod __macro_support { pub use crate::callsite::Callsite; - use crate::stdlib::sync::atomic::{AtomicUsize, Ordering}; + use core::sync::atomic::{AtomicUsize, Ordering}; use crate::{subscriber::Interest, Metadata}; use tracing_core::Once; diff --git a/tracing/src/span.rs b/tracing/src/span.rs index 085ecdce73..bece5a6a36 100644 --- a/tracing/src/span.rs +++ b/tracing/src/span.rs @@ -315,7 +315,7 @@ //! [parent]: #span-relationships pub use tracing_core::span::{Attributes, Id, Record}; -use crate::stdlib::{ +use core::{ cmp, fmt, hash::{Hash, Hasher}, marker::PhantomData, diff --git a/tracing/src/stdlib.rs b/tracing/src/stdlib.rs deleted file mode 100644 index 12b54084d4..0000000000 --- a/tracing/src/stdlib.rs +++ /dev/null @@ -1,55 +0,0 @@ -//! Re-exports either the Rust `std` library or `core` and `alloc` when `std` is -//! disabled. -//! -//! `crate::stdlib::...` should be used rather than `std::` when adding code that -//! will be available with the standard library disabled. -//! -//! Note that this module is called `stdlib` rather than `std`, as Rust 1.34.0 -//! does not permit redefining the name `stdlib` (although this works on the -//! latest stable Rust). -#[cfg(feature = "std")] -pub(crate) use std::*; - -#[cfg(not(feature = "std"))] -pub(crate) use self::no_std::*; - -#[cfg(not(feature = "std"))] -mod no_std { - // We pre-emptively export everything from libcore/liballoc, (even modules - // we aren't using currently) to make adding new code easier. Therefore, - // some of these imports will be unused. - #![allow(unused_imports)] - - pub(crate) use core::{ - any, array, ascii, cell, char, clone, cmp, convert, default, f32, f64, ffi, future, hash, - hint, i128, i16, i8, isize, iter, marker, mem, num, ops, option, pin, ptr, result, task, - time, u128, u16, u32, u8, usize, - }; - - pub(crate) use alloc::{boxed, collections, rc, string, vec}; - - pub(crate) mod borrow { - pub(crate) use alloc::borrow::*; - pub(crate) use core::borrow::*; - } - - pub(crate) mod fmt { - pub(crate) use alloc::fmt::*; - pub(crate) use core::fmt::*; - } - - pub(crate) mod slice { - pub(crate) use alloc::slice::*; - pub(crate) use core::slice::*; - } - - pub(crate) mod str { - pub(crate) use alloc::str::*; - pub(crate) use core::str::*; - } - - pub(crate) mod sync { - pub(crate) use alloc::sync::*; - pub(crate) use core::sync::*; - } -}