about summary refs log tree commit diff
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2023-09-09 21:45:47 +0000
committerbors <bors@rust-lang.org>2023-09-09 21:45:47 +0000
commit8ed4537d7c238eb77509d82445cf1cb861a3b5ff (patch)
tree61e628c6ca6e64831a7f09b3d9f027bf370c0add
parent559421e8e3ab373a296186104b7b0c18251e8182 (diff)
parentd190ebf2fc079a1437416bbd95dbaf9eed783bd1 (diff)
downloadrust-8ed4537d7c238eb77509d82445cf1cb861a3b5ff.tar.gz
rust-8ed4537d7c238eb77509d82445cf1cb861a3b5ff.zip
Auto merge of #115703 - ouz-a:smir_span, r=oli-obk
Add function that returns span of an item in smir

Addressees https://github.com/rust-lang/project-stable-mir/issues/31

Maybe we should change `Span = Opaque` into something else, and then return `String` with newly added function, I don't think it matters that much though, since we are not storing `Span` anywhere.

r? `@oli-obk`
-rw-r--r--compiler/rustc_smir/src/rustc_smir/mod.rs4
-rw-r--r--compiler/rustc_smir/src/stable_mir/mod.rs7
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;