diff --git a/src/attr.rs b/src/attr.rs index e0efb57c..82c50ddc 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -1,5 +1,5 @@ use super::*; -use punctuated::Punctuated; +use crate::punctuated::Punctuated; use std::iter; @@ -8,11 +8,11 @@ use proc_macro2::TokenStream; use proc_macro2::{Delimiter, Spacing, TokenTree}; #[cfg(feature = "parsing")] -use parse::{ParseStream, Result}; +use crate::parse::{ParseStream, Result}; +#[cfg(feature = "extra-traits")] +use crate::tt::TokenStreamHelper; #[cfg(feature = "extra-traits")] use std::hash::{Hash, Hasher}; -#[cfg(feature = "extra-traits")] -use tt::TokenStreamHelper; ast_struct! { /// An attribute like `#[repr(transparent)]`. @@ -542,10 +542,10 @@ where pub mod parsing { use super::*; - use ext::IdentExt; - use parse::{Parse, ParseStream, Result}; + use crate::ext::IdentExt; + use crate::parse::{Parse, ParseStream, Result}; #[cfg(feature = "full")] - use private; + use crate::private; pub fn single_parse_inner(input: ParseStream) -> Result { let content; diff --git a/src/buffer.rs b/src/buffer.rs index 6f66543c..be8ef128 100644 --- a/src/buffer.rs +++ b/src/buffer.rs @@ -11,7 +11,7 @@ not(all(target_arch = "wasm32", target_os = "unknown")), feature = "proc-macro" ))] -use proc_macro as pm; +use crate::proc_macro as pm; use proc_macro2::{Delimiter, Group, Ident, Literal, Punct, Spacing, Span, TokenStream, TokenTree}; use std::marker::PhantomData; diff --git a/src/data.rs b/src/data.rs index ba749b86..b635ed76 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,5 +1,5 @@ use super::*; -use punctuated::Punctuated; +use crate::punctuated::Punctuated; ast_struct! { /// An enum variant. @@ -179,8 +179,8 @@ ast_enum_of_structs! { pub mod parsing { use super::*; - use ext::IdentExt; - use parse::{Parse, ParseStream, Result}; + use crate::ext::IdentExt; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for Variant { fn parse(input: ParseStream) -> Result { @@ -319,7 +319,7 @@ mod printing { use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; - use print::TokensOrDefault; + use crate::print::TokensOrDefault; impl ToTokens for Variant { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/derive.rs b/src/derive.rs index 401d6b01..e47e3b38 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -1,5 +1,5 @@ use super::*; -use punctuated::Punctuated; +use crate::punctuated::Punctuated; ast_struct! { /// Data structure sent to a `proc_macro_derive` macro. @@ -74,7 +74,7 @@ ast_enum_of_structs! { pub mod parsing { use super::*; - use parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for DeriveInput { fn parse(input: ParseStream) -> Result { @@ -210,8 +210,8 @@ mod printing { use proc_macro2::TokenStream; use quote::ToTokens; - use attr::FilterAttrs; - use print::TokensOrDefault; + use crate::attr::FilterAttrs; + use crate::print::TokensOrDefault; impl ToTokens for DeriveInput { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/expr.rs b/src/expr.rs index 3d0b70a3..519fbf16 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1,12 +1,12 @@ use super::*; +use crate::punctuated::Punctuated; +#[cfg(feature = "extra-traits")] +use crate::tt::TokenStreamHelper; use proc_macro2::{Span, TokenStream}; -use punctuated::Punctuated; #[cfg(feature = "extra-traits")] use std::hash::{Hash, Hasher}; #[cfg(all(feature = "parsing", feature = "full"))] use std::mem; -#[cfg(feature = "extra-traits")] -use tt::TokenStreamHelper; ast_enum_of_structs! { /// A Rust expression. @@ -981,9 +981,9 @@ pub mod parsing { use super::*; #[cfg(feature = "full")] - use ext::IdentExt; - use parse::{Parse, ParseStream, Result}; - use path; + use crate::ext::IdentExt; + use crate::parse::{Parse, ParseStream, Result}; + use crate::path; // When we're parsing expressions which occur before blocks, like in an if // statement's condition, we cannot parse a struct literal. @@ -3038,9 +3038,9 @@ mod printing { use quote::{ToTokens, TokenStreamExt}; #[cfg(feature = "full")] - use attr::FilterAttrs; + use crate::attr::FilterAttrs; #[cfg(feature = "full")] - use print::TokensOrDefault; + use crate::print::TokensOrDefault; // If the given expression is a bare `ExprStruct`, wraps it in parenthesis // before appending it to `TokenStream`. diff --git a/src/file.rs b/src/file.rs index 30defe7d..1dcf64ce 100644 --- a/src/file.rs +++ b/src/file.rs @@ -78,7 +78,7 @@ ast_struct! { pub mod parsing { use super::*; - use parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for File { fn parse(input: ParseStream) -> Result { @@ -100,7 +100,7 @@ pub mod parsing { #[cfg(feature = "printing")] mod printing { use super::*; - use attr::FilterAttrs; + use crate::attr::FilterAttrs; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/generics.rs b/src/generics.rs index d9d652df..58838d28 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -1,5 +1,5 @@ use super::*; -use punctuated::{Iter, IterMut, Punctuated}; +use crate::punctuated::{Iter, IterMut, Punctuated}; ast_struct! { /// Lifetimes and type parameters attached to a declaration of a function, @@ -479,7 +479,7 @@ ast_enum_of_structs! { pub mod parsing { use super::*; - use parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for Generics { fn parse(input: ParseStream) -> Result { @@ -872,8 +872,8 @@ mod printing { use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; - use attr::FilterAttrs; - use print::TokensOrDefault; + use crate::attr::FilterAttrs; + use crate::print::TokensOrDefault; impl ToTokens for Generics { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/item.rs b/src/item.rs index 06346578..cc19b94a 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,13 +1,13 @@ use super::*; -use derive::{Data, DeriveInput}; +use crate::derive::{Data, DeriveInput}; +use crate::punctuated::Punctuated; +use crate::token::{Brace, Paren}; use proc_macro2::TokenStream; -use punctuated::Punctuated; -use token::{Brace, Paren}; #[cfg(feature = "extra-traits")] -use std::hash::{Hash, Hasher}; +use crate::tt::TokenStreamHelper; #[cfg(feature = "extra-traits")] -use tt::TokenStreamHelper; +use std::hash::{Hash, Hasher}; ast_enum_of_structs! { /// Things that can appear directly inside of a module or scope. @@ -778,8 +778,8 @@ ast_enum_of_structs! { pub mod parsing { use super::*; - use ext::IdentExt; - use parse::{Parse, ParseStream, Result}; + use crate::ext::IdentExt; + use crate::parse::{Parse, ParseStream, Result}; use proc_macro2::{Punct, Spacing, TokenTree}; use std::iter::FromIterator; @@ -2209,8 +2209,8 @@ mod printing { use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; - use attr::FilterAttrs; - use print::TokensOrDefault; + use crate::attr::FilterAttrs; + use crate::print::TokensOrDefault; impl ToTokens for ItemExternCrate { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/lib.rs b/src/lib.rs index fc8926ee..a87ca23f 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -299,17 +299,19 @@ pub mod group; pub mod token; mod ident; -pub use ident::Ident; +pub use crate::ident::Ident; #[cfg(any(feature = "full", feature = "derive"))] mod attr; #[cfg(any(feature = "full", feature = "derive"))] -pub use attr::{AttrStyle, Attribute, AttributeArgs, Meta, MetaList, MetaNameValue, NestedMeta}; +pub use crate::attr::{ + AttrStyle, Attribute, AttributeArgs, Meta, MetaList, MetaNameValue, NestedMeta, +}; #[cfg(any(feature = "full", feature = "derive"))] mod data; #[cfg(any(feature = "full", feature = "derive"))] -pub use data::{ +pub use crate::data::{ Field, Fields, FieldsNamed, FieldsUnnamed, Variant, VisCrate, VisPublic, VisRestricted, Visibility, }; @@ -317,7 +319,7 @@ pub use data::{ #[cfg(any(feature = "full", feature = "derive"))] mod expr; #[cfg(any(feature = "full", feature = "derive"))] -pub use expr::{ +pub use crate::expr::{ Expr, ExprArray, ExprAssign, ExprAssignOp, ExprAsync, ExprBinary, ExprBlock, ExprBox, ExprBreak, ExprCall, ExprCast, ExprClosure, ExprContinue, ExprField, ExprForLoop, ExprGroup, ExprIf, ExprInPlace, ExprIndex, ExprLet, ExprLit, ExprLoop, ExprMacro, ExprMatch, @@ -327,7 +329,7 @@ pub use expr::{ }; #[cfg(feature = "full")] -pub use expr::{ +pub use crate::expr::{ Arm, Block, FieldPat, FieldValue, GenericMethodArgument, Label, Local, MethodTurbofish, Pat, PatBox, PatIdent, PatLit, PatMacro, PatPath, PatRange, PatRef, PatSlice, PatStruct, PatTuple, PatTupleStruct, PatVerbatim, PatWild, RangeLimits, Stmt, @@ -336,18 +338,18 @@ pub use expr::{ #[cfg(any(feature = "full", feature = "derive"))] mod generics; #[cfg(any(feature = "full", feature = "derive"))] -pub use generics::{ +pub use crate::generics::{ BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeDef, PredicateEq, PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier, TypeParam, TypeParamBound, WhereClause, WherePredicate, }; #[cfg(all(any(feature = "full", feature = "derive"), feature = "printing"))] -pub use generics::{ImplGenerics, Turbofish, TypeGenerics}; +pub use crate::generics::{ImplGenerics, Turbofish, TypeGenerics}; #[cfg(feature = "full")] mod item; #[cfg(feature = "full")] -pub use item::{ +pub use crate::item::{ ArgCaptured, ArgSelf, ArgSelfRef, FnArg, FnDecl, ForeignItem, ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType, ForeignItemVerbatim, ImplItem, ImplItemConst, ImplItemExistential, ImplItemMacro, ImplItemMethod, ImplItemType, ImplItemVerbatim, Item, @@ -361,15 +363,15 @@ pub use item::{ #[cfg(feature = "full")] mod file; #[cfg(feature = "full")] -pub use file::File; +pub use crate::file::File; mod lifetime; -pub use lifetime::Lifetime; +pub use crate::lifetime::Lifetime; #[cfg(any(feature = "full", feature = "derive"))] mod lit; #[cfg(any(feature = "full", feature = "derive"))] -pub use lit::{ +pub use crate::lit::{ FloatSuffix, IntSuffix, Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr, LitVerbatim, StrStyle, }; @@ -377,22 +379,22 @@ pub use lit::{ #[cfg(any(feature = "full", feature = "derive"))] mod mac; #[cfg(any(feature = "full", feature = "derive"))] -pub use mac::{Macro, MacroDelimiter}; +pub use crate::mac::{Macro, MacroDelimiter}; #[cfg(any(feature = "full", feature = "derive"))] mod derive; #[cfg(feature = "derive")] -pub use derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput}; +pub use crate::derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput}; #[cfg(any(feature = "full", feature = "derive"))] mod op; #[cfg(any(feature = "full", feature = "derive"))] -pub use op::{BinOp, UnOp}; +pub use crate::op::{BinOp, UnOp}; #[cfg(any(feature = "full", feature = "derive"))] mod ty; #[cfg(any(feature = "full", feature = "derive"))] -pub use ty::{ +pub use crate::ty::{ Abi, BareFnArg, BareFnArgName, ReturnType, Type, TypeArray, TypeBareFn, TypeGroup, TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, TypeTraitObject, TypeTuple, TypeVerbatim, @@ -401,7 +403,7 @@ pub use ty::{ #[cfg(any(feature = "full", feature = "derive"))] mod path; #[cfg(any(feature = "full", feature = "derive"))] -pub use path::{ +pub use crate::path::{ AngleBracketedGenericArguments, Binding, Constraint, GenericArgument, ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf, }; @@ -546,7 +548,7 @@ mod gen { #[path = "../gen_helper.rs"] mod helper; } -pub use gen::*; +pub use crate::gen::*; // Not public API. #[doc(hidden)] diff --git a/src/mac.rs b/src/mac.rs index c4b16ba8..d74dd577 100644 --- a/src/mac.rs +++ b/src/mac.rs @@ -1,15 +1,15 @@ use super::*; +use crate::token::{Brace, Bracket, Paren}; use proc_macro2::TokenStream; #[cfg(feature = "parsing")] use proc_macro2::{Delimiter, Span, TokenTree}; -use token::{Brace, Bracket, Paren}; #[cfg(feature = "parsing")] -use parse::{Parse, ParseStream, Parser, Result}; +use crate::parse::{Parse, ParseStream, Parser, Result}; +#[cfg(feature = "extra-traits")] +use crate::tt::TokenStreamHelper; #[cfg(feature = "extra-traits")] use std::hash::{Hash, Hasher}; -#[cfg(feature = "extra-traits")] -use tt::TokenStreamHelper; ast_struct! { /// A macro invocation: `println!("{}", mac)`. @@ -194,7 +194,7 @@ pub fn parse_delimiter(input: ParseStream) -> Result<(MacroDelimiter, TokenStrea pub mod parsing { use super::*; - use parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for Macro { fn parse(input: ParseStream) -> Result { diff --git a/src/parse.rs b/src/parse.rs index 23845a93..dc66552f 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -203,7 +203,7 @@ use std::str::FromStr; not(all(target_arch = "wasm32", target_os = "unknown")), feature = "proc-macro" ))] -use proc_macro; +use crate::proc_macro; use proc_macro2::{self, Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree}; use crate::buffer::{Cursor, TokenBuffer}; diff --git a/src/path.rs b/src/path.rs index 6e891b94..15132d49 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,5 +1,5 @@ use super::*; -use punctuated::Punctuated; +use crate::punctuated::Punctuated; ast_struct! { /// A path at which a named item is exported: `std::collections::HashMap`. @@ -205,9 +205,9 @@ pub mod parsing { use super::*; #[cfg(feature = "full")] - use expr; - use ext::IdentExt; - use parse::{Parse, ParseStream, Result}; + use crate::expr; + use crate::ext::IdentExt; + use crate::parse::{Parse, ParseStream, Result}; impl Parse for Path { fn parse(input: ParseStream) -> Result { @@ -524,7 +524,7 @@ mod printing { use proc_macro2::TokenStream; use quote::ToTokens; - use print::TokensOrDefault; + use crate::print::TokensOrDefault; impl ToTokens for Path { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/src/ty.rs b/src/ty.rs index 9e6e3f3e..a361ce4d 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -1,10 +1,10 @@ use super::*; +use crate::punctuated::Punctuated; +#[cfg(feature = "extra-traits")] +use crate::tt::TokenStreamHelper; use proc_macro2::TokenStream; -use punctuated::Punctuated; #[cfg(feature = "extra-traits")] use std::hash::{Hash, Hasher}; -#[cfg(feature = "extra-traits")] -use tt::TokenStreamHelper; ast_enum_of_structs! { /// The possible types that a Rust value could have. @@ -245,8 +245,8 @@ ast_enum! { pub mod parsing { use super::*; - use parse::{Parse, ParseStream, Result}; - use path; + use crate::parse::{Parse, ParseStream, Result}; + use crate::path; impl Parse for Type { fn parse(input: ParseStream) -> Result { @@ -827,7 +827,7 @@ mod printing { use proc_macro2::TokenStream; use quote::ToTokens; - use print::TokensOrDefault; + use crate::print::TokensOrDefault; impl ToTokens for TypeSlice { fn to_tokens(&self, tokens: &mut TokenStream) { diff --git a/tests/macros/mod.rs b/tests/macros/mod.rs index e35872af..c72fd010 100644 --- a/tests/macros/mod.rs +++ b/tests/macros/mod.rs @@ -40,12 +40,12 @@ macro_rules! snapshot { #[macro_export] macro_rules! snapshot_impl { (($expr:ident) as $t:ty, @$snapshot:literal) => { - let $expr = ::macros::Tokens::parse::<$t>($expr).unwrap(); + let $expr = crate::macros::Tokens::parse::<$t>($expr).unwrap(); let debug = crate::macros::debug::Lite(&$expr); insta::assert_debug_snapshot_matches!(debug, @$snapshot); }; (($($expr:tt)*) as $t:ty, @$snapshot:literal) => {{ - let syntax_tree = ::macros::Tokens::parse::<$t>($($expr)*).unwrap(); + let syntax_tree = crate::macros::Tokens::parse::<$t>($($expr)*).unwrap(); let debug = crate::macros::debug::Lite(&syntax_tree); insta::assert_debug_snapshot_matches!(debug, @$snapshot); syntax_tree