Skip to content

Commit af3e34b

Browse files
committed
Stop creating ctor def ids for unions and move the ctor def id creation into the brg
1 parent 9ab01ae commit af3e34b

2 files changed

Lines changed: 10 additions & 19 deletions

File tree

compiler/rustc_resolve/src/build_reduced_graph.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -902,7 +902,7 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
902902

903903
// If this is a tuple or unit struct, define a name
904904
// in the value namespace as well.
905-
if let Some(ctor_node_id) = vdata.ctor_node_id() {
905+
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(vdata) {
906906
// If the structure is marked as non_exhaustive then lower the visibility
907907
// to within the crate.
908908
let mut ctor_vis = if vis.is_public()
@@ -927,6 +927,14 @@ impl<'a, 'ra, 'tcx> DefCollector<'a, 'ra, 'tcx> {
927927
}
928928
field_visibilities.push(field_vis.to_def_id());
929929
}
930+
// If this is a unit or tuple-like struct, register the constructor.
931+
self.create_def(
932+
ctor_node_id,
933+
None,
934+
DefKind::Ctor(CtorOf::Struct, ctor_kind),
935+
item.span,
936+
);
937+
930938
let feed = self.r.feed(ctor_node_id);
931939
let ctor_def_id = feed.key();
932940
let ctor_res = self.res(ctor_def_id);

compiler/rustc_resolve/src/def_collector.rs

Lines changed: 1 addition & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -191,24 +191,7 @@ impl<'a, 'ra, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'ra, 'tcx> {
191191
}
192192

193193
self.with_parent(def_id, |this| {
194-
this.with_impl_trait(ImplTraitContext::Existential, |this| {
195-
match i.kind {
196-
ItemKind::Struct(_, _, ref struct_def)
197-
| ItemKind::Union(_, _, ref struct_def) => {
198-
// If this is a unit or tuple-like struct, register the constructor.
199-
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
200-
this.create_def(
201-
ctor_node_id,
202-
None,
203-
DefKind::Ctor(CtorOf::Struct, ctor_kind),
204-
i.span,
205-
);
206-
}
207-
}
208-
_ => {}
209-
}
210-
this.brg_visit_item(i);
211-
})
194+
this.with_impl_trait(ImplTraitContext::Existential, |this| this.brg_visit_item(i))
212195
});
213196
}
214197

0 commit comments

Comments
 (0)