resolve: ImportDirective -> Import

`ImportDirectiveSubclass` -> `ImportKind`
`ImportKind::SingleImport` -> `ImportKind::Single`
`ImportKind::GlobImport` -> `ImportKind::Glob`
This commit is contained in:
Vadim Petrochenkov 2020-03-07 18:49:13 +03:00
parent a03921701c
commit 1915bf122e
5 changed files with 105 additions and 125 deletions

View File

@ -6,8 +6,7 @@
//! Imports are also considered items and placed into modules here, but not resolved yet.
use crate::def_collector::collect_definitions;
use crate::imports::ImportDirective;
use crate::imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
use crate::imports::{Import, ImportKind};
use crate::macros::{LegacyBinding, LegacyScope};
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
use crate::{CrateLint, Determinacy, PathResult, ResolutionError, VisResolutionError};
@ -312,7 +311,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
fn add_import_directive(
&mut self,
module_path: Vec<Segment>,
subclass: ImportDirectiveSubclass<'a>,
kind: ImportKind<'a>,
span: Span,
id: NodeId,
item: &ast::Item,
@ -321,11 +320,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
vis: ty::Visibility,
) {
let current_module = self.parent_scope.module;
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
let directive = self.r.arenas.alloc_import_directive(Import {
kind,
parent_scope: self.parent_scope,
module_path,
imported_module: Cell::new(None),
subclass,
span,
id,
use_span: item.span,
@ -340,10 +339,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
debug!("add_import_directive({:?})", directive);
self.r.indeterminate_imports.push(directive);
match directive.subclass {
match directive.kind {
// Don't add unresolved underscore imports to modules
SingleImport { target: Ident { name: kw::Underscore, .. }, .. } => {}
SingleImport { target, type_ns_only, .. } => {
ImportKind::Single { target: Ident { name: kw::Underscore, .. }, .. } => {}
ImportKind::Single { target, type_ns_only, .. } => {
self.r.per_ns(|this, ns| {
if !type_ns_only || ns == TypeNS {
let key = this.new_key(target, ns);
@ -354,8 +353,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport { is_prelude: true, .. } => {}
GlobImport { .. } => current_module.globs.borrow_mut().push(directive),
ImportKind::Glob { is_prelude: true, .. } => {}
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(directive),
_ => unreachable!(),
}
}
@ -480,7 +479,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
);
}
let subclass = SingleImport {
let kind = ImportKind::Single {
source: source.ident,
target: ident,
source_bindings: PerNS {
@ -498,7 +497,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
};
self.add_import_directive(
module_path,
subclass,
kind,
use_tree.span,
id,
item,
@ -508,13 +507,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
);
}
ast::UseTreeKind::Glob => {
let subclass = GlobImport {
let kind = ImportKind::Glob {
is_prelude: attr::contains_name(&item.attrs, sym::prelude_import),
max_vis: Cell::new(ty::Visibility::Invisible),
};
self.add_import_directive(
prefix,
subclass,
kind,
use_tree.span,
id,
item,
@ -637,15 +636,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
let used = self.process_legacy_macro_imports(item, module);
let binding =
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
let directive = self.r.arenas.alloc_import_directive(Import {
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
root_id: item.id,
id: item.id,
parent_scope: self.parent_scope,
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
subclass: ImportDirectiveSubclass::ExternCrate {
source: orig_name,
target: ident,
},
has_attributes: !item.attrs.is_empty(),
use_span_with_attributes: item.span_with_attributes(),
use_span: item.span,
@ -993,12 +989,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
}
let macro_use_directive = |this: &Self, span| {
this.r.arenas.alloc_import_directive(ImportDirective {
this.r.arenas.alloc_import_directive(Import {
kind: ImportKind::MacroUse,
root_id: item.id,
id: item.id,
parent_scope: this.parent_scope,
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
subclass: ImportDirectiveSubclass::MacroUse,
use_span_with_attributes: item.span_with_attributes(),
has_attributes: !item.attrs.is_empty(),
use_span: item.span,

View File

@ -23,7 +23,7 @@
// - `check_crate` finally emits the diagnostics based on the data generated
// in the last step
use crate::imports::ImportDirectiveSubclass;
use crate::imports::ImportKind;
use crate::Resolver;
use rustc::{lint, ty};
@ -224,12 +224,12 @@ fn calc_unused_spans(
impl Resolver<'_> {
crate fn check_unused(&mut self, krate: &ast::Crate) {
for directive in self.potentially_unused_imports.iter() {
match directive.subclass {
match directive.kind {
_ if directive.used.get()
|| directive.vis.get() == ty::Visibility::Public
|| directive.span.is_dummy() =>
{
if let ImportDirectiveSubclass::MacroUse = directive.subclass {
if let ImportKind::MacroUse = directive.kind {
if !directive.span.is_dummy() {
self.lint_buffer.buffer_lint(
lint::builtin::MACRO_USE_EXTERN_CRATE,
@ -243,10 +243,10 @@ impl Resolver<'_> {
}
}
}
ImportDirectiveSubclass::ExternCrate { .. } => {
ImportKind::ExternCrate { .. } => {
self.maybe_unused_extern_crates.push((directive.id, directive.span));
}
ImportDirectiveSubclass::MacroUse => {
ImportKind::MacroUse => {
let lint = lint::builtin::UNUSED_IMPORTS;
let msg = "unused `#[macro_use]` import";
self.lint_buffer.buffer_lint(lint, directive.id, directive.span, msg);

View File

@ -18,7 +18,7 @@ use rustc_span::source_map::SourceMap;
use rustc_span::symbol::{kw, Symbol};
use rustc_span::{BytePos, MultiSpan, Span};
use crate::imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
use crate::imports::{Import, ImportKind, ImportResolver};
use crate::path_names_to_string;
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
use crate::{BindingError, CrateLint, HasGenericParams, LegacyScope, Module, ModuleOrUniformRoot};
@ -1126,7 +1126,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
/// ```
pub(crate) fn check_for_module_export_macro(
&mut self,
directive: &'b ImportDirective<'b>,
directive: &'b Import<'b>,
module: ModuleOrUniformRoot<'b>,
ident: Ident,
) -> Option<(Option<Suggestion>, Vec<String>)> {
@ -1151,10 +1151,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
let binding = resolution.borrow().binding()?;
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() {
let module_name = crate_module.kind.name().unwrap();
let import = match directive.subclass {
ImportDirectiveSubclass::SingleImport { source, target, .. }
if source != target =>
{
let import = match directive.kind {
ImportKind::Single { source, target, .. } if source != target => {
format!("{} as {}", source, target)
}
_ => format!("{}", ident),

View File

@ -1,7 +1,5 @@
//! A bunch of methods and structures more or less related to resolving imports.
use ImportDirectiveSubclass::*;
use crate::diagnostics::Suggestion;
use crate::Determinacy::{self, *};
use crate::Namespace::{self, MacroNS, TypeNS};
@ -38,8 +36,8 @@ type Res = def::Res<NodeId>;
/// Contains data for specific types of import directives.
#[derive(Clone, Debug)]
pub enum ImportDirectiveSubclass<'a> {
SingleImport {
pub enum ImportKind<'a> {
Single {
/// `source` in `use prefix::source as target`.
source: Ident,
/// `target` in `use prefix::source as target`.
@ -53,7 +51,7 @@ pub enum ImportDirectiveSubclass<'a> {
/// Did this import result from a nested import? ie. `use foo::{bar, baz};`
nested: bool,
},
GlobImport {
Glob {
is_prelude: bool,
max_vis: Cell<ty::Visibility>, // The visibility of the greatest re-export.
// n.b. `max_vis` is only used in `finalize_import` to check for re-export errors.
@ -67,10 +65,12 @@ pub enum ImportDirectiveSubclass<'a> {
/// One import directive.
#[derive(Debug, Clone)]
crate struct ImportDirective<'a> {
/// The ID of the `extern crate`, `UseTree` etc that imported this `ImportDirective`.
crate struct Import<'a> {
pub kind: ImportKind<'a>,
/// The ID of the `extern crate`, `UseTree` etc that imported this `Import`.
///
/// In the case where the `ImportDirective` was expanded from a "nested" use tree,
/// In the case where the `Import` was expanded from a "nested" use tree,
/// this id is the ID of the leaf tree. For example:
///
/// ```ignore (pacify the mercilous tidy)
@ -107,22 +107,21 @@ crate struct ImportDirective<'a> {
pub module_path: Vec<Segment>,
/// The resolution of `module_path`.
pub imported_module: Cell<Option<ModuleOrUniformRoot<'a>>>,
pub subclass: ImportDirectiveSubclass<'a>,
pub vis: Cell<ty::Visibility>,
pub used: Cell<bool>,
}
impl<'a> ImportDirective<'a> {
impl<'a> Import<'a> {
pub fn is_glob(&self) -> bool {
match self.subclass {
ImportDirectiveSubclass::GlobImport { .. } => true,
match self.kind {
ImportKind::Glob { .. } => true,
_ => false,
}
}
pub fn is_nested(&self) -> bool {
match self.subclass {
ImportDirectiveSubclass::SingleImport { nested, .. } => nested,
match self.kind {
ImportKind::Single { nested, .. } => nested,
_ => false,
}
}
@ -137,7 +136,7 @@ impl<'a> ImportDirective<'a> {
pub struct NameResolution<'a> {
/// Single imports that may define the name in the namespace.
/// Import directives are arena-allocated, so it's ok to use pointers as keys.
single_imports: FxHashSet<PtrKey<'a, ImportDirective<'a>>>,
single_imports: FxHashSet<PtrKey<'a, Import<'a>>>,
/// The least shadowable known binding for this name, or None if there are no known bindings.
pub binding: Option<&'a NameBinding<'a>>,
shadowed_glob: Option<&'a NameBinding<'a>>,
@ -155,7 +154,7 @@ impl<'a> NameResolution<'a> {
})
}
crate fn add_single_import(&mut self, directive: &'a ImportDirective<'a>) {
crate fn add_single_import(&mut self, directive: &'a Import<'a>) {
self.single_imports.insert(PtrKey(directive));
}
}
@ -348,8 +347,8 @@ impl<'a> Resolver<'a> {
single_import.imported_module.get(),
return Err((Undetermined, Weak::No))
);
let ident = match single_import.subclass {
SingleImport { source, .. } => source,
let ident = match single_import.kind {
ImportKind::Single { source, .. } => source,
_ => unreachable!(),
};
match self.resolve_ident_in_module(
@ -456,7 +455,7 @@ impl<'a> Resolver<'a> {
crate fn import(
&self,
binding: &'a NameBinding<'a>,
directive: &'a ImportDirective<'a>,
directive: &'a Import<'a>,
) -> &'a NameBinding<'a> {
let vis = if binding.pseudo_vis().is_at_least(directive.vis.get(), self) ||
// cf. `PUB_USE_OF_PRIVATE_EXTERN_CRATE`
@ -467,7 +466,7 @@ impl<'a> Resolver<'a> {
binding.pseudo_vis()
};
if let GlobImport { ref max_vis, .. } = directive.subclass {
if let ImportKind::Glob { ref max_vis, .. } = directive.kind {
if vis == directive.vis.get() || vis.is_at_least(max_vis.get(), self) {
max_vis.set(vis)
}
@ -596,8 +595,8 @@ impl<'a> Resolver<'a> {
// Define a "dummy" resolution containing a Res::Err as a placeholder for a
// failed resolution
fn import_dummy_binding(&mut self, directive: &'a ImportDirective<'a>) {
if let SingleImport { target, .. } = directive.subclass {
fn import_dummy_binding(&mut self, directive: &'a Import<'a>) {
if let ImportKind::Single { target, .. } = directive.kind {
let dummy_binding = self.dummy_binding;
let dummy_binding = self.import(dummy_binding, directive);
self.per_ns(|this, ns| {
@ -671,7 +670,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
.chain(indeterminate_imports.into_iter().map(|i| (true, i)))
{
if let Some(err) = self.finalize_import(import) {
if let SingleImport { source, ref source_bindings, .. } = import.subclass {
if let ImportKind::Single { source, ref source_bindings, .. } = import.kind {
if source.name == kw::SelfLower {
// Silence `unresolved import` error if E0429 is already emitted
if let Err(Determined) = source_bindings.value_ns.get() {
@ -695,7 +694,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
if seen_spans.insert(err.span) {
let path = import_path_to_string(
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
&import.subclass,
&import.kind,
err.span,
);
errors.push((path, err));
@ -706,7 +705,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
self.r.used_imports.insert((import.id, TypeNS));
let path = import_path_to_string(
&import.module_path.iter().map(|seg| seg.ident).collect::<Vec<_>>(),
&import.subclass,
&import.kind,
import.span,
);
let err = UnresolvedImportError {
@ -767,7 +766,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
/// Attempts to resolve the given import, returning true if its resolution is determined.
/// If successful, the resolved bindings are written into the module.
fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
fn resolve_import(&mut self, directive: &'b Import<'b>) -> bool {
debug!(
"(resolving import for module) resolving import `{}::...` in `{}`",
Segment::names_to_string(&directive.module_path),
@ -798,22 +797,22 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
};
directive.imported_module.set(Some(module));
let (source, target, source_bindings, target_bindings, type_ns_only) =
match directive.subclass {
SingleImport {
source,
target,
ref source_bindings,
ref target_bindings,
type_ns_only,
..
} => (source, target, source_bindings, target_bindings, type_ns_only),
GlobImport { .. } => {
self.resolve_glob_import(directive);
return true;
}
_ => unreachable!(),
};
let (source, target, source_bindings, target_bindings, type_ns_only) = match directive.kind
{
ImportKind::Single {
source,
target,
ref source_bindings,
ref target_bindings,
type_ns_only,
..
} => (source, target, source_bindings, target_bindings, type_ns_only),
ImportKind::Glob { .. } => {
self.resolve_glob_import(directive);
return true;
}
_ => unreachable!(),
};
let mut indeterminate = false;
self.r.per_ns(|this, ns| {
@ -873,10 +872,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
///
/// Optionally returns an unresolved import error. This error is buffered and used to
/// consolidate multiple unresolved import errors into a single diagnostic.
fn finalize_import(
&mut self,
directive: &'b ImportDirective<'b>,
) -> Option<UnresolvedImportError> {
fn finalize_import(&mut self, directive: &'b Import<'b>) -> Option<UnresolvedImportError> {
let orig_vis = directive.vis.replace(ty::Visibility::Invisible);
let prev_ambiguity_errors_len = self.r.ambiguity_errors.len();
let path_res = self.r.resolve_path(
@ -957,10 +953,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
PathResult::Indeterminate | PathResult::NonModule(..) => unreachable!(),
};
let (ident, target, source_bindings, target_bindings, type_ns_only) = match directive
.subclass
{
SingleImport {
let (ident, target, source_bindings, target_bindings, type_ns_only) = match directive.kind {
ImportKind::Single {
source,
target,
ref source_bindings,
@ -968,7 +962,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
type_ns_only,
..
} => (source, target, source_bindings, target_bindings, type_ns_only),
GlobImport { is_prelude, ref max_vis } => {
ImportKind::Glob { is_prelude, ref max_vis } => {
if directive.module_path.len() <= 1 {
// HACK(eddyb) `lint_if_path_starts_with_module` needs at least
// 2 segments, so the `resolve_path` above won't trigger it.
@ -1272,7 +1266,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
fn check_for_redundant_imports(
&mut self,
ident: Ident,
directive: &'b ImportDirective<'b>,
directive: &'b Import<'b>,
source_bindings: &PerNS<Cell<Result<&'b NameBinding<'b>, Determinacy>>>,
target_bindings: &PerNS<Cell<Option<&'b NameBinding<'b>>>>,
target: Ident,
@ -1337,7 +1331,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
}
fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) {
fn resolve_glob_import(&mut self, directive: &'b Import<'b>) {
let module = match directive.imported_module.get().unwrap() {
ModuleOrUniformRoot::Module(module) => module,
_ => {
@ -1351,7 +1345,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
return;
} else if module.def_id() == directive.parent_scope.module.def_id() {
return;
} else if let GlobImport { is_prelude: true, .. } = directive.subclass {
} else if let ImportKind::Glob { is_prelude: true, .. } = directive.kind {
self.r.prelude = Some(module);
return;
}
@ -1412,11 +1406,11 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
&& orig_binding.is_variant()
&& !orig_binding.vis.is_at_least(binding.vis, &*this)
{
let msg = match directive.subclass {
ImportDirectiveSubclass::SingleImport { .. } => {
let msg = match directive.kind {
ImportKind::Single { .. } => {
format!("variant `{}` is private and cannot be re-exported", ident)
}
ImportDirectiveSubclass::GlobImport { .. } => {
ImportKind::Glob { .. } => {
let msg = "enum is private and its variants \
cannot be re-exported"
.to_owned();
@ -1432,7 +1426,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
msg
}
ref s => bug!("unexpected import subclass {:?}", s),
ref s => bug!("unexpected import kind {:?}", s),
};
let mut err = this.session.struct_span_err(binding.span, &msg);
@ -1481,11 +1475,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
}
}
fn import_path_to_string(
names: &[Ident],
subclass: &ImportDirectiveSubclass<'_>,
span: Span,
) -> String {
fn import_path_to_string(names: &[Ident], import_kind: &ImportKind<'_>, span: Span) -> String {
let pos = names.iter().position(|p| span == p.span && p.name != kw::PathRoot);
let global = !names.is_empty() && names[0].name == kw::PathRoot;
if let Some(pos) = pos {
@ -1494,22 +1484,22 @@ fn import_path_to_string(
} else {
let names = if global { &names[1..] } else { names };
if names.is_empty() {
import_directive_subclass_to_string(subclass)
import_directive_subclass_to_string(import_kind)
} else {
format!(
"{}::{}",
names_to_string(&names.iter().map(|ident| ident.name).collect::<Vec<_>>()),
import_directive_subclass_to_string(subclass),
import_directive_subclass_to_string(import_kind),
)
}
}
}
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass<'_>) -> String {
match *subclass {
SingleImport { source, .. } => source.to_string(),
GlobImport { .. } => "*".to_string(),
ExternCrate { .. } => "<extern crate>".to_string(),
MacroUse => "#[macro_use]".to_string(),
fn import_directive_subclass_to_string(import_kind: &ImportKind<'_>) -> String {
match import_kind {
ImportKind::Single { source, .. } => source.to_string(),
ImportKind::Glob { .. } => "*".to_string(),
ImportKind::ExternCrate { .. } => "<extern crate>".to_string(),
ImportKind::MacroUse => "#[macro_use]".to_string(),
}
}

View File

@ -56,7 +56,7 @@ use std::{cmp, fmt, iter, ptr};
use diagnostics::{extend_span_to_previous_binding, find_span_of_binding_until_next_binding};
use diagnostics::{ImportSuggestion, Suggestion};
use imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver, NameResolution};
use imports::{Import, ImportKind, ImportResolver, NameResolution};
use late::{HasGenericParams, PathSource, Rib, RibKind::*};
use macros::{LegacyBinding, LegacyScope};
@ -456,8 +456,8 @@ pub struct ModuleData<'a> {
no_implicit_prelude: bool,
glob_importers: RefCell<Vec<&'a ImportDirective<'a>>>,
globs: RefCell<Vec<&'a ImportDirective<'a>>>,
glob_importers: RefCell<Vec<&'a Import<'a>>>,
globs: RefCell<Vec<&'a Import<'a>>>,
// Used to memoize the traits in this module for faster searches through all traits in scope.
traits: RefCell<Option<Box<[(Ident, &'a NameBinding<'a>)]>>>,
@ -584,7 +584,7 @@ impl<'a> ToNameBinding<'a> for &'a NameBinding<'a> {
enum NameBindingKind<'a> {
Res(Res, /* is_macro_export */ bool),
Module(Module<'a>),
Import { binding: &'a NameBinding<'a>, directive: &'a ImportDirective<'a>, used: Cell<bool> },
Import { binding: &'a NameBinding<'a>, directive: &'a Import<'a>, used: Cell<bool> },
}
impl<'a> NameBindingKind<'a> {
@ -713,8 +713,7 @@ impl<'a> NameBinding<'a> {
fn is_extern_crate(&self) -> bool {
match self.kind {
NameBindingKind::Import {
directive:
&ImportDirective { subclass: ImportDirectiveSubclass::ExternCrate { .. }, .. },
directive: &Import { kind: ImportKind::ExternCrate { .. }, .. },
..
} => true,
NameBindingKind::Module(&ModuleData {
@ -839,10 +838,10 @@ pub struct Resolver<'a> {
field_names: FxHashMap<DefId, Vec<Spanned<Name>>>,
/// All imports known to succeed or fail.
determined_imports: Vec<&'a ImportDirective<'a>>,
determined_imports: Vec<&'a Import<'a>>,
/// All non-determined imports.
indeterminate_imports: Vec<&'a ImportDirective<'a>>,
indeterminate_imports: Vec<&'a Import<'a>>,
/// FIXME: Refactor things so that these fields are passed through arguments and not resolver.
/// We are resolving a last import segment during import validation.
@ -947,7 +946,7 @@ pub struct Resolver<'a> {
/// Avoid duplicated errors for "name already defined".
name_already_seen: FxHashMap<Name, Span>,
potentially_unused_imports: Vec<&'a ImportDirective<'a>>,
potentially_unused_imports: Vec<&'a Import<'a>>,
/// Table for mapping struct IDs into struct constructor IDs,
/// it's not used during normal resolution, only for better error reporting.
@ -971,7 +970,7 @@ pub struct ResolverArenas<'a> {
modules: arena::TypedArena<ModuleData<'a>>,
local_modules: RefCell<Vec<Module<'a>>>,
name_bindings: arena::TypedArena<NameBinding<'a>>,
import_directives: arena::TypedArena<ImportDirective<'a>>,
import_directives: arena::TypedArena<Import<'a>>,
name_resolutions: arena::TypedArena<RefCell<NameResolution<'a>>>,
legacy_bindings: arena::TypedArena<LegacyBinding<'a>>,
ast_paths: arena::TypedArena<ast::Path>,
@ -991,10 +990,7 @@ impl<'a> ResolverArenas<'a> {
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<'_> {
fn alloc_import_directive(&'a self, import_directive: Import<'a>) -> &'a Import<'_> {
self.import_directives.alloc(import_directive)
}
fn alloc_name_resolution(&'a self) -> &'a RefCell<NameResolution<'a>> {
@ -1431,7 +1427,7 @@ impl<'a> Resolver<'a> {
}
#[inline]
fn add_to_glob_map(&mut self, directive: &ImportDirective<'_>, ident: Ident) {
fn add_to_glob_map(&mut self, directive: &Import<'_>, ident: Ident) {
if directive.is_glob() {
self.glob_map.entry(directive.id).or_default().insert(ident.name);
}
@ -2261,7 +2257,7 @@ impl<'a> Resolver<'a> {
if let NameBindingKind::Import { directive: d, .. } = binding.kind {
// Careful: we still want to rewrite paths from
// renamed extern crates.
if let ImportDirectiveSubclass::ExternCrate { source: None, .. } = d.subclass {
if let ImportKind::ExternCrate { source: None, .. } = d.kind {
return;
}
}
@ -2639,7 +2635,7 @@ impl<'a> Resolver<'a> {
&self,
err: &mut DiagnosticBuilder<'_>,
name: Name,
directive: &ImportDirective<'_>,
directive: &Import<'_>,
binding_span: Span,
) {
let suggested_name = if name.as_str().chars().next().unwrap().is_uppercase() {
@ -2649,11 +2645,11 @@ impl<'a> Resolver<'a> {
};
let mut suggestion = None;
match directive.subclass {
ImportDirectiveSubclass::SingleImport { type_ns_only: true, .. } => {
match directive.kind {
ImportKind::Single { type_ns_only: true, .. } => {
suggestion = Some(format!("self as {}", suggested_name))
}
ImportDirectiveSubclass::SingleImport { source, .. } => {
ImportKind::Single { source, .. } => {
if let Some(pos) =
source.span.hi().0.checked_sub(binding_span.lo().0).map(|pos| pos as usize)
{
@ -2669,7 +2665,7 @@ impl<'a> Resolver<'a> {
}
}
}
ImportDirectiveSubclass::ExternCrate { source, target, .. } => {
ImportKind::ExternCrate { source, target, .. } => {
suggestion = Some(format!(
"extern crate {} as {};",
source.unwrap_or(target.name),
@ -2717,7 +2713,7 @@ impl<'a> Resolver<'a> {
fn add_suggestion_for_duplicate_nested_use(
&self,
err: &mut DiagnosticBuilder<'_>,
directive: &ImportDirective<'_>,
directive: &Import<'_>,
binding_span: Span,
) {
assert!(directive.is_nested());