From 74804fa3e706d6217127bc6b8d2bf019a4653e74 Mon Sep 17 00:00:00 2001 From: Mazdak Farrokhzad Date: Thu, 5 Dec 2019 06:38:06 +0100 Subject: [PATCH] rustc_parser: cleanup imports --- Cargo.lock | 1 - src/librustc_parse/Cargo.toml | 9 ++++---- src/librustc_parse/config.rs | 2 +- src/librustc_parse/lexer/mod.rs | 15 +++++++------- src/librustc_parse/lexer/tokentrees.rs | 8 +++----- src/librustc_parse/lexer/unicode_chars.rs | 4 ++-- src/librustc_parse/lib.rs | 4 ++-- src/librustc_parse/parser/attr.rs | 2 +- src/librustc_parse/parser/diagnostics.rs | 25 ++++++++++------------- src/librustc_parse/parser/expr.rs | 17 +++++++-------- src/librustc_parse/parser/generics.rs | 2 +- src/librustc_parse/parser/item.rs | 7 +++---- src/librustc_parse/parser/mod.rs | 13 +++++------- src/librustc_parse/parser/module.rs | 5 ++--- src/librustc_parse/parser/pat.rs | 4 ++-- src/librustc_parse/parser/path.rs | 4 ++-- src/librustc_parse/parser/stmt.rs | 6 +++--- src/librustc_parse/parser/ty.rs | 8 +++----- src/librustc_parse/validate_attr.rs | 2 +- 19 files changed, 60 insertions(+), 78 deletions(-) diff --git a/Cargo.lock b/Cargo.lock index 5e83513af5b..26727c5c1db 100644 --- a/Cargo.lock +++ b/Cargo.lock @@ -3806,7 +3806,6 @@ dependencies = [ "rustc_errors", "rustc_feature", "rustc_lexer", - "rustc_target", "smallvec 1.0.0", "syntax", "syntax_pos", diff --git a/src/librustc_parse/Cargo.toml b/src/librustc_parse/Cargo.toml index 95b3256f53a..fb5cb742ab6 100644 --- a/src/librustc_parse/Cargo.toml +++ b/src/librustc_parse/Cargo.toml @@ -12,12 +12,11 @@ doctest = false [dependencies] bitflags = "1.0" log = "0.4" -syntax_pos = { path = "../libsyntax_pos" } -syntax = { path = "../libsyntax" } -errors = { path = "../librustc_errors", package = "rustc_errors" } rustc_data_structures = { path = "../librustc_data_structures" } rustc_feature = { path = "../librustc_feature" } rustc_lexer = { path = "../librustc_lexer" } -rustc_target = { path = "../librustc_target" } -smallvec = { version = "1.0", features = ["union", "may_dangle"] } +rustc_errors = { path = "../librustc_errors" } rustc_error_codes = { path = "../librustc_error_codes" } +smallvec = { version = "1.0", features = ["union", "may_dangle"] } +syntax_pos = { path = "../libsyntax_pos" } +syntax = { path = "../libsyntax" } diff --git a/src/librustc_parse/config.rs b/src/librustc_parse/config.rs index 1bf6e9ecbc0..30e056e52d2 100644 --- a/src/librustc_parse/config.rs +++ b/src/librustc_parse/config.rs @@ -10,6 +10,7 @@ use crate::validate_attr; use rustc_feature::Features; +use rustc_errors::Applicability; use syntax::attr::HasAttrs; use syntax::feature_gate::{feature_err, get_features}; use syntax::attr; @@ -21,7 +22,6 @@ use syntax::sess::ParseSess; use syntax::util::map_in_place::MapInPlace; use syntax_pos::symbol::sym; -use errors::Applicability; use smallvec::SmallVec; /// A folder that strips out items that do not belong in the current configuration. diff --git a/src/librustc_parse/lexer/mod.rs b/src/librustc_parse/lexer/mod.rs index 5de63cb39d1..ddcfea18980 100644 --- a/src/librustc_parse/lexer/mod.rs +++ b/src/librustc_parse/lexer/mod.rs @@ -1,16 +1,15 @@ -use syntax::token::{self, Token, TokenKind}; -use syntax::sess::ParseSess; -use syntax::symbol::{sym, Symbol}; -use syntax::util::comments; - -use errors::{FatalError, DiagnosticBuilder}; -use syntax_pos::{BytePos, Pos, Span}; +use rustc_data_structures::sync::Lrc; +use rustc_errors::{FatalError, DiagnosticBuilder}; use rustc_lexer::Base; use rustc_lexer::unescape; +use syntax::token::{self, Token, TokenKind}; +use syntax::sess::ParseSess; +use syntax::util::comments; +use syntax_pos::symbol::{sym, Symbol}; +use syntax_pos::{BytePos, Pos, Span}; use std::char; use std::convert::TryInto; -use rustc_data_structures::sync::Lrc; use log::debug; mod tokentrees; diff --git a/src/librustc_parse/lexer/tokentrees.rs b/src/librustc_parse/lexer/tokentrees.rs index 1353591308b..5791c6396c5 100644 --- a/src/librustc_parse/lexer/tokentrees.rs +++ b/src/librustc_parse/lexer/tokentrees.rs @@ -1,13 +1,11 @@ -use rustc_data_structures::fx::FxHashMap; -use syntax_pos::Span; - use super::{StringReader, UnmatchedBrace}; +use rustc_data_structures::fx::FxHashMap; +use rustc_errors::PResult; use syntax::print::pprust::token_to_string; use syntax::token::{self, Token}; use syntax::tokenstream::{DelimSpan, IsJoint::{self, *}, TokenStream, TokenTree, TreeAndJoint}; - -use errors::PResult; +use syntax_pos::Span; impl<'a> StringReader<'a> { crate fn into_token_trees(self) -> (PResult<'a, TokenStream>, Vec) { diff --git a/src/librustc_parse/lexer/unicode_chars.rs b/src/librustc_parse/lexer/unicode_chars.rs index 6eb995b61d3..edfebc7de94 100644 --- a/src/librustc_parse/lexer/unicode_chars.rs +++ b/src/librustc_parse/lexer/unicode_chars.rs @@ -2,9 +2,9 @@ // http://www.unicode.org/Public/security/10.0.0/confusables.txt use super::StringReader; -use errors::{Applicability, DiagnosticBuilder}; -use syntax_pos::{BytePos, Pos, Span, symbol::kw}; use crate::token; +use rustc_errors::{Applicability, DiagnosticBuilder}; +use syntax_pos::{BytePos, Pos, Span, symbol::kw}; #[rustfmt::skip] // for line breaks const UNICODE_ARRAY: &[(char, &str, char)] = &[ diff --git a/src/librustc_parse/lib.rs b/src/librustc_parse/lib.rs index a22b383e5f3..a222f3f00c4 100644 --- a/src/librustc_parse/lib.rs +++ b/src/librustc_parse/lib.rs @@ -8,7 +8,7 @@ use syntax::sess::ParseSess; use syntax::token::{self, Nonterminal}; use syntax::tokenstream::{self, TokenStream, TokenTree}; -use errors::{PResult, FatalError, Level, Diagnostic}; +use rustc_errors::{PResult, FatalError, Level, Diagnostic}; use rustc_data_structures::sync::Lrc; use syntax_pos::{Span, SourceFile, FileName}; @@ -53,7 +53,7 @@ pub enum DirectoryOwnership { macro_rules! panictry_buffer { ($handler:expr, $e:expr) => ({ use std::result::Result::{Ok, Err}; - use errors::FatalError; + use rustc_errors::FatalError; match $e { Ok(e) => e, Err(errs) => { diff --git a/src/librustc_parse/parser/attr.rs b/src/librustc_parse/parser/attr.rs index c7261404f54..b2ae934ce64 100644 --- a/src/librustc_parse/parser/attr.rs +++ b/src/librustc_parse/parser/attr.rs @@ -1,10 +1,10 @@ use super::{SeqSep, Parser, TokenType, PathStyle}; +use rustc_errors::PResult; use syntax::attr; use syntax::ast; use syntax::util::comments; use syntax::token::{self, Nonterminal}; use syntax_pos::{Span, Symbol}; -use errors::PResult; use log::debug; diff --git a/src/librustc_parse/parser/diagnostics.rs b/src/librustc_parse/parser/diagnostics.rs index da8bf89ebf3..ba125cacab4 100644 --- a/src/librustc_parse/parser/diagnostics.rs +++ b/src/librustc_parse/parser/diagnostics.rs @@ -1,25 +1,22 @@ use super::{BlockMode, PathStyle, SemiColonMode, TokenType, TokenExpectType, SeqSep, Parser}; -use syntax::ast::{ - self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item, ItemKind, - Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind, -}; +use rustc_data_structures::fx::FxHashSet; +use rustc_errors::{self, PResult, Applicability, DiagnosticBuilder, Handler, pluralize}; +use rustc_error_codes::*; +use syntax::ast::{self, Param, BinOpKind, BindingMode, BlockCheckMode, Expr, ExprKind, Ident, Item}; +use syntax::ast::{ItemKind, Mutability, Pat, PatKind, PathSegment, QSelf, Ty, TyKind}; use syntax::token::{self, TokenKind, token_can_begin_expr}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::symbol::{kw, sym}; use syntax::ThinVec; use syntax::util::parser::AssocOp; use syntax::struct_span_err; - -use errors::{PResult, Applicability, DiagnosticBuilder, pluralize}; -use rustc_data_structures::fx::FxHashSet; +use syntax_pos::symbol::{kw, sym}; use syntax_pos::{Span, DUMMY_SP, MultiSpan, SpanSnippetError}; + use log::{debug, trace}; use std::mem; -use rustc_error_codes::*; - const TURBOFISH: &'static str = "use `::<...>` instead of `<...>` to specify type arguments"; /// Creates a placeholder argument. @@ -61,10 +58,10 @@ pub enum Error { } impl Error { - fn span_err>( + fn span_err( self, - sp: S, - handler: &errors::Handler, + sp: impl Into, + handler: &Handler, ) -> DiagnosticBuilder<'_> { match self { Error::FileNotFoundForModule { @@ -212,7 +209,7 @@ impl<'a> Parser<'a> { self.sess.span_diagnostic.span_bug(sp, m) } - pub(super) fn diagnostic(&self) -> &'a errors::Handler { + pub(super) fn diagnostic(&self) -> &'a Handler { &self.sess.span_diagnostic } diff --git a/src/librustc_parse/parser/expr.rs b/src/librustc_parse/parser/expr.rs index 1112274dc46..3cd4988ce0b 100644 --- a/src/librustc_parse/parser/expr.rs +++ b/src/librustc_parse/parser/expr.rs @@ -4,23 +4,20 @@ use super::pat::{GateOr, PARAM_EXPECTED}; use super::diagnostics::Error; use crate::maybe_recover_from_interpolated_ty_qpath; -use syntax::ast::{ - self, DUMMY_NODE_ID, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode, - Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm, Ty, TyKind, - FunctionRetTy, Param, FnDecl, BinOpKind, BinOp, UnOp, Mac, AnonConst, Field, Lit, -}; +use rustc_data_structures::thin_vec::ThinVec; +use rustc_errors::{PResult, Applicability}; +use syntax::ast::{self, DUMMY_NODE_ID, Attribute, AttrStyle, Ident, CaptureBy, BlockCheckMode}; +use syntax::ast::{Expr, ExprKind, RangeLimits, Label, Movability, IsAsync, Arm, Ty, TyKind}; +use syntax::ast::{FunctionRetTy, Param, FnDecl, BinOpKind, BinOp, UnOp, Mac, AnonConst, Field, Lit}; use syntax::token::{self, Token, TokenKind}; use syntax::print::pprust; use syntax::ptr::P; -use syntax::source_map::{self, Span}; use syntax::util::classify; use syntax::util::literal::LitError; use syntax::util::parser::{AssocOp, Fixity, prec_let_scrutinee_needs_par}; -use syntax_pos::symbol::{kw, sym}; -use syntax_pos::Symbol; -use errors::{PResult, Applicability}; +use syntax_pos::source_map::{self, Span}; +use syntax_pos::symbol::{kw, sym, Symbol}; use std::mem; -use rustc_data_structures::thin_vec::ThinVec; /// Possibly accepts an `token::Interpolated` expression (a pre-parsed expression /// dropped into the token stream, which happens while parsing the result of diff --git a/src/librustc_parse/parser/generics.rs b/src/librustc_parse/parser/generics.rs index ba5eafc0ed7..32819cca42b 100644 --- a/src/librustc_parse/parser/generics.rs +++ b/src/librustc_parse/parser/generics.rs @@ -1,11 +1,11 @@ use super::Parser; +use rustc_errors::PResult; use syntax::ast::{self, WhereClause, GenericParam, GenericParamKind, GenericBounds, Attribute}; use syntax::token; use syntax::source_map::DUMMY_SP; use syntax_pos::symbol::{kw, sym}; -use errors::PResult; impl<'a> Parser<'a> { /// Parses bounds of a lifetime parameter `BOUND + BOUND + BOUND`, possibly with trailing `+`. diff --git a/src/librustc_parse/parser/item.rs b/src/librustc_parse/parser/item.rs index 66a13527421..ccf78e6402b 100644 --- a/src/librustc_parse/parser/item.rs +++ b/src/librustc_parse/parser/item.rs @@ -3,6 +3,8 @@ use super::diagnostics::{Error, dummy_arg, ConsumeClosingDelim}; use crate::maybe_whole; +use rustc_errors::{PResult, Applicability, DiagnosticBuilder, StashKey}; +use rustc_error_codes::*; use syntax::ast::{self, DUMMY_NODE_ID, Ident, Attribute, AttrKind, AttrStyle, AnonConst, Item}; use syntax::ast::{ItemKind, ImplItem, ImplItemKind, TraitItem, TraitItemKind, UseTree, UseTreeKind}; use syntax::ast::{PathSegment, IsAuto, Constness, IsAsync, Unsafety, Defaultness, Extern, StrLit}; @@ -14,16 +16,13 @@ use syntax::ptr::P; use syntax::ThinVec; use syntax::token; use syntax::tokenstream::{DelimSpan, TokenTree, TokenStream}; -use syntax::source_map::{self, respan, Span}; use syntax::struct_span_err; use syntax_pos::BytePos; +use syntax_pos::source_map::{self, respan, Span}; use syntax_pos::symbol::{kw, sym, Symbol}; -use rustc_error_codes::*; - use log::debug; use std::mem; -use errors::{PResult, Applicability, DiagnosticBuilder, StashKey}; pub(super) type ItemInfo = (Ident, ItemKind, Option>); diff --git a/src/librustc_parse/parser/mod.rs b/src/librustc_parse/parser/mod.rs index 28689720044..07e99cfe012 100644 --- a/src/librustc_parse/parser/mod.rs +++ b/src/librustc_parse/parser/mod.rs @@ -14,23 +14,20 @@ use diagnostics::Error; use crate::{Directory, DirectoryOwnership}; use crate::lexer::UnmatchedBrace; -use syntax::ast::{ - self, DUMMY_NODE_ID, AttrStyle, Attribute, CrateSugar, Extern, Ident, StrLit, - IsAsync, MacArgs, MacDelimiter, Mutability, Visibility, VisibilityKind, Unsafety, -}; - +use rustc_errors::{PResult, Applicability, DiagnosticBuilder, FatalError}; +use rustc_data_structures::thin_vec::ThinVec; +use syntax::ast::{self, DUMMY_NODE_ID, AttrStyle, Attribute, CrateSugar, Extern, Ident, StrLit}; +use syntax::ast::{IsAsync, MacArgs, MacDelimiter, Mutability, Visibility, VisibilityKind, Unsafety}; use syntax::print::pprust; use syntax::ptr::P; use syntax::token::{self, Token, TokenKind, DelimToken}; use syntax::tokenstream::{self, DelimSpan, TokenTree, TokenStream, TreeAndJoint}; use syntax::sess::ParseSess; -use syntax::source_map::respan; use syntax::struct_span_err; use syntax::util::comments::{doc_comment_style, strip_doc_comment_decoration}; +use syntax_pos::source_map::respan; use syntax_pos::symbol::{kw, sym, Symbol}; use syntax_pos::{Span, BytePos, DUMMY_SP, FileName}; -use rustc_data_structures::thin_vec::ThinVec; -use errors::{PResult, Applicability, DiagnosticBuilder, FatalError}; use log::debug; use std::borrow::Cow; diff --git a/src/librustc_parse/parser/module.rs b/src/librustc_parse/parser/module.rs index 59d7c2b4239..5b8526caa41 100644 --- a/src/librustc_parse/parser/module.rs +++ b/src/librustc_parse/parser/module.rs @@ -4,13 +4,12 @@ use super::diagnostics::Error; use crate::{new_sub_parser_from_file, DirectoryOwnership}; +use rustc_errors::PResult; use syntax::attr; use syntax::ast::{self, Ident, Attribute, ItemKind, Mod, Crate}; use syntax::token::{self, TokenKind}; -use syntax::source_map::{SourceMap, Span, DUMMY_SP, FileName}; - +use syntax_pos::source_map::{SourceMap, Span, DUMMY_SP, FileName}; use syntax_pos::symbol::sym; -use errors::PResult; use std::path::{self, Path, PathBuf}; diff --git a/src/librustc_parse/parser/pat.rs b/src/librustc_parse/parser/pat.rs index 1127c4b2d5f..42ece96adb9 100644 --- a/src/librustc_parse/parser/pat.rs +++ b/src/librustc_parse/parser/pat.rs @@ -1,5 +1,6 @@ use super::{Parser, PathStyle}; use crate::{maybe_recover_from_interpolated_ty_qpath, maybe_whole}; +use rustc_errors::{PResult, Applicability, DiagnosticBuilder}; use syntax::ast::{self, Attribute, Pat, PatKind, FieldPat, RangeEnd, RangeSyntax, Mac}; use syntax::ast::{BindingMode, Ident, Mutability, Path, QSelf, Expr, ExprKind}; use syntax::mut_visit::{noop_visit_pat, noop_visit_mac, MutVisitor}; @@ -7,9 +8,8 @@ use syntax::ptr::P; use syntax::print::pprust; use syntax::ThinVec; use syntax::token; -use syntax::source_map::{respan, Span, Spanned}; +use syntax_pos::source_map::{respan, Span, Spanned}; use syntax_pos::symbol::{kw, sym}; -use errors::{PResult, Applicability, DiagnosticBuilder}; type Expected = Option<&'static str>; diff --git a/src/librustc_parse/parser/path.rs b/src/librustc_parse/parser/path.rs index 75bb67d47bc..70c3458e7c0 100644 --- a/src/librustc_parse/parser/path.rs +++ b/src/librustc_parse/parser/path.rs @@ -1,16 +1,16 @@ use super::{Parser, TokenType}; use crate::maybe_whole; +use rustc_errors::{PResult, Applicability, pluralize}; use syntax::ast::{self, QSelf, Path, PathSegment, Ident, ParenthesizedArgs, AngleBracketedArgs}; use syntax::ast::{AnonConst, GenericArg, AssocTyConstraint, AssocTyConstraintKind, BlockCheckMode}; use syntax::ast::MacArgs; use syntax::ThinVec; use syntax::token::{self, Token}; -use syntax::source_map::{Span, BytePos}; +use syntax_pos::source_map::{Span, BytePos}; use syntax_pos::symbol::{kw, sym}; use std::mem; use log::debug; -use errors::{PResult, Applicability, pluralize}; /// Specifies how to parse a path. #[derive(Copy, Clone, PartialEq)] diff --git a/src/librustc_parse/parser/stmt.rs b/src/librustc_parse/parser/stmt.rs index b952e8814a3..943b6ecc825 100644 --- a/src/librustc_parse/parser/stmt.rs +++ b/src/librustc_parse/parser/stmt.rs @@ -6,6 +6,7 @@ use super::diagnostics::Error; use crate::maybe_whole; use crate::DirectoryOwnership; +use rustc_errors::{PResult, Applicability}; use syntax::ThinVec; use syntax::ptr::P; use syntax::ast; @@ -13,11 +14,10 @@ use syntax::ast::{DUMMY_NODE_ID, Stmt, StmtKind, Local, Block, BlockCheckMode, E use syntax::ast::{Attribute, AttrStyle, VisibilityKind, MacStmtStyle, Mac}; use syntax::util::classify; use syntax::token; -use syntax::source_map::{respan, Span}; -use syntax::symbol::{kw, sym}; +use syntax_pos::source_map::{respan, Span}; +use syntax_pos::symbol::{kw, sym}; use std::mem; -use errors::{PResult, Applicability}; impl<'a> Parser<'a> { /// Parses a statement. This stops just before trailing semicolons on everything but items. diff --git a/src/librustc_parse/parser/ty.rs b/src/librustc_parse/parser/ty.rs index 32142796905..84ffef68e9a 100644 --- a/src/librustc_parse/parser/ty.rs +++ b/src/librustc_parse/parser/ty.rs @@ -3,19 +3,17 @@ use super::item::ParamCfg; use crate::{maybe_whole, maybe_recover_from_interpolated_ty_qpath}; +use rustc_errors::{PResult, Applicability, pluralize}; +use rustc_error_codes::*; use syntax::ptr::P; use syntax::ast::{self, Ty, TyKind, MutTy, BareFnTy, FunctionRetTy, GenericParam, Lifetime, Ident}; use syntax::ast::{TraitBoundModifier, TraitObjectSyntax, GenericBound, GenericBounds, PolyTraitRef}; use syntax::ast::{Mutability, AnonConst, Mac}; use syntax::token::{self, Token}; -use syntax::source_map::Span; use syntax::struct_span_fatal; +use syntax_pos::source_map::Span; use syntax_pos::symbol::kw; -use errors::{PResult, Applicability, pluralize}; - -use rustc_error_codes::*; - /// Returns `true` if `IDENT t` can start a type -- `IDENT::a::b`, `IDENT`, /// `IDENT<::AssocTy>`. /// diff --git a/src/librustc_parse/validate_attr.rs b/src/librustc_parse/validate_attr.rs index 8601add3f6f..97e9cb8dcdf 100644 --- a/src/librustc_parse/validate_attr.rs +++ b/src/librustc_parse/validate_attr.rs @@ -1,6 +1,6 @@ //! Meta-syntax validation logic of attributes for post-expansion. -use errors::{PResult, Applicability}; +use rustc_errors::{PResult, Applicability}; use rustc_feature::{AttributeTemplate, BUILTIN_ATTRIBUTE_MAP}; use syntax::ast::{self, Attribute, AttrKind, Ident, MacArgs, MetaItem, MetaItemKind}; use syntax::attr::mk_name_value_item_str;