Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion codegen/src/debug.rs
Original file line number Diff line number Diff line change
Expand Up @@ -198,7 +198,7 @@ pub fn generate(defs: &Definitions) -> Result<()> {
quote! {
#![allow(unknown_lints, non_local_definitions)]

use std::fmt::{self, Debug};
use core::fmt::{self, Debug};

#impls
},
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/eq.rs
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,8 @@ pub fn generate(defs: &Definitions) -> Result<()> {
quote! {
#[cfg(any(feature = "derive", feature = "full"))]
use crate::tt::TokenStreamHelper;
#[cfg(feature = "extra-traits")]
use alloc::string::ToString;

#impls
},
Expand Down
5 changes: 5 additions & 0 deletions codegen/src/fold.rs
Original file line number Diff line number Diff line change
Expand Up @@ -255,6 +255,11 @@ pub fn generate(defs: &Definitions) -> Result<()> {
clippy::needless_pass_by_ref_mut,
)]

#[cfg(any(feature = "derive", feature = "full"))]
use alloc::boxed::Box;
#[cfg(any(feature = "derive", feature = "full"))]
use alloc::vec::Vec;

#full_macro

/// Syntax tree traversal to transform the nodes of an owned syntax tree.
Expand Down
4 changes: 3 additions & 1 deletion codegen/src/hash.rs
Original file line number Diff line number Diff line change
Expand Up @@ -160,7 +160,9 @@ pub fn generate(defs: &Definitions) -> Result<()> {
quote! {
#[cfg(any(feature = "derive", feature = "full"))]
use crate::tt::TokenStreamHelper;
use std::hash::{Hash, Hasher};
#[cfg(feature = "extra-traits")]
use alloc::string::ToString;
use core::hash::{Hash, Hasher};

#impls
},
Expand Down
2 changes: 1 addition & 1 deletion codegen/src/snapshot.rs
Original file line number Diff line number Diff line change
Expand Up @@ -363,7 +363,7 @@ pub fn generate(defs: &Definitions) -> Result<()> {

use super::{Lite, Present};
use ref_cast::RefCast;
use std::fmt::{self, Debug, Display};
use core::fmt::{self, Debug, Display};

#impls
},
Expand Down
2 changes: 2 additions & 0 deletions codegen/src/visit_mut.rs
Original file line number Diff line number Diff line change
Expand Up @@ -233,6 +233,8 @@ pub fn generate(defs: &Definitions) -> Result<()> {
#![allow(unused_variables)]
#![allow(clippy::needless_pass_by_ref_mut)]

#[cfg(any(feature = "derive", feature = "full"))]
use alloc::vec::Vec;
#[cfg(any(feature = "full", feature = "derive"))]
use crate::punctuated::Punctuated;

Expand Down
13 changes: 9 additions & 4 deletions src/attr.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,15 @@ use crate::meta::{self, ParseNestedMeta};
use crate::parse::{Parse, ParseStream, Parser};
use crate::path::Path;
use crate::token;
use proc_macro2::TokenStream;
#[cfg(feature = "parsing")]
use alloc::format;
#[cfg(feature = "parsing")]
use alloc::vec::Vec;
#[cfg(feature = "printing")]
use std::iter;
use core::iter;
#[cfg(feature = "printing")]
use std::slice;
use core::slice;
use proc_macro2::TokenStream;

ast_struct! {
/// An attribute, like `#[repr(transparent)]`.
Expand Down Expand Up @@ -653,8 +657,9 @@ pub(crate) mod parsing {
use crate::parse::{Parse, ParseStream};
use crate::path::Path;
use crate::{mac, token};
use alloc::vec::Vec;
use core::fmt::{self, Display};
use proc_macro2::Ident;
use std::fmt::{self, Display};

pub(crate) fn parse_inner(input: ParseStream, attrs: &mut Vec<Attribute>) -> Result<()> {
while input.peek(Token![#]) && input.peek2(Token![!]) {
Expand Down
4 changes: 3 additions & 1 deletion src/bigint.rs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
use std::ops::{AddAssign, MulAssign};
use alloc::string::String;
use alloc::vec::Vec;
use core::ops::{AddAssign, MulAssign};

// For implementing base10_digits() accessor on LitInt.
pub(crate) struct BigInt {
Expand Down
8 changes: 5 additions & 3 deletions src/buffer.rs
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,13 @@

use crate::ext::TokenStreamExt as _;
use crate::Lifetime;
use alloc::boxed::Box;
use alloc::vec::Vec;
use core::cmp::Ordering;
use core::marker::PhantomData;
use core::ptr;
use proc_macro2::extra::DelimSpan;
use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree};
use std::cmp::Ordering;
use std::marker::PhantomData;
use std::ptr;

/// Internal type which is used instead of `TokenTree` to represent a token tree
/// within a `TokenBuffer`.
Expand Down
4 changes: 2 additions & 2 deletions src/classify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ use crate::path::{Path, PathArguments};
use crate::punctuated::Punctuated;
#[cfg(any(feature = "printing", feature = "full"))]
use crate::ty::{ReturnType, Type};
#[cfg(any(feature = "printing", feature = "full"))]
use core::ops::ControlFlow;
#[cfg(feature = "full")]
use proc_macro2::{Delimiter, TokenStream, TokenTree};
#[cfg(any(feature = "printing", feature = "full"))]
use std::ops::ControlFlow;

#[cfg(feature = "full")]
pub(crate) fn requires_semi_to_be_stmt(expr: &Expr) -> bool {
Expand Down
2 changes: 1 addition & 1 deletion src/custom_punctuation.rs
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
///
/// ```
/// use proc_macro2::{TokenStream, TokenTree};
/// use std::iter;
/// use core::iter;
/// use syn::parse::{Parse, ParseStream, Peek, Result};
/// use syn::punctuated::Punctuated;
/// use syn::Expr;
Expand Down
1 change: 1 addition & 0 deletions src/data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::punctuated::{self, Punctuated};
use crate::restriction::{FieldMutability, Visibility};
use crate::token;
use crate::ty::Type;
use alloc::vec::Vec;

ast_struct! {
/// An enum variant.
Expand Down
1 change: 1 addition & 0 deletions src/derive.rs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ use crate::ident::Ident;
use crate::punctuated::Punctuated;
use crate::restriction::Visibility;
use crate::token;
use alloc::vec::Vec;

ast_struct! {
/// Data structure sent to a `proc_macro_derive` macro.
Expand Down
6 changes: 3 additions & 3 deletions src/discouraged.rs
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
use crate::buffer::Cursor;
use crate::error::Result;
use crate::parse::{inner_unexpected, ParseBuffer, Unexpected};
use alloc::rc::Rc;
use core::cell::Cell;
use core::mem;
use proc_macro2::extra::DelimSpan;
use proc_macro2::Delimiter;
use std::cell::Cell;
use std::mem;
use std::rc::Rc;

/// Extensions to the `ParseStream` API to support speculative parsing.
pub trait Speculative {
Expand Down
12 changes: 6 additions & 6 deletions src/drops.rs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
use std::iter;
use std::mem::ManuallyDrop;
use std::ops::{Deref, DerefMut};
use std::option;
use std::slice;
use core::iter;
use core::mem::ManuallyDrop;
use core::ops::{Deref, DerefMut};
use core::option;
use core::slice;

#[repr(transparent)]
pub(crate) struct NoDrop<T: ?Sized>(ManuallyDrop<T>);
Expand Down Expand Up @@ -39,7 +39,7 @@ impl<T> TrivialDrop for option::IntoIter<&mut T> {}

#[test]
fn test_needs_drop() {
use std::mem::needs_drop;
use core::mem::needs_drop;

struct NeedsDrop;

Expand Down
30 changes: 17 additions & 13 deletions src/error.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,20 @@
use crate::buffer::Cursor;
use crate::ext::{PunctExt as _, TokenStreamExt as _};
use crate::thread::ThreadBound;
#[cfg(feature = "parsing")]
use alloc::format;
use alloc::string::{String, ToString};
use alloc::vec::{self, Vec};
use core::fmt::{self, Debug, Display};
use core::slice;
use proc_macro2::{
Delimiter, Group, Ident, LexError, Literal, Punct, Spacing, Span, TokenStream, TokenTree,
};
#[cfg(feature = "printing")]
use quote::ToTokens;
use std::fmt::{self, Debug, Display};
use std::slice;
use std::vec;

/// The result of a Syn parser.
pub type Result<T> = std::result::Result<T, Error>;
pub type Result<T> = core::result::Result<T, Error>;

/// Error returned when a Syn parser cannot parse the input tokens.
///
Expand All @@ -23,7 +26,7 @@ pub type Result<T> = std::result::Result<T, Error>;
/// [`compile_error!`] in the generated code. This produces a better diagnostic
/// message than simply panicking the macro.
///
/// [`compile_error!`]: std::compile_error!
/// [`compile_error!`]: core::compile_error!
///
/// When parsing macro input, the [`parse_macro_input!`] macro handles the
/// conversion to `compile_error!` automatically.
Expand Down Expand Up @@ -112,7 +115,7 @@ struct ErrorMessage {
message: String,
}

// Cannot use std::ops::Range<Span> because that does not implement Copy,
// Cannot use core::ops::Range<Span> because that does not implement Copy,
// whereas ThreadBound<T> requires a Copy impl as a way to ensure no Drop impls
// are involved.
struct SpanRange {
Expand Down Expand Up @@ -161,7 +164,7 @@ impl Error {

fn new(span: Span, message: String) -> Error {
Error {
messages: vec![ErrorMessage {
messages: alloc::vec![ErrorMessage {
span: ThreadBound::new(SpanRange {
start: span,
end: span,
Expand Down Expand Up @@ -195,7 +198,7 @@ impl Error {
let start = iter.next().map_or_else(Span::call_site, |t| t.span());
let end = iter.last().map_or(start, |t| t.span());
Error {
messages: vec![ErrorMessage {
messages: alloc::vec![ErrorMessage {
span: ThreadBound::new(SpanRange { start, end }),
message,
}],
Expand All @@ -221,7 +224,7 @@ impl Error {
/// The [`parse_macro_input!`] macro provides a convenient way to invoke
/// this method correctly in a procedural macro.
///
/// [`compile_error!`]: std::compile_error!
/// [`compile_error!`]: core::compile_error!
/// [`parse_macro_input!`]: crate::parse_macro_input!
pub fn to_compile_error(&self) -> TokenStream {
let mut tokens = TokenStream::new();
Expand All @@ -233,7 +236,7 @@ impl Error {

/// Render the error as an invocation of [`compile_error!`].
///
/// [`compile_error!`]: std::compile_error!
/// [`compile_error!`]: core::compile_error!
///
/// # Example
///
Expand Down Expand Up @@ -340,7 +343,7 @@ pub(crate) fn new2<T: Display>(start: Span, end: Span, message: T) -> Error {

fn new2(start: Span, end: Span, message: String) -> Error {
Error {
messages: vec![ErrorMessage {
messages: alloc::vec![ErrorMessage {
span: ThreadBound::new(SpanRange { start, end }),
message,
}],
Expand Down Expand Up @@ -401,6 +404,7 @@ impl Clone for SpanRange {

impl Copy for SpanRange {}

// TODO(MSRV 1.81.0): impl core::error::Error.
impl std::error::Error for Error {}

impl From<LexError> for Error {
Expand Down Expand Up @@ -429,7 +433,7 @@ impl Iterator for IntoIter {

fn next(&mut self) -> Option<Self::Item> {
Some(Error {
messages: vec![self.messages.next()?],
messages: alloc::vec![self.messages.next()?],
})
}
}
Expand All @@ -454,7 +458,7 @@ impl<'a> Iterator for Iter<'a> {

fn next(&mut self) -> Option<Self::Item> {
Some(Error {
messages: vec![self.messages.next()?.clone()],
messages: alloc::vec![self.messages.next()?.clone()],
})
}
}
Expand Down
28 changes: 14 additions & 14 deletions src/export.rs
Original file line number Diff line number Diff line change
@@ -1,33 +1,33 @@
#[doc(hidden)]
pub use std::clone::Clone;
pub use core::clone::Clone;
#[doc(hidden)]
pub use std::cmp::{Eq, PartialEq};
pub use core::cmp::{Eq, PartialEq};
#[doc(hidden)]
pub use std::concat;
pub use core::concat;
#[doc(hidden)]
pub use std::default::Default;
pub use core::default::Default;
#[doc(hidden)]
pub use std::fmt::Debug;
pub use core::fmt::Debug;
#[doc(hidden)]
pub use std::hash::{Hash, Hasher};
pub use core::hash::{Hash, Hasher};
#[doc(hidden)]
pub use std::marker::Copy;
pub use core::marker::Copy;
#[doc(hidden)]
pub use std::option::Option::{None, Some};
pub use core::option::Option::{None, Some};
#[doc(hidden)]
pub use std::result::Result::{Err, Ok};
pub use core::result::Result::{Err, Ok};
#[doc(hidden)]
pub use std::stringify;
pub use core::stringify;

#[doc(hidden)]
pub type Formatter<'a> = std::fmt::Formatter<'a>;
pub type Formatter<'a> = core::fmt::Formatter<'a>;
#[doc(hidden)]
pub type FmtResult = std::fmt::Result;
pub type FmtResult = core::fmt::Result;

#[doc(hidden)]
pub type bool = std::primitive::bool;
pub type bool = core::primitive::bool;
#[doc(hidden)]
pub type str = std::primitive::str;
pub type str = core::primitive::str;

#[cfg(feature = "printing")]
#[doc(hidden)]
Expand Down
Loading