diff --git a/compiler/rustc_resolve/src/build_reduced_graph.rs b/compiler/rustc_resolve/src/build_reduced_graph.rs index 4148ec1b7abd..4a7237ba192b 100644 --- a/compiler/rustc_resolve/src/build_reduced_graph.rs +++ b/compiler/rustc_resolve/src/build_reduced_graph.rs @@ -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); diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index a9b2ad9223a3..982e92a0c149 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -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)) }); }