diff options
| author | Matthias Krüger <matthias.krueger@famsik.de> | 2023-09-05 07:15:17 +0200 |
|---|---|---|
| committer | GitHub <noreply@github.com> | 2023-09-05 07:15:17 +0200 |
| commit | 03853d59ce84e468f174759d24e063198d6e7ea3 (patch) | |
| tree | 72ceb1a8b94d5d611c21d325ca48f888446dcc63 | |
| parent | f5e6aa3c4a1a58b468cb38ccd3f8198dfb900987 (diff) | |
| parent | 56d10a883e716fe252a60622d1e117a6f1970e3a (diff) | |
| download | rust-03853d59ce84e468f174759d24e063198d6e7ea3.tar.gz rust-03853d59ce84e468f174759d24e063198d6e7ea3.zip | |
Rollup merge of #115534 - ouz-a:smir_def, r=oli-obk
Expose more information with DefId in smir Currently `Debug` for `DefId` doesn't provide enough information, this changes so that we get `usize` of the `DefId` and the name of it. r? `@oli-obk`
| -rw-r--r-- | compiler/rustc_smir/src/rustc_smir/mod.rs | 5 | ||||
| -rw-r--r-- | compiler/rustc_smir/src/stable_mir/mod.rs | 16 |
2 files changed, 20 insertions, 1 deletions
diff --git a/compiler/rustc_smir/src/rustc_smir/mod.rs b/compiler/rustc_smir/src/rustc_smir/mod.rs index 822a6e48658..b4c150c591c 100644 --- a/compiler/rustc_smir/src/rustc_smir/mod.rs +++ b/compiler/rustc_smir/src/rustc_smir/mod.rs @@ -37,9 +37,14 @@ impl<'tcx> Context for Tables<'tcx> { }) } + fn name_of_def_id(&self, def_id: stable_mir::DefId) -> String { + self.tcx.def_path_str(self[def_id]) + } + fn all_local_items(&mut self) -> stable_mir::CrateItems { self.tcx.mir_keys(()).iter().map(|item| self.crate_item(item.to_def_id())).collect() } + fn entry_fn(&mut self) -> Option<stable_mir::CrateItem> { Some(self.crate_item(self.tcx.entry_fn(())?.0)) } diff --git a/compiler/rustc_smir/src/stable_mir/mod.rs b/compiler/rustc_smir/src/stable_mir/mod.rs index dad7c75c340..bfc2c15a42e 100644 --- a/compiler/rustc_smir/src/stable_mir/mod.rs +++ b/compiler/rustc_smir/src/stable_mir/mod.rs @@ -12,6 +12,8 @@ //! If you need an internal construct, consider using `rustc_internal` or `rustc_smir`. use std::cell::Cell; +use std::fmt; +use std::fmt::Debug; use self::ty::{ GenericPredicates, Generics, ImplDef, ImplTrait, Span, TraitDecl, TraitDef, Ty, TyKind, @@ -29,9 +31,18 @@ pub type Symbol = String; pub type CrateNum = usize; /// A unique identification number for each item accessible for the current compilation unit. -#[derive(Clone, Copy, PartialEq, Eq, Debug)] +#[derive(Clone, Copy, PartialEq, Eq)] pub struct DefId(pub(crate) usize); +impl Debug for DefId { + fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result { + f.debug_struct("DefId:") + .field("id", &self.0) + .field("name", &with(|cx| cx.name_of_def_id(*self))) + .finish() + } +} + /// A unique identification number for each provenance #[derive(Clone, Copy, PartialEq, Eq, Debug)] pub struct AllocId(pub(crate) usize); @@ -127,6 +138,9 @@ pub trait Context { /// Find a crate with the given name. fn find_crate(&self, name: &str) -> Option<Crate>; + /// Prints the name of given `DefId` + fn name_of_def_id(&self, def_id: DefId) -> String; + /// Obtain the representation of a type. fn ty_kind(&mut self, ty: Ty) -> TyKind; |
