From edbd8a36c8820fb8a128675859c1fa76feab2bea Mon Sep 17 00:00:00 2001 From: Taiki Endo Date: Thu, 7 Feb 2019 02:15:23 +0900 Subject: [PATCH] librustc_resolve => 2018 --- src/librustc_resolve/Cargo.toml | 1 + src/librustc_resolve/build_reduced_graph.rs | 20 +++-- src/librustc_resolve/check_unused.rs | 6 +- src/librustc_resolve/diagnostics.rs | 2 + src/librustc_resolve/error_reporting.rs | 8 +- src/librustc_resolve/lib.rs | 93 ++++++++++----------- src/librustc_resolve/macros.rs | 23 ++--- src/librustc_resolve/resolve_imports.rs | 30 ++++--- 8 files changed, 95 insertions(+), 88 deletions(-) diff --git a/src/librustc_resolve/Cargo.toml b/src/librustc_resolve/Cargo.toml index 3a8e84a3280..0ce82f2ce52 100644 --- a/src/librustc_resolve/Cargo.toml +++ b/src/librustc_resolve/Cargo.toml @@ -2,6 +2,7 @@ authors = ["The Rust Project Developers"] name = "rustc_resolve" version = "0.0.0" +edition = "2018" [lib] name = "rustc_resolve" diff --git a/src/librustc_resolve/build_reduced_graph.rs b/src/librustc_resolve/build_reduced_graph.rs index c5401ac3f55..750eb35a988 100644 --- a/src/librustc_resolve/build_reduced_graph.rs +++ b/src/librustc_resolve/build_reduced_graph.rs @@ -3,14 +3,15 @@ //! Here we build the "reduced graph": the graph of the module tree without //! any imports resolved. -use macros::{InvocationData, ParentScope, LegacyScope}; -use resolve_imports::ImportDirective; -use resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport}; -use {Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segment, ToNameBinding}; -use {ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas, ExternPreludeEntry}; -use Namespace::{self, TypeNS, ValueNS, MacroNS}; -use {resolve_error, resolve_struct_error, ResolutionError}; +use crate::macros::{InvocationData, ParentScope, LegacyScope}; +use crate::resolve_imports::ImportDirective; +use crate::resolve_imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport}; +use crate::{Module, ModuleData, ModuleKind, NameBinding, NameBindingKind, Segment, ToNameBinding}; +use crate::{ModuleOrUniformRoot, PerNS, Resolver, ResolverArenas, ExternPreludeEntry}; +use crate::Namespace::{self, TypeNS, ValueNS, MacroNS}; +use crate::{resolve_error, resolve_struct_error, ResolutionError}; +use rustc::bug; use rustc::hir::def::*; use rustc::hir::def_id::{CrateNum, CRATE_DEF_INDEX, LOCAL_CRATE, DefId}; use rustc::ty; @@ -21,7 +22,7 @@ use std::cell::Cell; use std::ptr; use rustc_data_structures::sync::Lrc; -use errors::Applicability; +use crate::errors::Applicability; use syntax::ast::{Name, Ident}; use syntax::attr; @@ -34,12 +35,15 @@ use syntax::ext::hygiene::Mark; use syntax::ext::tt::macro_rules; use syntax::feature_gate::is_builtin_attr; use syntax::parse::token::{self, Token}; +use syntax::span_err; use syntax::std_inject::injected_crate_name; use syntax::symbol::keywords; use syntax::visit::{self, Visitor}; use syntax_pos::{Span, DUMMY_SP}; +use log::debug; + impl<'a> ToNameBinding<'a> for (Module<'a>, ty::Visibility, Span, Mark) { fn to_name_binding(self, arenas: &'a ResolverArenas<'a>) -> &'a NameBinding<'a> { arenas.alloc_name_binding(NameBinding { diff --git a/src/librustc_resolve/check_unused.rs b/src/librustc_resolve/check_unused.rs index 16d8a95c003..639960827c9 100644 --- a/src/librustc_resolve/check_unused.rs +++ b/src/librustc_resolve/check_unused.rs @@ -10,8 +10,8 @@ use std::ops::{Deref, DerefMut}; -use Resolver; -use resolve_imports::ImportDirectiveSubclass; +use crate::Resolver; +use crate::resolve_imports::ImportDirectiveSubclass; use rustc::{lint, ty}; use rustc::util::nodemap::NodeMap; @@ -113,7 +113,7 @@ impl<'a, 'b> Visitor<'a> for UnusedImportCheckVisitor<'a, 'b> { } } -pub fn check_crate(resolver: &mut Resolver, krate: &ast::Crate) { +pub fn check_crate(resolver: &mut Resolver<'_>, krate: &ast::Crate) { for directive in resolver.potentially_unused_imports.iter() { match directive.subclass { _ if directive.used.get() || diff --git a/src/librustc_resolve/diagnostics.rs b/src/librustc_resolve/diagnostics.rs index 3f9c5f4fd27..0db8689c0c1 100644 --- a/src/librustc_resolve/diagnostics.rs +++ b/src/librustc_resolve/diagnostics.rs @@ -1,5 +1,7 @@ #![allow(non_snake_case)] +use syntax::{register_diagnostic, register_diagnostics, register_long_diagnostics}; + // Error messages for EXXXX errors. Each message should start and end with a // new line, and be wrapped to 80 characters. In vim you can `:set tw=80` and // use `gq` to wrap paragraphs. Use `:set tw=0` to disable. diff --git a/src/librustc_resolve/error_reporting.rs b/src/librustc_resolve/error_reporting.rs index 2a8e95536b8..b131a6b62f9 100644 --- a/src/librustc_resolve/error_reporting.rs +++ b/src/librustc_resolve/error_reporting.rs @@ -1,10 +1,12 @@ -use {CrateLint, PathResult, Segment}; -use macros::ParentScope; +use crate::{CrateLint, PathResult, Segment}; +use crate::macros::ParentScope; +use crate::resolve_imports::ImportResolver; use syntax::symbol::keywords; use syntax_pos::Span; -use resolve_imports::ImportResolver; +use log::debug; + use std::cmp::Reverse; impl<'a, 'b:'a> ImportResolver<'a, 'b> { diff --git a/src/librustc_resolve/lib.rs b/src/librustc_resolve/lib.rs index 3973bc2ad62..b166b1be02f 100644 --- a/src/librustc_resolve/lib.rs +++ b/src/librustc_resolve/lib.rs @@ -4,30 +4,19 @@ #![feature(crate_visibility_modifier)] #![feature(label_break_value)] -#![feature(nll)] #![feature(rustc_diagnostic_macros)] #![feature(slice_sort_by_cached_key)] #![recursion_limit="256"] -#[macro_use] -extern crate bitflags; -#[macro_use] -extern crate log; -#[macro_use] -extern crate syntax; -extern crate syntax_pos; -extern crate rustc_errors as errors; -extern crate arena; -#[macro_use] -extern crate rustc; -extern crate rustc_data_structures; -extern crate rustc_metadata; +#![deny(rust_2018_idioms)] + +use rustc_errors as errors; pub use rustc::hir::def::{Namespace, PerNS}; -use self::TypeParameters::*; -use self::RibKind::*; +use TypeParameters::*; +use RibKind::*; use rustc::hir::map::{Definitions, DefCollector}; use rustc::hir::{self, PrimTy, Bool, Char, Float, Int, Uint, Str}; @@ -41,6 +30,7 @@ use rustc::hir::{Freevar, FreevarMap, TraitCandidate, TraitMap, GlobMap}; use rustc::session::config::nightly_options; use rustc::ty; use rustc::util::nodemap::{NodeMap, NodeSet, FxHashMap, FxHashSet, DefIdMap}; +use rustc::{bug, span_bug}; use rustc_metadata::creader::CrateLoader; use rustc_metadata::cstore::CStore; @@ -62,10 +52,13 @@ use syntax::ast::{Item, ItemKind, ImplItem, ImplItemKind}; use syntax::ast::{Label, Local, Mutability, Pat, PatKind, Path}; use syntax::ast::{QSelf, TraitItemKind, TraitRef, Ty, TyKind}; use syntax::ptr::P; +use syntax::{span_err, struct_span_err, unwrap_or, walk_list}; use syntax_pos::{BytePos, Span, DUMMY_SP, MultiSpan}; use errors::{Applicability, DiagnosticBuilder, DiagnosticId}; +use log::debug; + use std::cell::{Cell, RefCell}; use std::{cmp, fmt, iter, mem, ptr}; use std::collections::BTreeSet; @@ -191,13 +184,13 @@ enum ResolutionError<'a> { /// /// This takes the error provided, combines it with the span and any additional spans inside the /// error and emits it. -fn resolve_error<'sess, 'a>(resolver: &'sess Resolver, +fn resolve_error<'sess, 'a>(resolver: &'sess Resolver<'_>, span: Span, resolution_error: ResolutionError<'a>) { resolve_struct_error(resolver, span, resolution_error).emit(); } -fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver, +fn resolve_struct_error<'sess, 'a>(resolver: &'sess Resolver<'_>, span: Span, resolution_error: ResolutionError<'a>) -> DiagnosticBuilder<'sess> { @@ -1192,7 +1185,7 @@ impl<'a> ModuleData<'a> { } impl<'a> fmt::Debug for ModuleData<'a> { - fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { write!(f, "{:?}", self.def()) } } @@ -1416,7 +1409,7 @@ impl<'a> NameBinding<'a> { // in some later round and screw up our previously found resolution. // See more detailed explanation in // https://github.com/rust-lang/rust/pull/53778#issuecomment-419224049 - fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding) -> bool { + fn may_appear_after(&self, invoc_parent_expansion: Mark, binding: &NameBinding<'_>) -> bool { // self > max(invoc, binding) => !(self <= invoc || self <= binding) // Expansions are partially ordered, so "may appear after" is an inversion of // "certainly appears before or simultaneously" and includes unordered cases. @@ -1630,14 +1623,14 @@ impl<'a> ResolverArenas<'a> { } module } - fn local_modules(&'a self) -> ::std::cell::Ref<'a, Vec>> { + fn local_modules(&'a self) -> std::cell::Ref<'a, Vec>> { self.local_modules.borrow() } fn alloc_name_binding(&'a self, name_binding: NameBinding<'a>) -> &'a NameBinding<'a> { self.name_bindings.alloc(name_binding) } fn alloc_import_directive(&'a self, import_directive: ImportDirective<'a>) - -> &'a ImportDirective { + -> &'a ImportDirective<'_> { self.import_directives.alloc(import_directive) } fn alloc_name_resolution(&'a self) -> &'a RefCell> { @@ -1754,7 +1747,7 @@ impl<'a> Resolver<'a> { is_value: bool, error_callback: F, ) -> hir::Path - where F: for<'c, 'b> FnOnce(&'c mut Resolver, Span, ResolutionError<'b>) + where F: for<'c, 'b> FnOnce(&'c mut Resolver<'_>, Span, ResolutionError<'b>) { let namespace = if is_value { ValueNS } else { TypeNS }; let span = path.span; @@ -1819,7 +1812,7 @@ impl<'a> Resolver<'a> { DefCollector::new(&mut definitions, Mark::root()) .collect_root(crate_name, session.local_crate_disambiguator()); - let mut extern_prelude: FxHashMap = + let mut extern_prelude: FxHashMap> = session.opts.externs.iter().map(|kv| (Ident::from_str(kv.0), Default::default())) .collect(); @@ -2315,7 +2308,7 @@ impl<'a> Resolver<'a> { // implementations thus found, for compatibility with old resolve pass. pub fn with_scope(&mut self, id: NodeId, f: F) -> T - where F: FnOnce(&mut Resolver) -> T + where F: FnOnce(&mut Resolver<'_>) -> T { let id = self.definitions.local_def_id(id); let module = self.module_map.get(&id).cloned(); // clones a reference @@ -2342,7 +2335,7 @@ impl<'a> Resolver<'a> { /// /// Stops after meeting a closure. fn search_label(&self, mut ident: Ident, pred: P) -> Option - where P: Fn(&Rib, Ident) -> Option + where P: Fn(&Rib<'_>, Ident) -> Option { for rib in self.label_ribs.iter().rev() { match rib.kind { @@ -2527,7 +2520,7 @@ impl<'a> Resolver<'a> { } fn with_type_parameter_rib<'b, F>(&'b mut self, type_parameters: TypeParameters<'a, 'b>, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { match type_parameters { HasTypeParameters(generics, rib_kind) => { @@ -2573,7 +2566,7 @@ impl<'a> Resolver<'a> { } fn with_label_rib(&mut self, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { self.label_ribs.push(Rib::new(NormalRibKind)); f(self); @@ -2581,7 +2574,7 @@ impl<'a> Resolver<'a> { } fn with_item_rib(&mut self, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { self.ribs[ValueNS].push(Rib::new(ItemRibKind)); self.ribs[TypeNS].push(Rib::new(ItemRibKind)); @@ -2591,7 +2584,7 @@ impl<'a> Resolver<'a> { } fn with_constant_rib(&mut self, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { self.ribs[ValueNS].push(Rib::new(ConstantItemRibKind)); self.label_ribs.push(Rib::new(ConstantItemRibKind)); @@ -2601,7 +2594,7 @@ impl<'a> Resolver<'a> { } fn with_current_self_type(&mut self, self_type: &Ty, f: F) -> T - where F: FnOnce(&mut Resolver) -> T + where F: FnOnce(&mut Resolver<'_>) -> T { // Handle nested impls (inside fn bodies) let previous_value = replace(&mut self.current_self_type, Some(self_type.clone())); @@ -2611,7 +2604,7 @@ impl<'a> Resolver<'a> { } fn with_current_self_item(&mut self, self_item: &Item, f: F) -> T - where F: FnOnce(&mut Resolver) -> T + where F: FnOnce(&mut Resolver<'_>) -> T { let previous_value = replace(&mut self.current_self_item, Some(self_item.id)); let result = f(self); @@ -2621,7 +2614,7 @@ impl<'a> Resolver<'a> { /// This is called to resolve a trait reference from an `impl` (i.e., `impl Trait for Foo`) fn with_optional_trait_ref(&mut self, opt_trait_ref: Option<&TraitRef>, f: F) -> T - where F: FnOnce(&mut Resolver, Option) -> T + where F: FnOnce(&mut Resolver<'_>, Option) -> T { let mut new_val = None; let mut new_id = None; @@ -2658,7 +2651,7 @@ impl<'a> Resolver<'a> { } fn with_self_rib(&mut self, self_def: Def, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { let mut self_type_rib = Rib::new(NormalRibKind); @@ -2670,7 +2663,7 @@ impl<'a> Resolver<'a> { } fn with_self_struct_ctor_rib(&mut self, impl_id: DefId, f: F) - where F: FnOnce(&mut Resolver) + where F: FnOnce(&mut Resolver<'_>) { let self_def = Def::SelfCtor(impl_id); let mut self_type_rib = Rib::new(NormalRibKind); @@ -2771,7 +2764,7 @@ impl<'a> Resolver<'a> { } fn check_trait_item(&mut self, ident: Ident, ns: Namespace, span: Span, err: F) - where F: FnOnce(Name, &str) -> ResolutionError + where F: FnOnce(Name, &str) -> ResolutionError<'_> { // If there is a TraitRef in scope for an impl, then the method must be in the // trait. @@ -3102,7 +3095,7 @@ impl<'a> Resolver<'a> { id: NodeId, qself: Option<&QSelf>, path: &Path, - source: PathSource) + source: PathSource<'_>) -> PathResolution { self.smart_resolve_path_with_crate_lint(id, qself, path, source, CrateLint::SimplePath(id)) } @@ -3120,7 +3113,7 @@ impl<'a> Resolver<'a> { id: NodeId, qself: Option<&QSelf>, path: &Path, - source: PathSource, + source: PathSource<'_>, crate_lint: CrateLint ) -> PathResolution { self.smart_resolve_path_fragment( @@ -3138,7 +3131,7 @@ impl<'a> Resolver<'a> { qself: Option<&QSelf>, path: &[Segment], span: Span, - source: PathSource, + source: PathSource<'_>, crate_lint: CrateLint) -> PathResolution { let ident_span = path.last().map_or(span, |ident| ident.ident.span); @@ -3581,7 +3574,7 @@ impl<'a> Resolver<'a> { } fn type_ascription_suggestion(&self, - err: &mut DiagnosticBuilder, + err: &mut DiagnosticBuilder<'_>, base_span: Span) { debug!("type_ascription_suggetion {:?}", base_span); let cm = self.session.source_map(); @@ -4040,7 +4033,7 @@ impl<'a> Resolver<'a> { crate_lint: CrateLint, path: &[Segment], path_span: Span, - second_binding: Option<&NameBinding>, + second_binding: Option<&NameBinding<'_>>, ) { let (diag_id, diag_span) = match crate_lint { CrateLint::No => return, @@ -4266,7 +4259,7 @@ impl<'a> Resolver<'a> { where FilterFn: Fn(Def) -> bool, { - let add_module_candidates = |module: Module, names: &mut Vec| { + let add_module_candidates = |module: Module<'_>, names: &mut Vec| { for (&(ident, _), resolution) in module.resolutions.borrow().iter() { if let Some(binding) = resolution.borrow().binding { if filter_fn(binding.def()) { @@ -4361,7 +4354,7 @@ impl<'a> Resolver<'a> { } fn with_resolved_label(&mut self, label: Option