Skip to content

Commit 1915bf1

Browse files
committed
resolve: ImportDirective -> Import
`ImportDirectiveSubclass` -> `ImportKind` `ImportKind::SingleImport` -> `ImportKind::Single` `ImportKind::GlobImport` -> `ImportKind::Glob`
1 parent a039217 commit 1915bf1

File tree

5 files changed

+105
-125
lines changed

5 files changed

+105
-125
lines changed

src/librustc_resolve/build_reduced_graph.rs

+17-21
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,7 @@
66
//! Imports are also considered items and placed into modules here, but not resolved yet.
77
88
use crate::def_collector::collect_definitions;
9-
use crate::imports::ImportDirective;
10-
use crate::imports::ImportDirectiveSubclass::{self, GlobImport, SingleImport};
9+
use crate::imports::{Import, ImportKind};
1110
use crate::macros::{LegacyBinding, LegacyScope};
1211
use crate::Namespace::{self, MacroNS, TypeNS, ValueNS};
1312
use crate::{CrateLint, Determinacy, PathResult, ResolutionError, VisResolutionError};
@@ -312,7 +311,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
312311
fn add_import_directive(
313312
&mut self,
314313
module_path: Vec<Segment>,
315-
subclass: ImportDirectiveSubclass<'a>,
314+
kind: ImportKind<'a>,
316315
span: Span,
317316
id: NodeId,
318317
item: &ast::Item,
@@ -321,11 +320,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
321320
vis: ty::Visibility,
322321
) {
323322
let current_module = self.parent_scope.module;
324-
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
323+
let directive = self.r.arenas.alloc_import_directive(Import {
324+
kind,
325325
parent_scope: self.parent_scope,
326326
module_path,
327327
imported_module: Cell::new(None),
328-
subclass,
329328
span,
330329
id,
331330
use_span: item.span,
@@ -340,10 +339,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
340339
debug!("add_import_directive({:?})", directive);
341340

342341
self.r.indeterminate_imports.push(directive);
343-
match directive.subclass {
342+
match directive.kind {
344343
// Don't add unresolved underscore imports to modules
345-
SingleImport { target: Ident { name: kw::Underscore, .. }, .. } => {}
346-
SingleImport { target, type_ns_only, .. } => {
344+
ImportKind::Single { target: Ident { name: kw::Underscore, .. }, .. } => {}
345+
ImportKind::Single { target, type_ns_only, .. } => {
347346
self.r.per_ns(|this, ns| {
348347
if !type_ns_only || ns == TypeNS {
349348
let key = this.new_key(target, ns);
@@ -354,8 +353,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
354353
}
355354
// We don't add prelude imports to the globs since they only affect lexical scopes,
356355
// which are not relevant to import resolution.
357-
GlobImport { is_prelude: true, .. } => {}
358-
GlobImport { .. } => current_module.globs.borrow_mut().push(directive),
356+
ImportKind::Glob { is_prelude: true, .. } => {}
357+
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(directive),
359358
_ => unreachable!(),
360359
}
361360
}
@@ -480,7 +479,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
480479
);
481480
}
482481

483-
let subclass = SingleImport {
482+
let kind = ImportKind::Single {
484483
source: source.ident,
485484
target: ident,
486485
source_bindings: PerNS {
@@ -498,7 +497,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
498497
};
499498
self.add_import_directive(
500499
module_path,
501-
subclass,
500+
kind,
502501
use_tree.span,
503502
id,
504503
item,
@@ -508,13 +507,13 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
508507
);
509508
}
510509
ast::UseTreeKind::Glob => {
511-
let subclass = GlobImport {
510+
let kind = ImportKind::Glob {
512511
is_prelude: attr::contains_name(&item.attrs, sym::prelude_import),
513512
max_vis: Cell::new(ty::Visibility::Invisible),
514513
};
515514
self.add_import_directive(
516515
prefix,
517-
subclass,
516+
kind,
518517
use_tree.span,
519518
id,
520519
item,
@@ -637,15 +636,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
637636
let used = self.process_legacy_macro_imports(item, module);
638637
let binding =
639638
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
640-
let directive = self.r.arenas.alloc_import_directive(ImportDirective {
639+
let directive = self.r.arenas.alloc_import_directive(Import {
640+
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
641641
root_id: item.id,
642642
id: item.id,
643643
parent_scope: self.parent_scope,
644644
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
645-
subclass: ImportDirectiveSubclass::ExternCrate {
646-
source: orig_name,
647-
target: ident,
648-
},
649645
has_attributes: !item.attrs.is_empty(),
650646
use_span_with_attributes: item.span_with_attributes(),
651647
use_span: item.span,
@@ -993,12 +989,12 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
993989
}
994990

995991
let macro_use_directive = |this: &Self, span| {
996-
this.r.arenas.alloc_import_directive(ImportDirective {
992+
this.r.arenas.alloc_import_directive(Import {
993+
kind: ImportKind::MacroUse,
997994
root_id: item.id,
998995
id: item.id,
999996
parent_scope: this.parent_scope,
1000997
imported_module: Cell::new(Some(ModuleOrUniformRoot::Module(module))),
1001-
subclass: ImportDirectiveSubclass::MacroUse,
1002998
use_span_with_attributes: item.span_with_attributes(),
1003999
has_attributes: !item.attrs.is_empty(),
10041000
use_span: item.span,

src/librustc_resolve/check_unused.rs

+5-5
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
// - `check_crate` finally emits the diagnostics based on the data generated
2424
// in the last step
2525

26-
use crate::imports::ImportDirectiveSubclass;
26+
use crate::imports::ImportKind;
2727
use crate::Resolver;
2828

2929
use rustc::{lint, ty};
@@ -224,12 +224,12 @@ fn calc_unused_spans(
224224
impl Resolver<'_> {
225225
crate fn check_unused(&mut self, krate: &ast::Crate) {
226226
for directive in self.potentially_unused_imports.iter() {
227-
match directive.subclass {
227+
match directive.kind {
228228
_ if directive.used.get()
229229
|| directive.vis.get() == ty::Visibility::Public
230230
|| directive.span.is_dummy() =>
231231
{
232-
if let ImportDirectiveSubclass::MacroUse = directive.subclass {
232+
if let ImportKind::MacroUse = directive.kind {
233233
if !directive.span.is_dummy() {
234234
self.lint_buffer.buffer_lint(
235235
lint::builtin::MACRO_USE_EXTERN_CRATE,
@@ -243,10 +243,10 @@ impl Resolver<'_> {
243243
}
244244
}
245245
}
246-
ImportDirectiveSubclass::ExternCrate { .. } => {
246+
ImportKind::ExternCrate { .. } => {
247247
self.maybe_unused_extern_crates.push((directive.id, directive.span));
248248
}
249-
ImportDirectiveSubclass::MacroUse => {
249+
ImportKind::MacroUse => {
250250
let lint = lint::builtin::UNUSED_IMPORTS;
251251
let msg = "unused `#[macro_use]` import";
252252
self.lint_buffer.buffer_lint(lint, directive.id, directive.span, msg);

src/librustc_resolve/diagnostics.rs

+4-6
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ use rustc_span::source_map::SourceMap;
1818
use rustc_span::symbol::{kw, Symbol};
1919
use rustc_span::{BytePos, MultiSpan, Span};
2020

21-
use crate::imports::{ImportDirective, ImportDirectiveSubclass, ImportResolver};
21+
use crate::imports::{Import, ImportKind, ImportResolver};
2222
use crate::path_names_to_string;
2323
use crate::{AmbiguityError, AmbiguityErrorMisc, AmbiguityKind};
2424
use crate::{BindingError, CrateLint, HasGenericParams, LegacyScope, Module, ModuleOrUniformRoot};
@@ -1126,7 +1126,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11261126
/// ```
11271127
pub(crate) fn check_for_module_export_macro(
11281128
&mut self,
1129-
directive: &'b ImportDirective<'b>,
1129+
directive: &'b Import<'b>,
11301130
module: ModuleOrUniformRoot<'b>,
11311131
ident: Ident,
11321132
) -> Option<(Option<Suggestion>, Vec<String>)> {
@@ -1151,10 +1151,8 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
11511151
let binding = resolution.borrow().binding()?;
11521152
if let Res::Def(DefKind::Macro(MacroKind::Bang), _) = binding.res() {
11531153
let module_name = crate_module.kind.name().unwrap();
1154-
let import = match directive.subclass {
1155-
ImportDirectiveSubclass::SingleImport { source, target, .. }
1156-
if source != target =>
1157-
{
1154+
let import = match directive.kind {
1155+
ImportKind::Single { source, target, .. } if source != target => {
11581156
format!("{} as {}", source, target)
11591157
}
11601158
_ => format!("{}", ident),

0 commit comments

Comments
 (0)