diff --git a/src/attr.rs b/src/attr.rs index 2859c709fd..5d85895288 100644 --- a/src/attr.rs +++ b/src/attr.rs @@ -1,15 +1,21 @@ -use super::*; +#[cfg(feature = "parsing")] +use crate::error::Error; +#[cfg(feature = "parsing")] +use crate::error::Result; +use crate::expr::Expr; +use crate::mac::MacroDelimiter; +#[cfg(feature = "parsing")] +use crate::meta::{self, ParseNestedMeta}; +#[cfg(feature = "parsing")] +use crate::parse::{Parse, ParseStream, Parser}; +use crate::path::Path; +use crate::token; use proc_macro2::TokenStream; #[cfg(feature = "printing")] use std::iter; #[cfg(feature = "printing")] use std::slice; -#[cfg(feature = "parsing")] -use crate::meta::{self, ParseNestedMeta}; -#[cfg(feature = "parsing")] -use crate::parse::{Parse, ParseStream, Parser, Result}; - ast_struct! { /// An attribute, like `#[repr(transparent)]`. /// @@ -621,14 +627,19 @@ impl<'a> FilterAttrs<'a> for &'a [Attribute] { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::{AttrStyle, Attribute, Meta, MetaList, MetaNameValue}; + use crate::error::Result; + use crate::expr::{Expr, ExprLit}; + use crate::lit::Lit; use crate::parse::discouraged::Speculative as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream}; + use crate::path::Path; + use crate::{mac, token}; use std::fmt::{self, Display}; pub(crate) fn parse_inner(input: ParseStream, attrs: &mut Vec) -> Result<()> { while input.peek(Token![#]) && input.peek2(Token![!]) { - attrs.push(input.call(parsing::single_parse_inner)?); + attrs.push(input.call(single_parse_inner)?); } Ok(()) } @@ -746,7 +757,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::attr::{AttrStyle, Attribute, MetaList, MetaNameValue}; use proc_macro2::TokenStream; use quote::ToTokens; diff --git a/src/data.rs b/src/data.rs index 134b76bb41..febf39acc2 100644 --- a/src/data.rs +++ b/src/data.rs @@ -1,5 +1,10 @@ -use super::*; -use crate::punctuated::Punctuated; +use crate::attr::Attribute; +use crate::expr::Expr; +use crate::ident::Ident; +use crate::punctuated::{self, Punctuated}; +use crate::restriction::{FieldMutability, Visibility}; +use crate::token; +use crate::ty::Type; ast_struct! { /// An enum variant. @@ -155,11 +160,19 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::Attribute; + use crate::data::{Field, Fields, FieldsNamed, FieldsUnnamed, Variant}; + use crate::error::Result; + use crate::expr::Expr; use crate::ext::IdentExt as _; + use crate::ident::Ident; #[cfg(not(feature = "full"))] use crate::parse::discouraged::Speculative as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream}; + use crate::restriction::{FieldMutability, Visibility}; + use crate::token; + use crate::ty::Type; + use crate::verbatim; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Variant { @@ -205,6 +218,12 @@ pub(crate) mod parsing { #[cfg(not(feature = "full"))] pub(crate) fn scan_lenient_discriminant(input: ParseStream) -> Result<()> { + use crate::expr::Member; + use crate::lifetime::Lifetime; + use crate::lit::Lit; + use crate::lit::LitFloat; + use crate::op::{BinOp, UnOp}; + use crate::path::{self, AngleBracketedGenericArguments}; use proc_macro2::Delimiter::{self, Brace, Bracket, Parenthesis}; let consume = |delimiter: Delimiter| { @@ -353,7 +372,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::data::{Field, FieldsNamed, FieldsUnnamed, Variant}; use crate::print::TokensOrDefault; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/derive.rs b/src/derive.rs index 25fa4c910b..277fef7939 100644 --- a/src/derive.rs +++ b/src/derive.rs @@ -1,5 +1,10 @@ -use super::*; +use crate::attr::Attribute; +use crate::data::{Fields, FieldsNamed, Variant}; +use crate::generics::Generics; +use crate::ident::Ident; use crate::punctuated::Punctuated; +use crate::restriction::Visibility; +use crate::token; ast_struct! { /// Data structure sent to a `proc_macro_derive` macro. @@ -60,8 +65,16 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - use crate::parse::{Parse, ParseStream, Result}; + use crate::attr::Attribute; + use crate::data::{Fields, FieldsNamed, Variant}; + use crate::derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput}; + use crate::error::Result; + use crate::generics::{Generics, WhereClause}; + use crate::ident::Ident; + use crate::parse::{Parse, ParseStream}; + use crate::punctuated::Punctuated; + use crate::restriction::Visibility; + use crate::token; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for DeriveInput { @@ -193,8 +206,9 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::data::Fields; + use crate::derive::{Data, DeriveInput}; use crate::print::TokensOrDefault; use proc_macro2::TokenStream; use quote::ToTokens; diff --git a/src/discouraged.rs b/src/discouraged.rs index fb98d6332c..7ed51c96e6 100644 --- a/src/discouraged.rs +++ b/src/discouraged.rs @@ -1,7 +1,13 @@ //! Extensions to the parsing API with niche applicability. -use super::*; +use crate::buffer::Cursor; +use crate::error::Result; +use crate::parse::{inner_unexpected, ParseBuffer, Unexpected}; 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 { diff --git a/src/expr.rs b/src/expr.rs index 7fb0f7b4e2..4229864a80 100644 --- a/src/expr.rs +++ b/src/expr.rs @@ -1,12 +1,29 @@ -use super::*; +use crate::attr::Attribute; +#[cfg(feature = "full")] +use crate::generics::BoundLifetimes; +use crate::ident::Ident; +#[cfg(feature = "full")] +use crate::lifetime::Lifetime; +use crate::lit::Lit; +use crate::mac::Macro; +use crate::op::{BinOp, UnOp}; +#[cfg(feature = "full")] +use crate::pat::Pat; +use crate::path::{AngleBracketedGenericArguments, Path, QSelf}; use crate::punctuated::Punctuated; +#[cfg(feature = "full")] +use crate::stmt::Block; +use crate::token; +#[cfg(feature = "full")] +use crate::ty::ReturnType; +use crate::ty::Type; use proc_macro2::{Span, TokenStream}; #[cfg(feature = "printing")] use quote::IdentFragment; #[cfg(feature = "printing")] use std::fmt::{self, Display}; use std::hash::{Hash, Hasher}; -#[cfg(feature = "parsing")] +#[cfg(all(feature = "parsing", feature = "full"))] use std::mem; ast_enum_of_structs! { @@ -1011,16 +1028,52 @@ mod precedence { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::precedence::Precedence; - use super::*; + #[cfg(feature = "full")] + use crate::attr; + use crate::attr::Attribute; + use crate::error::{Error, Result}; + use crate::expr::precedence::Precedence; + #[cfg(feature = "full")] + use crate::expr::{ + requires_terminator, Arm, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, + ExprBreak, ExprClosure, ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, + ExprLoop, ExprMatch, ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, + ExprUnsafe, ExprWhile, ExprYield, Label, RangeLimits, + }; + use crate::expr::{ + Expr, ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro, + ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue, + Index, Member, + }; #[cfg(feature = "full")] use crate::ext::IdentExt as _; + #[cfg(feature = "full")] + use crate::generics::BoundLifetimes; + use crate::ident::Ident; + #[cfg(feature = "full")] + use crate::lifetime::Lifetime; + use crate::lit::{Lit, LitFloat, LitInt}; + use crate::mac::{self, Macro}; + use crate::op::BinOp; use crate::parse::discouraged::Speculative as _; #[cfg(feature = "full")] use crate::parse::ParseBuffer; - use crate::parse::{Parse, ParseStream, Result}; - use crate::path; + use crate::parse::{Parse, ParseStream}; + #[cfg(feature = "full")] + use crate::pat::{Pat, PatType}; + use crate::path::{self, AngleBracketedGenericArguments, Path, QSelf}; + use crate::punctuated::Punctuated; + #[cfg(feature = "full")] + use crate::stmt::Block; + use crate::token; + use crate::ty; + #[cfg(feature = "full")] + use crate::ty::{ReturnType, Type}; + use crate::verbatim; + #[cfg(feature = "full")] + use proc_macro2::TokenStream; use std::cmp::Ordering; + use std::mem; mod kw { crate::custom_keyword!(builtin); @@ -2948,10 +3001,25 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] pub(crate) mod printing { - use super::*; + use crate::attr::Attribute; #[cfg(feature = "full")] use crate::attr::FilterAttrs; - use proc_macro2::{Literal, TokenStream}; + #[cfg(feature = "full")] + use crate::expr::{ + requires_terminator, Arm, Expr, ExprArray, ExprAssign, ExprAsync, ExprAwait, ExprBlock, + ExprBreak, ExprClosure, ExprConst, ExprContinue, ExprForLoop, ExprIf, ExprInfer, ExprLet, + ExprLoop, ExprMatch, ExprRange, ExprRepeat, ExprReturn, ExprTry, ExprTryBlock, ExprTuple, + ExprUnsafe, ExprWhile, ExprYield, Label, RangeLimits, + }; + use crate::expr::{ + ExprBinary, ExprCall, ExprCast, ExprField, ExprGroup, ExprIndex, ExprLit, ExprMacro, + ExprMethodCall, ExprParen, ExprPath, ExprReference, ExprStruct, ExprUnary, FieldValue, + Index, Member, + }; + use crate::path; + #[cfg(feature = "full")] + use crate::token; + use proc_macro2::{Literal, Span, TokenStream}; use quote::{ToTokens, TokenStreamExt}; // If the given expression is a bare `ExprStruct`, wraps it in parenthesis diff --git a/src/ext.rs b/src/ext.rs index 9ee567251e..5cd79e863a 100644 --- a/src/ext.rs +++ b/src/ext.rs @@ -1,8 +1,9 @@ //! Extension traits to provide parsing methods on foreign types. use crate::buffer::Cursor; +use crate::error::Result; +use crate::parse::ParseStream; use crate::parse::Peek; -use crate::parse::{ParseStream, Result}; use crate::sealed::lookahead; use crate::token::CustomToken; use proc_macro2::Ident; diff --git a/src/file.rs b/src/file.rs index 2d9f298cc8..f728ab9ce9 100644 --- a/src/file.rs +++ b/src/file.rs @@ -1,4 +1,5 @@ -use super::*; +use crate::attr::Attribute; +use crate::item::Item; ast_struct! { /// A complete file of Rust source code. @@ -87,8 +88,10 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - use crate::parse::{Parse, ParseStream, Result}; + use crate::attr::Attribute; + use crate::error::Result; + use crate::file::File; + use crate::parse::{Parse, ParseStream}; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for File { @@ -110,8 +113,8 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::file::File; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/generics.rs b/src/generics.rs index aed50e3047..0299d74a81 100644 --- a/src/generics.rs +++ b/src/generics.rs @@ -1,5 +1,11 @@ -use super::*; +use crate::attr::Attribute; +use crate::expr::Expr; +use crate::ident::Ident; +use crate::lifetime::Lifetime; +use crate::path::Path; use crate::punctuated::{Iter, IterMut, Punctuated}; +use crate::token; +use crate::ty::Type; use proc_macro2::TokenStream; #[cfg(all(feature = "printing", feature = "extra-traits"))] use std::fmt::{self, Debug}; @@ -531,9 +537,22 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::Attribute; + use crate::error::Result; use crate::ext::IdentExt as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::generics::{ + BoundLifetimes, ConstParam, GenericParam, Generics, LifetimeParam, PredicateLifetime, + PredicateType, TraitBound, TraitBoundModifier, TypeParam, TypeParamBound, WhereClause, + WherePredicate, + }; + use crate::ident::Ident; + use crate::lifetime::Lifetime; + use crate::parse::{Parse, ParseStream}; + use crate::path::{self, ParenthesizedGenericArguments, Path, PathArguments}; + use crate::punctuated::Punctuated; + use crate::token; + use crate::ty::Type; + use crate::verbatim; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Generics { @@ -971,8 +990,12 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::generics::{ + BoundLifetimes, ConstParam, GenericParam, Generics, ImplGenerics, LifetimeParam, + PredicateLifetime, PredicateType, TraitBound, TraitBoundModifier, Turbofish, TypeGenerics, + TypeParam, WhereClause, + }; use crate::print::TokensOrDefault; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/ident.rs b/src/ident.rs index d0f4ba08db..3e57324c33 100644 --- a/src/ident.rs +++ b/src/ident.rs @@ -51,7 +51,8 @@ pub(crate) fn xid_ok(symbol: &str) -> bool { #[cfg(feature = "parsing")] mod parsing { use crate::buffer::Cursor; - use crate::parse::{Parse, ParseStream, Result}; + use crate::error::Result; + use crate::parse::{Parse, ParseStream}; use crate::token::Token; use proc_macro2::Ident; diff --git a/src/item.rs b/src/item.rs index 4e404e266a..22447bb318 100644 --- a/src/item.rs +++ b/src/item.rs @@ -1,8 +1,19 @@ -use super::*; +use crate::attr::Attribute; +use crate::data::{Fields, FieldsNamed, Variant}; use crate::derive::{Data, DataEnum, DataStruct, DataUnion, DeriveInput}; +use crate::expr::Expr; +use crate::generics::{Generics, TypeParamBound}; +use crate::ident::Ident; +use crate::lifetime::Lifetime; +use crate::mac::Macro; +use crate::pat::{Pat, PatType}; +use crate::path::Path; use crate::punctuated::Punctuated; +use crate::restriction::Visibility; +use crate::stmt::Block; +use crate::token; +use crate::ty::{Abi, ReturnType, Type}; use proc_macro2::TokenStream; - #[cfg(feature = "parsing")] use std::mem; @@ -893,10 +904,35 @@ ast_enum! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::{self, Attribute}; + use crate::derive; + use crate::error::{Error, Result}; + use crate::expr::Expr; use crate::ext::IdentExt as _; + use crate::generics::{Generics, TypeParamBound}; + use crate::ident::Ident; + use crate::item::{ + FnArg, ForeignItem, ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType, + ImplItem, ImplItemConst, ImplItemFn, ImplItemMacro, ImplItemType, Item, ItemConst, + ItemEnum, ItemExternCrate, ItemFn, ItemForeignMod, ItemImpl, ItemMacro, ItemMod, + ItemStatic, ItemStruct, ItemTrait, ItemTraitAlias, ItemType, ItemUnion, ItemUse, Receiver, + Signature, StaticMutability, TraitItem, TraitItemConst, TraitItemFn, TraitItemMacro, + TraitItemType, UseGlob, UseGroup, UseName, UsePath, UseRename, UseTree, Variadic, + }; + use crate::lifetime::Lifetime; + use crate::lit::LitStr; + use crate::mac::{self, Macro, MacroDelimiter}; use crate::parse::discouraged::Speculative as _; - use crate::parse::{Parse, ParseBuffer, ParseStream, Result}; + use crate::parse::{Parse, ParseBuffer, ParseStream}; + use crate::pat::{Pat, PatType, PatWild}; + use crate::path::Path; + use crate::punctuated::Punctuated; + use crate::restriction::Visibility; + use crate::stmt::Block; + use crate::token; + use crate::ty::{Abi, ReturnType, Type, TypePath, TypeReference}; + use crate::verbatim; + use proc_macro2::TokenStream; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Item { @@ -2856,9 +2892,19 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::data::Fields; + use crate::item::{ + ForeignItemFn, ForeignItemMacro, ForeignItemStatic, ForeignItemType, ImplItemConst, + ImplItemFn, ImplItemMacro, ImplItemType, ItemConst, ItemEnum, ItemExternCrate, ItemFn, + ItemForeignMod, ItemImpl, ItemMacro, ItemMod, ItemStatic, ItemStruct, ItemTrait, + ItemTraitAlias, ItemType, ItemUnion, ItemUse, Receiver, Signature, StaticMutability, + TraitItemConst, TraitItemFn, TraitItemMacro, TraitItemType, UseGlob, UseGroup, UseName, + UsePath, UseRename, Variadic, + }; + use crate::mac::MacroDelimiter; use crate::print::TokensOrDefault; + use crate::ty::Type; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/lib.rs b/src/lib.rs index 72e855270b..15c714fb5d 100644 --- a/src/lib.rs +++ b/src/lib.rs @@ -456,15 +456,9 @@ mod parse_quote; mod pat; #[cfg(feature = "full")] #[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] -pub use crate::expr::{ - ExprConst as PatConst, ExprLit as PatLit, ExprMacro as PatMacro, ExprPath as PatPath, - ExprRange as PatRange, -}; -#[cfg(feature = "full")] -#[cfg_attr(doc_cfg, doc(cfg(feature = "full")))] pub use crate::pat::{ - FieldPat, Pat, PatIdent, PatOr, PatParen, PatReference, PatRest, PatSlice, PatStruct, PatTuple, - PatTupleStruct, PatType, PatWild, + FieldPat, Pat, PatConst, PatIdent, PatLit, PatMacro, PatOr, PatParen, PatPath, PatRange, + PatReference, PatRest, PatSlice, PatStruct, PatTuple, PatTupleStruct, PatType, PatWild, }; #[cfg(any(feature = "full", feature = "derive"))] diff --git a/src/lifetime.rs b/src/lifetime.rs index 29f4cfdb3b..1df2c53482 100644 --- a/src/lifetime.rs +++ b/src/lifetime.rs @@ -1,11 +1,10 @@ +#[cfg(feature = "parsing")] +use crate::lookahead; use proc_macro2::{Ident, Span}; use std::cmp::Ordering; use std::fmt::{self, Display}; use std::hash::{Hash, Hasher}; -#[cfg(feature = "parsing")] -use crate::lookahead; - /// A Rust lifetime: `'a`. /// /// Lifetime names must conform to the following rules: @@ -123,8 +122,9 @@ pub_if_not_doc! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - use crate::parse::{Parse, ParseStream, Result}; + use crate::error::Result; + use crate::lifetime::Lifetime; + use crate::parse::{Parse, ParseStream}; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Lifetime { @@ -140,7 +140,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::lifetime::Lifetime; use proc_macro2::{Punct, Spacing, TokenStream}; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/lit.rs b/src/lit.rs index 9addf1d370..55565c7b9e 100644 --- a/src/lit.rs +++ b/src/lit.rs @@ -555,7 +555,7 @@ impl LitBool { #[cfg(feature = "extra-traits")] mod debug_impls { - use super::*; + use crate::lit::{LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr}; use std::fmt::{self, Debug}; #[cfg_attr(doc_cfg, doc(cfg(feature = "extra-traits")))] @@ -808,10 +808,14 @@ pub_if_not_doc! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; use crate::buffer::Cursor; - use crate::parse::{Parse, ParseStream, Result}; - use proc_macro2::Punct; + use crate::error::Result; + use crate::lit::{ + value, Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitFloatRepr, LitInt, + LitIntRepr, LitStr, + }; + use crate::parse::{Parse, ParseStream}; + use proc_macro2::{Literal, Punct}; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Lit { @@ -964,7 +968,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::lit::{LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitInt, LitStr}; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; @@ -1019,8 +1023,12 @@ mod printing { } mod value { - use super::*; use crate::bigint::BigInt; + use crate::lit::{ + Lit, LitBool, LitByte, LitByteStr, LitChar, LitFloat, LitFloatRepr, LitInt, LitIntRepr, + LitRepr, LitStr, + }; + use proc_macro2::{Literal, Span}; use std::char; use std::ops::{Index, RangeFrom}; diff --git a/src/mac.rs b/src/mac.rs index 8f687cc9aa..d32cce4b30 100644 --- a/src/mac.rs +++ b/src/mac.rs @@ -1,15 +1,16 @@ -use super::*; +#[cfg(feature = "parsing")] +use crate::error::Result; +#[cfg(feature = "parsing")] +use crate::parse::{Parse, ParseStream, Parser}; +use crate::path::Path; use crate::token::{Brace, Bracket, Paren}; use proc_macro2::extra::DelimSpan; -#[cfg(any(feature = "parsing", feature = "printing"))] +#[cfg(feature = "parsing")] use proc_macro2::Delimiter; use proc_macro2::TokenStream; #[cfg(feature = "parsing")] use proc_macro2::TokenTree; -#[cfg(feature = "parsing")] -use crate::parse::{Parse, ParseStream, Parser, Result}; - ast_struct! { /// A macro invocation: `println!("{}", mac)`. #[cfg_attr(doc_cfg, doc(cfg(any(feature = "full", feature = "derive"))))] @@ -162,8 +163,10 @@ pub(crate) fn parse_delimiter(input: ParseStream) -> Result<(MacroDelimiter, Tok #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - use crate::parse::{Parse, ParseStream, Result}; + use crate::error::Result; + use crate::mac::{parse_delimiter, Macro}; + use crate::parse::{Parse, ParseStream}; + use crate::path::Path; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Macro { @@ -185,8 +188,9 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; - use proc_macro2::TokenStream; + use crate::mac::{Macro, MacroDelimiter}; + use crate::token; + use proc_macro2::{Delimiter, TokenStream}; use quote::ToTokens; impl MacroDelimiter { diff --git a/src/meta.rs b/src/meta.rs index 66a0a467be..ffeeb2629f 100644 --- a/src/meta.rs +++ b/src/meta.rs @@ -1,8 +1,9 @@ //! Facility for interpreting structured content inside of an `Attribute`. +use crate::error::{Error, Result}; use crate::ext::IdentExt as _; use crate::lit::Lit; -use crate::parse::{Error, ParseStream, Parser, Result}; +use crate::parse::{ParseStream, Parser}; use crate::path::{Path, PathSegment}; use crate::punctuated::Punctuated; use proc_macro2::Ident; diff --git a/src/op.rs b/src/op.rs index c231285b95..ff83bd7963 100644 --- a/src/op.rs +++ b/src/op.rs @@ -78,8 +78,9 @@ ast_enum! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - use crate::parse::{Parse, ParseStream, Result}; + use crate::error::Result; + use crate::op::{BinOp, UnOp}; + use crate::parse::{Parse, ParseStream}; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for BinOp { @@ -165,7 +166,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::op::{BinOp, UnOp}; use proc_macro2::TokenStream; use quote::ToTokens; diff --git a/src/parse.rs b/src/parse.rs index d539e192f7..8668e0e1b7 100644 --- a/src/parse.rs +++ b/src/parse.rs @@ -185,11 +185,9 @@ pub mod discouraged; use crate::buffer::{Cursor, TokenBuffer}; use crate::error; use crate::lookahead; -#[cfg(feature = "proc-macro")] -use crate::proc_macro; use crate::punctuated::Punctuated; use crate::token::Token; -use proc_macro2::{self, Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree}; +use proc_macro2::{Delimiter, Group, Literal, Punct, Span, TokenStream, TokenTree}; use std::cell::Cell; use std::fmt::{self, Debug, Display}; #[cfg(feature = "extra-traits")] diff --git a/src/parse_quote.rs b/src/parse_quote.rs index 18de474505..1e3cacf9fe 100644 --- a/src/parse_quote.rs +++ b/src/parse_quote.rs @@ -107,7 +107,8 @@ macro_rules! parse_quote_spanned { //////////////////////////////////////////////////////////////////////////////// // Can parse any type that implements Parse. -use crate::parse::{Parse, ParseStream, Parser, Result}; +use crate::error::Result; +use crate::parse::{Parse, ParseStream, Parser}; use proc_macro2::TokenStream; // Not public API. diff --git a/src/pat.rs b/src/pat.rs index ce6399d9f5..1e95adb8ed 100644 --- a/src/pat.rs +++ b/src/pat.rs @@ -1,7 +1,17 @@ -use super::*; +use crate::attr::Attribute; +use crate::expr::Member; +use crate::ident::Ident; +use crate::path::{Path, QSelf}; use crate::punctuated::Punctuated; +use crate::token; +use crate::ty::Type; use proc_macro2::TokenStream; +pub use crate::expr::{ + ExprConst as PatConst, ExprLit as PatLit, ExprMacro as PatMacro, ExprPath as PatPath, + ExprRange as PatRange, +}; + ast_enum_of_structs! { /// A pattern in a local binding, function signature, match expression, or /// various other places. @@ -227,10 +237,26 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::Attribute; + use crate::error::{self, Result}; + use crate::expr::{ + Expr, ExprConst, ExprLit, ExprMacro, ExprPath, ExprRange, Member, RangeLimits, + }; use crate::ext::IdentExt as _; - use crate::parse::{Parse, ParseBuffer, ParseStream, Result}; - use crate::path; + use crate::ident::Ident; + use crate::lit::Lit; + use crate::mac::{self, Macro}; + use crate::parse::{Parse, ParseBuffer, ParseStream}; + use crate::pat::{ + FieldPat, Pat, PatIdent, PatOr, PatParen, PatReference, PatRest, PatSlice, PatStruct, + PatTuple, PatTupleStruct, PatType, PatWild, + }; + use crate::path::{self, Path, QSelf}; + use crate::punctuated::Punctuated; + use crate::stmt::Block; + use crate::token; + use crate::verbatim; + use proc_macro2::TokenStream; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Pat { @@ -773,8 +799,12 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::pat::{ + FieldPat, Pat, PatIdent, PatOr, PatParen, PatReference, PatRest, PatSlice, PatStruct, + PatTuple, PatTupleStruct, PatType, PatWild, + }; + use crate::path; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/path.rs b/src/path.rs index 975154a31c..3f5894583a 100644 --- a/src/path.rs +++ b/src/path.rs @@ -1,5 +1,12 @@ -use super::*; +#[cfg(feature = "parsing")] +use crate::error::Result; +use crate::expr::Expr; +use crate::generics::TypeParamBound; +use crate::ident::Ident; +use crate::lifetime::Lifetime; use crate::punctuated::Punctuated; +use crate::token; +use crate::ty::{ReturnType, Type}; ast_struct! { /// A path at which a named item is exported (e.g. `std::collections::HashMap`). @@ -275,10 +282,28 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; - + use crate::error::Result; + #[cfg(feature = "full")] + use crate::expr::ExprBlock; + use crate::expr::{Expr, ExprPath}; use crate::ext::IdentExt as _; - use crate::parse::{Parse, ParseStream, Result}; + #[cfg(feature = "full")] + use crate::generics::TypeParamBound; + use crate::ident::Ident; + use crate::lifetime::Lifetime; + use crate::lit::Lit; + use crate::parse::{Parse, ParseStream}; + #[cfg(feature = "full")] + use crate::path::Constraint; + use crate::path::{ + AngleBracketedGenericArguments, AssocConst, AssocType, GenericArgument, + ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf, + }; + use crate::punctuated::Punctuated; + use crate::token; + use crate::ty::{ReturnType, Type}; + #[cfg(not(feature = "full"))] + use crate::verbatim; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Path { @@ -663,10 +688,15 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] pub(crate) mod printing { - use super::*; + use crate::expr::Expr; + use crate::path::{ + AngleBracketedGenericArguments, AssocConst, AssocType, Constraint, GenericArgument, + ParenthesizedGenericArguments, Path, PathArguments, PathSegment, QSelf, + }; use crate::print::TokensOrDefault; #[cfg(feature = "parsing")] use crate::spanned::Spanned; + use crate::token; #[cfg(feature = "parsing")] use proc_macro2::Span; use proc_macro2::TokenStream; diff --git a/src/punctuated.rs b/src/punctuated.rs index 3ea8a1d4ee..d644354902 100644 --- a/src/punctuated.rs +++ b/src/punctuated.rs @@ -20,6 +20,13 @@ //! ~~~~^ ~~~~^ ~~~~ //! ``` +use crate::drops::{NoDrop, TrivialDrop}; +#[cfg(feature = "parsing")] +use crate::error::Result; +#[cfg(feature = "parsing")] +use crate::parse::{Parse, ParseStream}; +#[cfg(feature = "parsing")] +use crate::token::Token; #[cfg(feature = "extra-traits")] use std::fmt::{self, Debug}; #[cfg(feature = "extra-traits")] @@ -31,12 +38,6 @@ use std::option; use std::slice; use std::vec; -use crate::drops::{NoDrop, TrivialDrop}; -#[cfg(feature = "parsing")] -use crate::parse::{Parse, ParseStream, Result}; -#[cfg(feature = "parsing")] -use crate::token::Token; - /// **A punctuated sequence of syntax tree nodes of type `T` separated by /// punctuation of type `P`.** /// @@ -1074,7 +1075,7 @@ impl IndexMut for Punctuated { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::punctuated::{Pair, Punctuated}; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/restriction.rs b/src/restriction.rs index e66b17f3b5..8634607c76 100644 --- a/src/restriction.rs +++ b/src/restriction.rs @@ -1,4 +1,5 @@ -use super::*; +use crate::path::Path; +use crate::token; ast_enum! { /// The visibility level of an item: inherited or `pub` or @@ -57,10 +58,14 @@ ast_enum! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::error::Result; use crate::ext::IdentExt as _; + use crate::ident::Ident; use crate::parse::discouraged::Speculative as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream}; + use crate::path::Path; + use crate::restriction::{VisRestricted, Visibility}; + use crate::token; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] impl Parse for Visibility { @@ -141,7 +146,7 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::restriction::{VisRestricted, Visibility}; use proc_macro2::TokenStream; use quote::ToTokens; diff --git a/src/spanned.rs b/src/spanned.rs index 98aa0aa1e7..17b69e9f5b 100644 --- a/src/spanned.rs +++ b/src/spanned.rs @@ -108,7 +108,7 @@ impl Spanned for T { } mod private { - use super::*; + use crate::spanned::ToTokens; pub trait Sealed {} impl Sealed for T {} diff --git a/src/stmt.rs b/src/stmt.rs index b6d0664be7..8a987a5ec4 100644 --- a/src/stmt.rs +++ b/src/stmt.rs @@ -1,4 +1,9 @@ -use super::*; +use crate::attr::Attribute; +use crate::expr::Expr; +use crate::item::Item; +use crate::mac::Macro; +use crate::pat::Pat; +use crate::token; ast_struct! { /// A braced block containing Rust statements. @@ -74,9 +79,19 @@ ast_struct! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::Attribute; + use crate::error::Result; + use crate::expr::{self, Expr, ExprBlock, ExprMacro}; + use crate::ident::Ident; + use crate::item; + use crate::mac::{self, Macro}; use crate::parse::discouraged::Speculative as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::parse::{Parse, ParseStream}; + use crate::pat::{Pat, PatType}; + use crate::path::Path; + use crate::stmt::{Block, Local, LocalInit, Stmt, StmtMacro}; + use crate::token; + use crate::ty::Type; use proc_macro2::TokenStream; struct AllowNoSemi(bool); @@ -395,7 +410,8 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; + use crate::expr; + use crate::stmt::{Block, Local, Stmt, StmtMacro}; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt}; diff --git a/src/ty.rs b/src/ty.rs index 3213e7f3b7..50aaafb148 100644 --- a/src/ty.rs +++ b/src/ty.rs @@ -1,5 +1,13 @@ -use super::*; +use crate::attr::Attribute; +use crate::expr::Expr; +use crate::generics::{BoundLifetimes, TypeParamBound}; +use crate::ident::Ident; +use crate::lifetime::Lifetime; +use crate::lit::LitStr; +use crate::mac::Macro; +use crate::path::{Path, QSelf}; use crate::punctuated::Punctuated; +use crate::token; use proc_macro2::TokenStream; ast_enum_of_structs! { @@ -264,10 +272,24 @@ ast_enum! { #[cfg(feature = "parsing")] pub(crate) mod parsing { - use super::*; + use crate::attr::Attribute; + use crate::error::{self, Result}; use crate::ext::IdentExt as _; - use crate::parse::{Parse, ParseStream, Result}; + use crate::generics::{BoundLifetimes, TraitBound, TraitBoundModifier, TypeParamBound}; + use crate::ident::Ident; + use crate::lifetime::Lifetime; + use crate::mac::{self, Macro}; + use crate::parse::{Parse, ParseStream}; use crate::path; + use crate::path::{Path, PathArguments, QSelf}; + use crate::punctuated::Punctuated; + use crate::token; + use crate::ty::{ + Abi, BareFnArg, BareVariadic, ReturnType, Type, TypeArray, TypeBareFn, TypeGroup, + TypeImplTrait, TypeInfer, TypeMacro, TypeNever, TypeParen, TypePath, TypePtr, + TypeReference, TypeSlice, TypeTraitObject, TypeTuple, + }; + use crate::verbatim; use proc_macro2::Span; #[cfg_attr(doc_cfg, doc(cfg(feature = "parsing")))] @@ -994,9 +1016,14 @@ pub(crate) mod parsing { #[cfg(feature = "printing")] mod printing { - use super::*; use crate::attr::FilterAttrs; + use crate::path; use crate::print::TokensOrDefault; + use crate::ty::{ + Abi, BareFnArg, BareVariadic, ReturnType, TypeArray, TypeBareFn, TypeGroup, TypeImplTrait, + TypeInfer, TypeMacro, TypeNever, TypeParen, TypePath, TypePtr, TypeReference, TypeSlice, + TypeTraitObject, TypeTuple, + }; use proc_macro2::TokenStream; use quote::{ToTokens, TokenStreamExt};