Skip to content

Commit

Permalink
def collector: Set correct namespace in DefPathData for foreign types
Browse files Browse the repository at this point in the history
  • Loading branch information
petrochenkov committed Nov 28, 2023
1 parent f0dc906 commit 84de641
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 17 deletions.
26 changes: 10 additions & 16 deletions compiler/rustc_resolve/src/def_collector.rs
Original file line number Diff line number Diff line change
Expand Up @@ -194,25 +194,19 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
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) {
Expand Down
2 changes: 1 addition & 1 deletion tests/ui/symbol-names/foreign-types.stderr
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB<REF>_5CheckNvB<REF>_11ForeignTypeE)
error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB<REF>_5CheckNtB<REF>_11ForeignTypeE)
--> $DIR/foreign-types.rs:13:1
|
LL | #[rustc_symbol_name]
Expand Down

0 comments on commit 84de641

Please sign in to comment.