From d190ebf2fc079a1437416bbd95dbaf9eed783bd1 Mon Sep 17 00:00:00 2001 From: ouz-a Date: Sat, 9 Sep 2023 14:17:36 +0300 Subject: [PATCH] add function that returns span of an item --- compiler/rustc_smir/src/rustc_smir/mod.rs | 4 ++++ compiler/rustc_smir/src/stable_mir/mod.rs | 7 +++++++ 2 files changed, 11 insertions(+) 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;