Skip to content

Commit 21064d0

Browse files
committed
Refactor away resolve_imports::Shadowable and rename shadowable -> is_prelude
1 parent 64a13a4 commit 21064d0

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};
@@ -161,14 +160,9 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
161160
};
162161

163162
// Build up the import directives.
164-
let shadowable = item.attrs.iter().any(|attr| {
163+
let is_prelude = item.attrs.iter().any(|attr| {
165164
attr.name() == special_idents::prelude_import.name.as_str()
166165
});
167-
let shadowable = if shadowable {
168-
Shadowable::Always
169-
} else {
170-
Shadowable::Never
171-
};
172166

173167
match view_path.node {
174168
ViewPathSimple(binding, ref full_path) => {
@@ -186,7 +180,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
186180
view_path.span,
187181
item.id,
188182
is_public,
189-
shadowable);
183+
is_prelude);
190184
}
191185
ViewPathList(_, ref source_items) => {
192186
// Make sure there's at most one `mod` import in the list.
@@ -237,7 +231,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
237231
source_item.span,
238232
source_item.node.id(),
239233
is_public,
240-
shadowable);
234+
is_prelude);
241235
}
242236
}
243237
ViewPathGlob(_) => {
@@ -247,7 +241,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
247241
view_path.span,
248242
item.id,
249243
is_public,
250-
shadowable);
244+
is_prelude);
251245
}
252246
}
253247
parent
@@ -631,7 +625,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
631625
span: Span,
632626
id: NodeId,
633627
is_public: bool,
634-
shadowable: Shadowable) {
628+
is_prelude: bool) {
635629
// Bump the reference count on the name. Or, if this is a glob, set
636630
// the appropriate flag.
637631

@@ -648,7 +642,7 @@ impl<'a, 'b:'a, 'tcx:'b> GraphBuilder<'a, 'b, 'tcx> {
648642
}
649643

650644
let directive =
651-
ImportDirective::new(module_path, subclass, span, id, is_public, shadowable);
645+
ImportDirective::new(module_path, subclass, span, id, is_public, is_prelude);
652646
module_.add_import_directive(directive);
653647
self.unresolved_imports += 1;
654648
}

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)