From 971948ad691a7336c4a453304842cc714e54cd6f Mon Sep 17 00:00:00 2001 From: David Tolnay Date: Sun, 31 Jul 2022 20:25:11 -0700 Subject: [PATCH] Change std imports to core where possible Useful for seeing what are the gaps toward being compatible with no-std. Useful for copying chunks of code into a no-std crate. --- src/detection.rs | 2 +- src/fallback.rs | 16 ++++++++-------- src/lib.rs | 14 +++++++------- src/marker.rs | 4 ++-- src/parse.rs | 4 ++-- src/rcvec.rs | 4 ++-- src/wrapper.rs | 8 ++++---- 7 files changed, 26 insertions(+), 26 deletions(-) diff --git a/src/detection.rs b/src/detection.rs index d139b736..beba7b23 100644 --- a/src/detection.rs +++ b/src/detection.rs @@ -1,4 +1,4 @@ -use std::sync::atomic::{AtomicUsize, Ordering}; +use core::sync::atomic::{AtomicUsize, Ordering}; use std::sync::Once; static WORKS: AtomicUsize = AtomicUsize::new(0); diff --git a/src/fallback.rs b/src/fallback.rs index 2abfff7d..378ef7e9 100644 --- a/src/fallback.rs +++ b/src/fallback.rs @@ -2,18 +2,18 @@ use crate::parse::{self, Cursor}; use crate::rcvec::{RcVec, RcVecBuilder, RcVecIntoIter, RcVecMut}; use crate::{Delimiter, Spacing, TokenTree}; #[cfg(span_locations)] -use std::cell::RefCell; +use core::cell::RefCell; #[cfg(span_locations)] -use std::cmp; -use std::fmt::{self, Debug, Display, Write}; -use std::iter::FromIterator; -use std::mem::ManuallyDrop; -use std::ops::RangeBounds; +use core::cmp; +use core::fmt::{self, Debug, Display, Write}; +use core::iter::FromIterator; +use core::mem::ManuallyDrop; +use core::ops::RangeBounds; +use core::ptr; +use core::str::FromStr; #[cfg(procmacro2_semver_exempt)] use std::path::Path; use std::path::PathBuf; -use std::ptr; -use std::str::FromStr; /// Force use of proc-macro2's fallback implementation of the API for now, even /// if the compiler's implementation is available. diff --git a/src/lib.rs b/src/lib.rs index 470c7283..ed08169f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -137,15 +137,15 @@ use crate::fallback as imp; mod imp; use crate::marker::Marker; -use std::cmp::Ordering; +use core::cmp::Ordering; +use core::fmt::{self, Debug, Display}; +use core::hash::{Hash, Hasher}; +use core::iter::FromIterator; +use core::ops::RangeBounds; +use core::str::FromStr; use std::error::Error; -use std::fmt::{self, Debug, Display}; -use std::hash::{Hash, Hasher}; -use std::iter::FromIterator; -use std::ops::RangeBounds; #[cfg(procmacro2_semver_exempt)] use std::path::PathBuf; -use std::str::FromStr; /// An abstract stream of tokens, or more concretely a sequence of token trees. /// @@ -1271,7 +1271,7 @@ impl Display for Literal { pub mod token_stream { use crate::marker::Marker; use crate::{imp, TokenTree}; - use std::fmt::{self, Debug}; + use core::fmt::{self, Debug}; pub use crate::TokenStream; diff --git a/src/marker.rs b/src/marker.rs index 58729baf..59fd0963 100644 --- a/src/marker.rs +++ b/src/marker.rs @@ -1,4 +1,4 @@ -use std::marker::PhantomData; +use core::marker::PhantomData; use std::panic::{RefUnwindSafe, UnwindSafe}; use std::rc::Rc; @@ -9,7 +9,7 @@ pub(crate) type Marker = PhantomData; pub(crate) use self::value::*; mod value { - pub(crate) use std::marker::PhantomData as Marker; + pub(crate) use core::marker::PhantomData as Marker; } pub(crate) struct ProcMacroAutoTraits(Rc<()>); diff --git a/src/parse.rs b/src/parse.rs index 9974ab82..1c9974cf 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -3,8 +3,8 @@ use crate::fallback::{ TokenStreamBuilder, }; use crate::{Delimiter, Punct, Spacing, TokenTree}; -use std::char; -use std::str::{Bytes, CharIndices, Chars}; +use core::char; +use core::str::{Bytes, CharIndices, Chars}; #[derive(Copy, Clone, Eq, PartialEq)] pub(crate) struct Cursor<'a> { diff --git a/src/rcvec.rs b/src/rcvec.rs index 5e6cc27c..86ca7d80 100644 --- a/src/rcvec.rs +++ b/src/rcvec.rs @@ -1,6 +1,6 @@ -use std::mem; +use core::mem; +use core::slice; use std::rc::Rc; -use std::slice; use std::vec; pub(crate) struct RcVec { diff --git a/src/wrapper.rs b/src/wrapper.rs index 15d6dc4c..93444013 100644 --- a/src/wrapper.rs +++ b/src/wrapper.rs @@ -1,12 +1,12 @@ use crate::detection::inside_proc_macro; use crate::{fallback, Delimiter, Punct, Spacing, TokenTree}; -use std::fmt::{self, Debug, Display}; -use std::iter::FromIterator; -use std::ops::RangeBounds; +use core::fmt::{self, Debug, Display}; +use core::iter::FromIterator; +use core::ops::RangeBounds; +use core::str::FromStr; use std::panic; #[cfg(super_unstable)] use std::path::PathBuf; -use std::str::FromStr; #[derive(Clone)] pub(crate) enum TokenStream {