Skip to content

Commit 0d08467

Browse files
committed
resolve: Do not afraid to set current module to enums and traits
1 parent ef54f57 commit 0d08467

File tree

2 files changed

+9
-8
lines changed

2 files changed

+9
-8
lines changed

src/librustc_resolve/build_reduced_graph.rs

+4-7
Original file line numberDiff line numberDiff line change
@@ -728,9 +728,10 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
728728
expansion,
729729
item.span);
730730
self.r.define(parent, ident, TypeNS, (module, vis, sp, expansion));
731+
self.parent_scope.module = module;
731732

732733
for variant in &(*enum_definition).variants {
733-
self.build_reduced_graph_for_variant(variant, module, vis);
734+
self.build_reduced_graph_for_variant(variant, vis);
734735
}
735736
}
736737

@@ -818,10 +819,8 @@ impl<'a, 'b> BuildReducedGraphVisitor<'a, 'b> {
818819

819820
// Constructs the reduced graph for one variant. Variants exist in the
820821
// type and value namespaces.
821-
fn build_reduced_graph_for_variant(&mut self,
822-
variant: &Variant,
823-
parent: Module<'a>,
824-
vis: ty::Visibility) {
822+
fn build_reduced_graph_for_variant(&mut self, variant: &Variant, vis: ty::Visibility) {
823+
let parent = self.parent_scope.module;
825824
let expn_id = self.parent_scope.expansion;
826825
let ident = variant.ident;
827826

@@ -1253,9 +1252,7 @@ impl<'a, 'b> Visitor<'b> for BuildReducedGraphVisitor<'a, 'b> {
12531252
let expansion = self.parent_scope.expansion;
12541253
self.r.define(parent, item.ident, ns, (res, vis, item.span, expansion));
12551254

1256-
self.parent_scope.module = parent.parent.unwrap(); // nearest normal ancestor
12571255
visit::walk_trait_item(self, item);
1258-
self.parent_scope.module = parent;
12591256
}
12601257

12611258
fn visit_token(&mut self, t: Token) {

src/librustc_resolve/lib.rs

+5-1
Original file line numberDiff line numberDiff line change
@@ -538,7 +538,11 @@ impl<'a> ModuleData<'a> {
538538
}
539539

540540
fn nearest_item_scope(&'a self) -> Module<'a> {
541-
if self.is_trait() { self.parent.unwrap() } else { self }
541+
match self.kind {
542+
ModuleKind::Def(DefKind::Enum, ..) | ModuleKind::Def(DefKind::Trait, ..) =>
543+
self.parent.expect("enum or trait module without a parent"),
544+
_ => self,
545+
}
542546
}
543547

544548
fn is_ancestor_of(&self, mut other: &Self) -> bool {

0 commit comments

Comments
 (0)