Skip to content

Commit 8ed4537

Browse files
committed
Auto merge of rust-lang#115703 - ouz-a:smir_span, r=oli-obk
Add function that returns span of an item in smir Addressees rust-lang/project-stable-mir#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`
2 parents 559421e + d190ebf commit 8ed4537

File tree

2 files changed

+11
-0
lines changed

2 files changed

+11
-0
lines changed

compiler/rustc_smir/src/rustc_smir/mod.rs

+4
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,10 @@ impl<'tcx> Context for Tables<'tcx> {
4242
self.tcx.def_path_str(self[def_id])
4343
}
4444

45+
fn span_of_an_item(&mut self, def_id: stable_mir::DefId) -> stable_mir::ty::Span {
46+
self.tcx.def_span(self[def_id]).stable(self)
47+
}
48+
4549
fn all_local_items(&mut self) -> stable_mir::CrateItems {
4650
self.tcx.mir_keys(()).iter().map(|item| self.crate_item(item.to_def_id())).collect()
4751
}

compiler/rustc_smir/src/stable_mir/mod.rs

+7
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,10 @@ impl CrateItem {
8989
pub fn body(&self) -> mir::Body {
9090
with(|cx| cx.mir_body(self.0))
9191
}
92+
93+
pub fn span(&self) -> ty::Span {
94+
with(|cx| cx.span_of_an_item(self.0))
95+
}
9296
}
9397

9498
/// Return the function where execution starts if the current
@@ -156,6 +160,9 @@ pub trait Context {
156160
/// Prints the name of given `DefId`
157161
fn name_of_def_id(&self, def_id: DefId) -> String;
158162

163+
/// `Span` of an item
164+
fn span_of_an_item(&mut self, def_id: DefId) -> Span;
165+
159166
/// Obtain the representation of a type.
160167
fn ty_kind(&mut self, ty: Ty) -> TyKind;
161168

0 commit comments

Comments
 (0)