Skip to content

Commit 5f47915

Browse files
committed
Refactor is_prelude to only apply to glob imports
1 parent aa58887 commit 5f47915

File tree

2 files changed

+16
-30
lines changed

2 files changed

+16
-30
lines changed

src/librustc_resolve/build_reduced_graph.rs

Lines changed: 7 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -177,13 +177,9 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
177177
}
178178

179179
let subclass = ImportDirectiveSubclass::single(binding, source_name);
180+
let span = view_path.span;
181+
parent.add_import_directive(module_path, subclass, span, item.id, vis);
180182
self.unresolved_imports += 1;
181-
parent.add_import_directive(module_path,
182-
subclass,
183-
view_path.span,
184-
item.id,
185-
vis,
186-
is_prelude);
187183
}
188184
ViewPathList(_, ref source_items) => {
189185
// Make sure there's at most one `mod` import in the list.
@@ -228,23 +224,16 @@ impl<'b, 'tcx:'b> Resolver<'b, 'tcx> {
228224
}
229225
};
230226
let subclass = ImportDirectiveSubclass::single(rename, name);
227+
let (span, id) = (source_item.span, source_item.node.id());
228+
parent.add_import_directive(module_path, subclass, span, id, vis);
231229
self.unresolved_imports += 1;
232-
parent.add_import_directive(module_path,
233-
subclass,
234-
source_item.span,
235-
source_item.node.id(),
236-
vis,
237-
is_prelude);
238230
}
239231
}
240232
ViewPathGlob(_) => {
233+
let subclass = GlobImport { is_prelude: is_prelude };
234+
let span = view_path.span;
235+
parent.add_import_directive(module_path, subclass, span, item.id, vis);
241236
self.unresolved_imports += 1;
242-
parent.add_import_directive(module_path,
243-
GlobImport,
244-
view_path.span,
245-
item.id,
246-
vis,
247-
is_prelude);
248237
}
249238
}
250239
}

src/librustc_resolve/resolve_imports.rs

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@ pub enum ImportDirectiveSubclass {
4141
type_determined: Cell<bool>,
4242
value_determined: Cell<bool>,
4343
},
44-
GlobImport,
44+
GlobImport { is_prelude: bool },
4545
}
4646

4747
impl ImportDirectiveSubclass {
@@ -64,7 +64,6 @@ pub struct ImportDirective<'a> {
6464
subclass: ImportDirectiveSubclass,
6565
span: Span,
6666
vis: ty::Visibility, // see note in ImportResolutionPerNamespace about how to use this
67-
is_prelude: bool,
6867
}
6968

7069
impl<'a> ImportDirective<'a> {
@@ -84,7 +83,7 @@ impl<'a> ImportDirective<'a> {
8483
}
8584

8685
pub fn is_glob(&self) -> bool {
87-
match self.subclass { ImportDirectiveSubclass::GlobImport => true, _ => false }
86+
match self.subclass { ImportDirectiveSubclass::GlobImport { .. } => true, _ => false }
8887
}
8988
}
9089

@@ -191,7 +190,7 @@ impl<'a> NameResolution<'a> {
191190
};
192191
let name = match directive.subclass {
193192
SingleImport { source, .. } => source,
194-
GlobImport => unreachable!(),
193+
GlobImport { .. } => unreachable!(),
195194
};
196195
match target_module.resolve_name(name, ns, false) {
197196
Failed(_) => {}
@@ -282,16 +281,14 @@ impl<'a> ::ModuleS<'a> {
282281
subclass: ImportDirectiveSubclass,
283282
span: Span,
284283
id: NodeId,
285-
vis: ty::Visibility,
286-
is_prelude: bool) {
284+
vis: ty::Visibility) {
287285
let directive = self.arenas.alloc_import_directive(ImportDirective {
288286
module_path: module_path,
289287
target_module: Cell::new(None),
290288
subclass: subclass,
291289
span: span,
292290
id: id,
293291
vis: vis,
294-
is_prelude: is_prelude,
295292
});
296293

297294
self.unresolved_imports.borrow_mut().push(directive);
@@ -304,8 +301,8 @@ impl<'a> ::ModuleS<'a> {
304301
}
305302
// We don't add prelude imports to the globs since they only affect lexical scopes,
306303
// which are not relevant to import resolution.
307-
GlobImport if directive.is_prelude => {}
308-
GlobImport => self.globs.borrow_mut().push(directive),
304+
GlobImport { is_prelude: true } => {}
305+
GlobImport { .. } => self.globs.borrow_mut().push(directive),
309306
}
310307
}
311308

@@ -496,7 +493,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
496493
let (source, target, value_determined, type_determined) = match directive.subclass {
497494
SingleImport { source, target, ref value_determined, ref type_determined } =>
498495
(source, target, value_determined, type_determined),
499-
GlobImport => return self.resolve_glob_import(target_module, directive),
496+
GlobImport { .. } => return self.resolve_glob_import(target_module, directive),
500497
};
501498

502499
// We need to resolve both namespaces for this to succeed.
@@ -644,7 +641,7 @@ impl<'a, 'b:'a, 'tcx:'b> ImportResolver<'a, 'b, 'tcx> {
644641
}
645642
self.resolver.populate_module_if_necessary(target_module);
646643

647-
if directive.is_prelude {
644+
if let GlobImport { is_prelude: true } = directive.subclass {
648645
*module_.prelude.borrow_mut() = Some(target_module);
649646
return Success(());
650647
}
@@ -747,7 +744,7 @@ fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) ->
747744
fn import_directive_subclass_to_string(subclass: &ImportDirectiveSubclass) -> String {
748745
match *subclass {
749746
SingleImport { source, .. } => source.to_string(),
750-
GlobImport => "*".to_string(),
747+
GlobImport { .. } => "*".to_string(),
751748
}
752749
}
753750

0 commit comments

Comments
 (0)