From 84de641484fcb337351947573c7c8608ee52dfc2 Mon Sep 17 00:00:00 2001 From: Vadim Petrochenkov Date: Tue, 28 Nov 2023 15:43:07 +0300 Subject: [PATCH] def collector: Set correct namespace in `DefPathData` for foreign types --- compiler/rustc_resolve/src/def_collector.rs | 26 ++++++++------------- tests/ui/symbol-names/foreign-types.stderr | 2 +- 2 files changed, 11 insertions(+), 17 deletions(-) diff --git a/compiler/rustc_resolve/src/def_collector.rs b/compiler/rustc_resolve/src/def_collector.rs index cf3e787d839..224f3f36a3f 100644 --- a/compiler/rustc_resolve/src/def_collector.rs +++ b/compiler/rustc_resolve/src/def_collector.rs @@ -194,25 +194,19 @@ fn visit_use_tree(&mut self, use_tree: &'a UseTree, id: NodeId, _nested: bool) { visit::walk_use_tree(self, use_tree, id); } - fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) { - let def_kind = match foreign_item.kind { - ForeignItemKind::Static(_, mt, _) => DefKind::Static(mt), - ForeignItemKind::Fn(_) => DefKind::Fn, - ForeignItemKind::TyAlias(_) => DefKind::ForeignTy, - ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(foreign_item.id), + fn visit_foreign_item(&mut self, fi: &'a ForeignItem) { + let (def_data, def_kind) = match fi.kind { + ForeignItemKind::Static(_, mt, _) => { + (DefPathData::ValueNs(fi.ident.name), DefKind::Static(mt)) + } + ForeignItemKind::Fn(_) => (DefPathData::ValueNs(fi.ident.name), DefKind::Fn), + ForeignItemKind::TyAlias(_) => (DefPathData::TypeNs(fi.ident.name), DefKind::ForeignTy), + ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id), }; - // FIXME: The namespace is incorrect for foreign types. - let def = self.create_def( - foreign_item.id, - DefPathData::ValueNs(foreign_item.ident.name), - def_kind, - foreign_item.span, - ); + let def = self.create_def(fi.id, def_data, def_kind, fi.span); - self.with_parent(def, |this| { - visit::walk_foreign_item(this, foreign_item); - }); + self.with_parent(def, |this| visit::walk_foreign_item(this, fi)); } fn visit_variant(&mut self, v: &'a Variant) { diff --git a/tests/ui/symbol-names/foreign-types.stderr b/tests/ui/symbol-names/foreign-types.stderr index 9c8633742b2..63044991485 100644 --- a/tests/ui/symbol-names/foreign-types.stderr +++ b/tests/ui/symbol-names/foreign-types.stderr @@ -1,4 +1,4 @@ -error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB_5CheckNvB_11ForeignTypeE) +error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB_5CheckNtB_11ForeignTypeE) --> $DIR/foreign-types.rs:13:1 | LL | #[rustc_symbol_name]