diff options
| author | ouz-a <ouz.agz@gmail.com> | 2023-09-09 14:17:36 +0300 |
|---|---|---|
| committer | ouz-a <ouz.agz@gmail.com> | 2023-09-09 14:17:36 +0300 |
| commit | d190ebf2fc079a1437416bbd95dbaf9eed783bd1 (patch) | |
| tree | e9e3fe98a5696e836bc7f6bcf76cd378d0b82ef9 | |
| parent | 5ede9408945b46ab183dd228253297bdf62304f7 (diff) | |
| download | rust-d190ebf2fc079a1437416bbd95dbaf9eed783bd1.tar.gz rust-d190ebf2fc079a1437416bbd95dbaf9eed783bd1.zip | |
add function that returns span of an item
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 4 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/mod.rs | 7 |
2 files changed, 11 insertions, 0 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index a7640736481..7e533f990fd 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -42,6 +42,10 @@ impl<'tcx> Context for Tables<'tcx> { self.tcx.def_path_str(self[def_id]) } + fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> stable_mir::ty::Span { + self.tcx.def_span(self[def_id]).stable(self) + } + fn all_local_items(&mut self) -> stable_mir::CrateItems { self.tcx.mir_keys(()).iter().map(|item| self.crate_item(item.to_def_id())).collect() } diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index 9cab7230b97..508e3aa1291 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -89,6 +89,10 @@ impl CrateItem { pub fn body(&self) -> mir::Body { with(|cx| cx.mir_body(self.0)) } + + pub fn span(&self) -> ty::Span { + with(|cx| cx.span_of_an_item(self.0)) + } } /// Return the function where execution starts if the current @@ -156,6 +160,9 @@ pub trait Context { /// Prints the name of given `DefId` fn name_of_def_id(&self, def_id: DefId) -> String; + /// `Span` of an item + fn span_of_an_item(&mut self, def_id: DefId) -> Span; + /// Obtain the representation of a type. fn ty_kind(&mut self, ty: Ty) -> TyKind; |
