Skip to content

Commit 84de641

Browse files
committed
def collector: Set correct namespace in DefPathData for foreign types
1 parent f0dc906 commit 84de641

File tree

2 files changed

+11
-17
lines changed

2 files changed

+11
-17
lines changed

Diff for: compiler/rustc_resolve/src/def_collector.rs

+10-16
Original file line numberDiff line numberDiff line change
@@ -194,25 +194,19 @@ impl<'a, 'b, 'tcx> visit::Visitor<'a> for DefCollector<'a, 'b, 'tcx> {
194194
visit::walk_use_tree(self, use_tree, id);
195195
}
196196

197-
fn visit_foreign_item(&mut self, foreign_item: &'a ForeignItem) {
198-
let def_kind = match foreign_item.kind {
199-
ForeignItemKind::Static(_, mt, _) => DefKind::Static(mt),
200-
ForeignItemKind::Fn(_) => DefKind::Fn,
201-
ForeignItemKind::TyAlias(_) => DefKind::ForeignTy,
202-
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(foreign_item.id),
197+
fn visit_foreign_item(&mut self, fi: &'a ForeignItem) {
198+
let (def_data, def_kind) = match fi.kind {
199+
ForeignItemKind::Static(_, mt, _) => {
200+
(DefPathData::ValueNs(fi.ident.name), DefKind::Static(mt))
201+
}
202+
ForeignItemKind::Fn(_) => (DefPathData::ValueNs(fi.ident.name), DefKind::Fn),
203+
ForeignItemKind::TyAlias(_) => (DefPathData::TypeNs(fi.ident.name), DefKind::ForeignTy),
204+
ForeignItemKind::MacCall(_) => return self.visit_macro_invoc(fi.id),
203205
};
204206

205-
// FIXME: The namespace is incorrect for foreign types.
206-
let def = self.create_def(
207-
foreign_item.id,
208-
DefPathData::ValueNs(foreign_item.ident.name),
209-
def_kind,
210-
foreign_item.span,
211-
);
207+
let def = self.create_def(fi.id, def_data, def_kind, fi.span);
212208

213-
self.with_parent(def, |this| {
214-
visit::walk_foreign_item(this, foreign_item);
215-
});
209+
self.with_parent(def, |this| visit::walk_foreign_item(this, fi));
216210
}
217211

218212
fn visit_variant(&mut self, v: &'a Variant) {

Diff for: tests/ui/symbol-names/foreign-types.stderr

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB<REF>_5CheckNvB<REF>_11ForeignTypeE)
1+
error: symbol-name(_RMCsCRATE_HASH_13foreign_typesINtB<REF>_5CheckNtB<REF>_11ForeignTypeE)
22
--> $DIR/foreign-types.rs:13:1
33
|
44
LL | #[rustc_symbol_name]

0 commit comments

Comments
 (0)