forked from rust-lang/rust
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmod.rs
54 lines (45 loc) · 1.19 KB
/
mod.rs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
//! HIR datatypes. See the [rustc guide] for more info.
//!
//! [rustc guide]: https://rust-lang.github.io/rustc-guide/hir.html
pub mod check_attr;
pub mod exports;
pub mod map;
use crate::ty::query::Providers;
use crate::ty::TyCtxt;
use rustc_hir::def_id::LOCAL_CRATE;
use rustc_hir::print;
use rustc_hir::Crate;
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)
}
}
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<'_>) {
providers.hir_crate = |tcx, _| tcx.hir_map.untracked_krate();
map::provide(providers);
}