Stream: t-compiler/help

Topic: How do I get an Item from a DefId?


Joshua Nelson (Jun 06 2020 at 20:09, on Zulip):

Sort of the opposite of https://rust-lang.zulipchat.com/#narrow/stream/182449-t-compiler.2Fhelp/topic/How.20do.20I.20get.20the.20module.20that.20an.20Item.20belongs.20to.3F - I have a rustc_hir::DefId and I want to get a rustc_hir::Item. Is there a way to do that? In case it helps, I don't need the whole Item, just the ItemKind.

Matthew Jasper (Jun 06 2020 at 20:21, on Zulip):

You can't get the ItemKind for cross-crate items. Is tcx.def_kind good enough for what you need?

Joshua Nelson (Jun 06 2020 at 20:35, on Zulip):

I think I found it going another way, rustdoc stores an ImportSource which I think has the DefId of the item being imported: https://github.com/rust-lang/rust/blob/master/src/librustdoc/clean/types.rs#L1500

Joshua Nelson (Jun 06 2020 at 20:37, on Zulip):

Are HirIds only for the current crate? Or can they be cross-crate?

Matthew Jasper (Jun 06 2020 at 20:38, on Zulip):

Only the current crate

Joshua Nelson (Jun 06 2020 at 20:40, on Zulip):

Got it, so this is why resolve_str_path_error only works on local items. Thanks.

Last update: Sep 27 2020 at 13:45UTC