Skip to content

Commit 7fc0e40

Browse files
committed
Refactor away resolve_imports::Shadowable and rename shadowable -> is_prelude
1 parent 3ac4076 commit 7fc0e40

File tree

2 files changed

+10
-23
lines changed

2 files changed

+10
-23
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 6 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ use {NameBinding, NameBindingKind};
2222
use module_to_string;
2323
use ParentLink::{ModuleParentLink, BlockParentLink};
2424
use Resolver;
25-
use resolve_imports::Shadowable;
2625
use {resolve_error, resolve_struct_error, ResolutionError};
2726

2827
use rustc::middle::cstore::{CrateStore, ChildItem, DlDef, DlField, DlImpl};
@@ -189,14 +188,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
189188
};
190189

191190
// Build up the import directives.
192-
let shadowable = item.attrs.iter().any(|attr| {
191+
let is_prelude = item.attrs.iter().any(|attr| {
193192
attr.name() == special_idents::prelude_import.name.as_str()
194193
});
195-
let shadowable = if shadowable {
196-
Shadowable::Always
197-
} else {
198-
Shadowable::Never
199-
};
200194

201195
match view_path.node {
202196
ViewPathSimple(binding, ref full_path) => {
@@ -214,7 +208,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
214208
view_path.span,
215209
item.id,
216210
is_public,
217-
shadowable);
211+
is_prelude);
218212
}
219213
ViewPathList(_, ref source_items) => {
220214
// Make sure there's at most one `mod` import in the list.
@@ -265,7 +259,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
265259
source_item.span,
266260
source_item.node.id(),
267261
is_public,
268-
shadowable);
262+
is_prelude);
269263
}
270264
}
271265
ViewPathGlob(_) => {
@@ -275,7 +269,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
275269
view_path.span,
276270
item.id,
277271
is_public,
278-
shadowable);
272+
is_prelude);
279273
}
280274
}
281275
parent
@@ -661,7 +655,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
661655
span: Span,
662656
id: NodeId,
663657
is_public: bool,
664-
shadowable: Shadowable) {
658+
is_prelude: bool) {
665659
// Bump the reference count on the name. Or, if this is a glob, set
666660
// the appropriate flag.
667661

@@ -678,7 +672,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
678672
}
679673

680674
let directive =
681-
ImportDirective::new(module_path, subclass, span, id, is_public, shadowable);
675+
ImportDirective::new(module_path, subclass, span, id, is_public, is_prelude);
682676
module_.add_import_directive(directive);
683677
self.unresolved_imports += 1;
684678
}

src/librustc_resolve/resolve_imports.rs

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -57,13 +57,6 @@ impl ImportDirectiveSubclass {
5757
}
5858
}
5959

60-
/// Whether an import can be shadowed by another import.
61-
#[derive(Debug,PartialEq,Clone,Copy)]
62-
pub enum Shadowable {
63-
Always,
64-
Never,
65-
}
66-
6760
/// One import directive.
6861
#[derive(Debug,Clone)]
6962
pub struct ImportDirective {
@@ -72,7 +65,7 @@ pub struct ImportDirective {
7265
pub span: Span,
7366
pub id: NodeId,
7467
pub is_public: bool, // see note in ImportResolutionPerNamespace about how to use this
75-
pub shadowable: Shadowable,
68+
pub is_prelude: bool,
7669
}
7770

7871
impl ImportDirective {
@@ -81,15 +74,15 @@ impl ImportDirective {
8174
span: Span,
8275
id: NodeId,
8376
is_public: bool,
84-
shadowable: Shadowable)
77+
is_prelude: bool)
8578
-> ImportDirective {
8679
ImportDirective {
8780
module_path: module_path,
8881
subclass: subclass,
8982
span: span,
9083
id: id,
9184
is_public: is_public,
92-
shadowable: shadowable,
85+
is_prelude: is_prelude,
9386
}
9487
}
9588

@@ -105,7 +98,7 @@ impl ImportDirective {
10598
if let GlobImport = self.subclass {
10699
modifiers = modifiers | DefModifiers::GLOB_IMPORTED;
107100
}
108-
if self.shadowable == Shadowable::Always {
101+
if self.is_prelude {
109102
modifiers = modifiers | DefModifiers::PRELUDE;
110103
}
111104

0 commit comments

Comments
 (0)