Stop creating ctor def ids for unions and move the ctor def id creation into the brg

This commit is contained in:
Oli Scherer
2026-04-20 14:27:50 +02:00
parent 9ab01ae53c
commit af3e34bf65
2 changed files with 10 additions and 19 deletions
@@ -902,7 +902,7 @@ fn build_reduced_graph_for_item(&mut self, item: &'a Item) {
// If this is a tuple or unit struct, define a name
// in the value namespace as well.
if let Some(ctor_node_id) = vdata.ctor_node_id() {
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(vdata) {
// If the structure is marked as non_exhaustive then lower the visibility
// to within the crate.
let mut ctor_vis = if vis.is_public()
@@ -927,6 +927,14 @@ fn build_reduced_graph_for_item(&mut self, item: &'a Item) {
}
field_visibilities.push(field_vis.to_def_id());
}
// If this is a unit or tuple-like struct, register the constructor.
self.create_def(
ctor_node_id,
None,
DefKind::Ctor(CtorOf::Struct, ctor_kind),
item.span,
);
let feed = self.r.feed(ctor_node_id);
let ctor_def_id = feed.key();
let ctor_res = self.res(ctor_def_id);
+1 -18
View File
@@ -191,24 +191,7 @@ fn visit_item(&mut self, i: &'a Item) {
}
self.with_parent(def_id, |this| {
this.with_impl_trait(ImplTraitContext::Existential, |this| {
match i.kind {
ItemKind::Struct(_, _, ref struct_def)
| ItemKind::Union(_, _, ref struct_def) => {
// If this is a unit or tuple-like struct, register the constructor.
if let Some((ctor_kind, ctor_node_id)) = CtorKind::from_ast(struct_def) {
this.create_def(
ctor_node_id,
None,
DefKind::Ctor(CtorOf::Struct, ctor_kind),
i.span,
);
}
}
_ => {}
}
this.brg_visit_item(i);
})
this.with_impl_trait(ImplTraitContext::Existential, |this| this.brg_visit_item(i))
});
}