Skip to content

Add function that returns span of an item in smir #115703

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Sep 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions compiler/rustc_smir/src/rustc_smir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
7 changes: 7 additions & 0 deletions compiler/rustc_smir/src/stable_mir/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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;

Expand Down