Skip to content

Commit

Permalink
Eliminate glob imports
Browse files Browse the repository at this point in the history
  • Loading branch information
dtolnay committed Feb 19, 2024
1 parent 6eb82a9 commit 713f932
Showing 25 changed files with 418 additions and 110 deletions.
31 changes: 21 additions & 10 deletions src/attr.rs
Original file line number Diff line number Diff line change
@@ -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<Attribute>) -> 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;

29 changes: 24 additions & 5 deletions src/data.rs
Original file line number Diff line number Diff line change
@@ -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};
22 changes: 18 additions & 4 deletions src/derive.rs
Original file line number Diff line number Diff line change
@@ -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;
8 changes: 7 additions & 1 deletion src/discouraged.rs
Original file line number Diff line number Diff line change
@@ -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 {
84 changes: 76 additions & 8 deletions src/expr.rs
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion src/ext.rs
Original file line number Diff line number Diff line change
@@ -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;
11 changes: 7 additions & 4 deletions src/file.rs
Original file line number Diff line number Diff line change
@@ -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};

31 changes: 27 additions & 4 deletions src/generics.rs
Original file line number Diff line number Diff line change
@@ -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};
3 changes: 2 additions & 1 deletion src/ident.rs
Original file line number Diff line number Diff line change
@@ -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;

Loading

0 comments on commit 713f932

Please sign in to comment.