1
Fork 0
rust/src/librustc/hir/mod.rs

54 lines
1.2 KiB
Rust
Raw Normal View History

//! HIR datatypes. See the [rustc guide] for more info.
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
pub mod exports;
pub mod map;
use crate::ty::query::Providers;
2020-02-06 11:59:29 +01:00
use crate::ty::TyCtxt;
use rustc_hir::def_id::LOCAL_CRATE;
2020-02-06 11:59:29 +01:00
use rustc_hir::print;
use rustc_hir::Crate;
2020-02-06 11:59:29 +01:00
use std::ops::Deref;
/// A wrapper type which allows you to access HIR.
#[derive(Clone)]
pub struct Hir<'tcx> {
tcx: TyCtxt<'tcx>,
map: &'tcx map::Map<'tcx>,
}
impl<'tcx> Hir<'tcx> {
pub fn krate(&self) -> &'tcx Crate<'tcx> {
self.tcx.hir_crate(LOCAL_CRATE)
}
}
2020-02-06 11:59:29 +01:00
impl<'tcx> Deref for Hir<'tcx> {
type Target = &'tcx map::Map<'tcx>;
#[inline(always)]
fn deref(&self) -> &Self::Target {
&self.map
}
}
impl<'hir> print::PpAnn for Hir<'hir> {
fn nested(&self, state: &mut print::State<'_>, nested: print::Nested) {
self.map.nested(state, nested)
}
}
impl<'tcx> TyCtxt<'tcx> {
#[inline(always)]
pub fn hir(self) -> Hir<'tcx> {
Hir { tcx: self, map: &self.hir_map }
}
}
pub fn provide(providers: &mut Providers<'_>) {
2020-02-06 13:41:37 +01:00
providers.hir_crate = |tcx, _| tcx.hir_map.untracked_krate();
map::provide(providers);
}