Currently I have the following code:
item.def_id.as_local().map(|def_id| self.cx.tcx.hir().as_local_hir_id(def_id)) = Some(hir::CRATE_HIR_ID). Is there an easier way to do this?
(sorry, I keep replying in the wrong thread)
Yes, that should work.
@Joshua Nelson you generally shouldn't need to convert a
DefId into a
HirId unless you plan to grab some HIR nodes. kind of weird that
CRATE_HIR_ID even exists tbh
I guess this makes sense but it could be a constant shrug https://github.com/rust-lang/rust/blob/master/src/librustc_span/def_id.rs#L167
This is left over from when intra-doc links were first written and people assumed they would always be to within the local crate
sure, what I mean is that
HirId only makes sense if you actually go poking at the HIR
most of the time, having a
DefId is the "better" thing to have
HirId is like a "downgrade"
(it's also not free to convert to it, for now)
hmm now I'm wondering if this code will break if you implement a foreign trait for a type in a different module https://github.com/rust-lang/rust/blob/b11656273c16c647c367ffa95203722cd3cf41b3/src/librustdoc/passes/collect_intra_doc_links.rs#L298
assuming you mean that the
as_local_hir_id would return
ok neat, and the only other place
hir() is called is for
Self which shouldn't lead to issues
and checking if the item is private, which only happens if it's a local item anyway