Stream: t-compiler/help

Topic: Why is def_id_visibility private?

Joshua Nelson (May 30 2020 at 05:20, on Zulip):

Hello all, I'm trying to fix and I need to know the visibility of the linked item for that. My idea was to use rustc_privacy::def_id_visibility to look it up, but that function is private. Is there a reason for that, is there a better way to find that information?

Matthew Jasper (May 30 2020 at 08:51, on Zulip):


Joshua Nelson (May 30 2020 at 15:18, on Zulip):

Hmm, if I try that I get this error instead:

error[E0308]: mismatched types
   --> src/librustdoc/passes/
709 |                     if ! {
    |                                                                                                       ^^^^^^ expected struct `rustc_hir::HirId`, found struct `rustc_span::def_id::DefId`
Joshua Nelson (May 30 2020 at 15:19, on Zulip):

I got def_id from Res::opt_def_id():

lcnr (May 30 2020 at 15:20, on Zulip):

you can use tcx.hir().as_local_hir_id(def_id.as_local()?) to get the relevant HirId

marmeladema (May 30 2020 at 15:27, on Zulip):

You can also use def_id.expect_local(), "localize" the def id or panic if the def is is foreign. You can use that if the call should never fail.

Joshua Nelson (May 30 2020 at 15:32, on Zulip):

I'd rather avoid expect() calls until I know the code base better, as_local() works pretty well though :)

                if let Some(local) = res.opt_def_id().and_then(|def_id| def_id.as_local()) {
                    let hir_id =;
                    if ! {
Last update: Sep 27 2020 at 14:15UTC