Skip to content

Commit 66d7a88

Browse files
committed
resolve: directive -> import
1 parent 1915bf1 commit 66d7a88

8 files changed

+215
-237
lines changed

src/librustc_resolve/build_reduced_graph.rs

+21-30
Original file line numberDiff line numberDiff line change
@@ -307,8 +307,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
307307
})
308308
}
309309

310-
// Add an import directive to the current module.
311-
fn add_import_directive(
310+
// Add an import to the current module.
311+
fn add_import(
312312
&mut self,
313313
module_path: Vec<Segment>,
314314
kind: ImportKind<'a>,
@@ -320,7 +320,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
320320
vis: ty::Visibility,
321321
) {
322322
let current_module = self.parent_scope.module;
323-
let directive = self.r.arenas.alloc_import_directive(Import {
323+
let import = self.r.arenas.alloc_import(Import {
324324
kind,
325325
parent_scope: self.parent_scope,
326326
module_path,
@@ -336,25 +336,25 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
336336
used: Cell::new(false),
337337
});
338338

339-
debug!("add_import_directive({:?})", directive);
339+
debug!("add_import({:?})", import);
340340

341-
self.r.indeterminate_imports.push(directive);
342-
match directive.kind {
341+
self.r.indeterminate_imports.push(import);
342+
match import.kind {
343343
// Don't add unresolved underscore imports to modules
344344
ImportKind::Single { target: Ident { name: kw::Underscore, .. }, .. } => {}
345345
ImportKind::Single { target, type_ns_only, .. } => {
346346
self.r.per_ns(|this, ns| {
347347
if !type_ns_only || ns == TypeNS {
348348
let key = this.new_key(target, ns);
349349
let mut resolution = this.resolution(current_module, key).borrow_mut();
350-
resolution.add_single_import(directive);
350+
resolution.add_single_import(import);
351351
}
352352
});
353353
}
354354
// We don't add prelude imports to the globs since they only affect lexical scopes,
355355
// which are not relevant to import resolution.
356356
ImportKind::Glob { is_prelude: true, .. } => {}
357-
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(directive),
357+
ImportKind::Glob { .. } => current_module.globs.borrow_mut().push(import),
358358
_ => unreachable!(),
359359
}
360360
}
@@ -495,7 +495,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
495495
type_ns_only,
496496
nested,
497497
};
498-
self.add_import_directive(
498+
self.add_import(
499499
module_path,
500500
kind,
501501
use_tree.span,
@@ -511,16 +511,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
511511
is_prelude: attr::contains_name(&item.attrs, sym::prelude_import),
512512
max_vis: Cell::new(ty::Visibility::Invisible),
513513
};
514-
self.add_import_directive(
515-
prefix,
516-
kind,
517-
use_tree.span,
518-
id,
519-
item,
520-
root_span,
521-
item.id,
522-
vis,
523-
);
514+
self.add_import(prefix, kind, use_tree.span, id, item, root_span, item.id, vis);
524515
}
525516
ast::UseTreeKind::Nested(ref items) => {
526517
// Ensure there is at most one `self` in the list
@@ -636,7 +627,7 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
636627
let used = self.process_legacy_macro_imports(item, module);
637628
let binding =
638629
(module, ty::Visibility::Public, sp, expansion).to_name_binding(self.r.arenas);
639-
let directive = self.r.arenas.alloc_import_directive(Import {
630+
let import = self.r.arenas.alloc_import(Import {
640631
kind: ImportKind::ExternCrate { source: orig_name, target: ident },
641632
root_id: item.id,
642633
id: item.id,
@@ -651,8 +642,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
651642
vis: Cell::new(vis),
652643
used: Cell::new(used),
653644
});
654-
self.r.potentially_unused_imports.push(directive);
655-
let imported_binding = self.r.import(binding, directive);
645+
self.r.potentially_unused_imports.push(import);
646+
let imported_binding = self.r.import(binding, import);
656647
if ptr::eq(parent, self.r.graph_root) {
657648
if let Some(entry) = self.r.extern_prelude.get(&ident.modern()) {
658649
if expansion != ExpnId::root()
@@ -988,8 +979,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
988979
}
989980
}
990981

991-
let macro_use_directive = |this: &Self, span| {
992-
this.r.arenas.alloc_import_directive(Import {
982+
let macro_use_import = |this: &Self, span| {
983+
this.r.arenas.alloc_import(Import {
993984
kind: ImportKind::MacroUse,
994985
root_id: item.id,
995986
id: item.id,
@@ -1008,11 +999,11 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
1008999

10091000
let allow_shadowing = self.parent_scope.expansion == ExpnId::root();
10101001
if let Some(span) = import_all {
1011-
let directive = macro_use_directive(self, span);
1012-
self.r.potentially_unused_imports.push(directive);
1002+
let import = macro_use_import(self, span);
1003+
self.r.potentially_unused_imports.push(import);
10131004
module.for_each_child(self, |this, ident, ns, binding| {
10141005
if ns == MacroNS {
1015-
let imported_binding = this.r.import(binding, directive);
1006+
let imported_binding = this.r.import(binding, import);
10161007
this.legacy_import_macro(ident.name, imported_binding, span, allow_shadowing);
10171008
}
10181009
});
@@ -1027,9 +1018,9 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
10271018
ident.span,
10281019
);
10291020
if let Ok(binding) = result {
1030-
let directive = macro_use_directive(self, ident.span);
1031-
self.r.potentially_unused_imports.push(directive);
1032-
let imported_binding = self.r.import(binding, directive);
1021+
let import = macro_use_import(self, ident.span);
1022+
self.r.potentially_unused_imports.push(import);
1023+
let imported_binding = self.r.import(binding, import);
10331024
self.legacy_import_macro(
10341025
ident.name,
10351026
imported_binding,

src/librustc_resolve/check_unused.rs

+15-15
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
//
44
// Although this is mostly a lint pass, it lives in here because it depends on
55
// resolve data structures and because it finalises the privacy information for
6-
// `use` directives.
6+
// `use` items.
77
//
88
// Unused trait imports can't be checked until the method resolution. We save
99
// candidates here, and do the actual check in librustc_typeck/check_unused.rs.
@@ -58,7 +58,7 @@ struct UnusedImportCheckVisitor<'a, 'b> {
5858
}
5959

6060
impl<'a, 'b> UnusedImportCheckVisitor<'a, 'b> {
61-
// We have information about whether `use` (import) directives are actually
61+
// We have information about whether `use` (import) items are actually
6262
// used now. If an import is not used at all, we signal a lint error.
6363
fn check_import(&mut self, id: ast::NodeId) {
6464
let mut used = false;
@@ -223,33 +223,33 @@ fn calc_unused_spans(
223223

224224
impl Resolver<'_> {
225225
crate fn check_unused(&mut self, krate: &ast::Crate) {
226-
for directive in self.potentially_unused_imports.iter() {
227-
match directive.kind {
228-
_ if directive.used.get()
229-
|| directive.vis.get() == ty::Visibility::Public
230-
|| directive.span.is_dummy() =>
226+
for import in self.potentially_unused_imports.iter() {
227+
match import.kind {
228+
_ if import.used.get()
229+
|| import.vis.get() == ty::Visibility::Public
230+
|| import.span.is_dummy() =>
231231
{
232-
if let ImportKind::MacroUse = directive.kind {
233-
if !directive.span.is_dummy() {
232+
if let ImportKind::MacroUse = import.kind {
233+
if !import.span.is_dummy() {
234234
self.lint_buffer.buffer_lint(
235235
lint::builtin::MACRO_USE_EXTERN_CRATE,
236-
directive.id,
237-
directive.span,
238-
"deprecated `#[macro_use]` directive used to \
236+
import.id,
237+
import.span,
238+
"deprecated `#[macro_use]` attribute used to \
239239
import macros should be replaced at use sites \
240-
with a `use` statement to import the macro \
240+
with a `use` item to import the macro \
241241
instead",
242242
);
243243
}
244244
}
245245
}
246246
ImportKind::ExternCrate { .. } => {
247-
self.maybe_unused_extern_crates.push((directive.id, directive.span));
247+
self.maybe_unused_extern_crates.push((import.id, import.span));
248248
}
249249
ImportKind::MacroUse => {
250250
let lint = lint::builtin::UNUSED_IMPORTS;
251251
let msg = "unused `#[macro_use]` import";
252-
self.lint_buffer.buffer_lint(lint, directive.id, directive.span, msg);
252+
self.lint_buffer.buffer_lint(lint, import.id, import.span, msg);
253253
}
254254
_ => {}
255255
}

src/librustc_resolve/diagnostics.rs

+9-9
Original file line numberDiff line numberDiff line change
@@ -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 Import<'b>,
1129+
import: &'b Import<'b>,
11301130
module: ModuleOrUniformRoot<'b>,
11311131
ident: Ident,
11321132
) -> Option<(Option<Suggestion>, Vec<String>)> {
@@ -1151,26 +1151,26 @@ 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.kind {
1154+
let import_snippet = match import.kind {
11551155
ImportKind::Single { source, target, .. } if source != target => {
11561156
format!("{} as {}", source, target)
11571157
}
11581158
_ => format!("{}", ident),
11591159
};
11601160

11611161
let mut corrections: Vec<(Span, String)> = Vec::new();
1162-
if !directive.is_nested() {
1162+
if !import.is_nested() {
11631163
// Assume this is the easy case of `use issue_59764::foo::makro;` and just remove
11641164
// intermediate segments.
1165-
corrections.push((directive.span, format!("{}::{}", module_name, import)));
1165+
corrections.push((import.span, format!("{}::{}", module_name, import_snippet)));
11661166
} else {
11671167
// Find the binding span (and any trailing commas and spaces).
11681168
// ie. `use a::b::{c, d, e};`
11691169
// ^^^
11701170
let (found_closing_brace, binding_span) = find_span_of_binding_until_next_binding(
11711171
self.r.session,
1172-
directive.span,
1173-
directive.use_span,
1172+
import.span,
1173+
import.use_span,
11741174
);
11751175
debug!(
11761176
"check_for_module_export_macro: found_closing_brace={:?} binding_span={:?}",
@@ -1207,7 +1207,7 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
12071207
let (has_nested, after_crate_name) = find_span_immediately_after_crate_name(
12081208
self.r.session,
12091209
module_name,
1210-
directive.use_span,
1210+
import.use_span,
12111211
);
12121212
debug!(
12131213
"check_for_module_export_macro: has_nested={:?} after_crate_name={:?}",
@@ -1223,11 +1223,11 @@ impl<'a, 'b> ImportResolver<'a, 'b> {
12231223
start_point,
12241224
if has_nested {
12251225
// In this case, `start_snippet` must equal '{'.
1226-
format!("{}{}, ", start_snippet, import)
1226+
format!("{}{}, ", start_snippet, import_snippet)
12271227
} else {
12281228
// In this case, add a `{`, then the moved import, then whatever
12291229
// was there before.
1230-
format!("{{{}, {}", import, start_snippet)
1230+
format!("{{{}, {}", import_snippet, start_snippet)
12311231
},
12321232
));
12331233
}

0 commit comments

Comments
 (0)