1 //! HIR datatypes. See the [rustc guide] for more info.
3 //! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
8 use crate::ty
::query
::Providers
;
10 use rustc_hir
::def_id
::{DefId, LOCAL_CRATE}
;
16 /// A wrapper type which allows you to access HIR.
18 pub struct Hir
<'tcx
> {
20 map
: &'tcx map
::Map
<'tcx
>,
23 impl<'tcx
> Hir
<'tcx
> {
24 pub fn krate(&self) -> &'tcx Crate
<'tcx
> {
25 self.tcx
.hir_crate(LOCAL_CRATE
)
29 impl<'tcx
> Deref
for Hir
<'tcx
> {
30 type Target
= &'tcx map
::Map
<'tcx
>;
33 fn deref(&self) -> &Self::Target
{
38 impl<'hir
> print
::PpAnn
for Hir
<'hir
> {
39 fn nested(&self, state
: &mut print
::State
<'_
>, nested
: print
::Nested
) {
40 self.map
.nested(state
, nested
)
44 impl<'tcx
> TyCtxt
<'tcx
> {
46 pub fn hir(self) -> Hir
<'tcx
> {
47 Hir { tcx: self, map: &self.hir_map }
50 pub fn parent_module(self, id
: HirId
) -> DefId
{
51 self.parent_module_from_def_id(DefId
::local(id
.owner
))
55 pub fn provide(providers
: &mut Providers
<'_
>) {
56 providers
.parent_module_from_def_id
= |tcx
, id
| {
58 hir
.local_def_id(hir
.get_module_parent_node(hir
.as_local_hir_id(id
).unwrap()))
60 providers
.hir_crate
= |tcx
, _
| tcx
.hir_map
.untracked_krate();
61 map
::provide(providers
);