diff --git a/compiler/rustc_public/src/compiler_interface.rs b/compiler/rustc_public/src/compiler_interface.rs index 82ee546c59910..b0ea1e0f5b847 100644 --- a/compiler/rustc_public/src/compiler_interface.rs +++ b/compiler/rustc_public/src/compiler_interface.rs @@ -562,12 +562,12 @@ impl<'tcx> CompilerInterface<'tcx> { cnst.internal(&mut *tables, cx.tcx).to_string() } - /// `Span` of an item. - pub(crate) fn span_of_an_item(&self, def_id: DefId) -> Span { + /// `Span` of a `DefId`. + pub(crate) fn span_of_a_def(&self, def_id: DefId) -> Span { let mut tables = self.tables.borrow_mut(); let cx = &*self.cx.borrow(); let did = tables[def_id]; - cx.span_of_an_item(did).stable(&mut *tables, cx) + cx.span_of_a_def(did).stable(&mut *tables, cx) } pub(crate) fn ty_const_pretty(&self, ct: TyConstId) -> String { diff --git a/compiler/rustc_public/src/crate_def.rs b/compiler/rustc_public/src/crate_def.rs index 02297c5317621..e534004af4d3c 100644 --- a/compiler/rustc_public/src/crate_def.rs +++ b/compiler/rustc_public/src/crate_def.rs @@ -34,6 +34,10 @@ impl DefId { pub fn parent(&self) -> Option { with(|cx| cx.def_parent(*self)) } + + pub fn span(&self) -> Span { + with(|cx| cx.span_of_a_def(*self)) + } } /// A trait for retrieving information about a particular definition. @@ -68,8 +72,7 @@ pub trait CrateDef { /// Return the span of this definition. fn span(&self) -> Span { - let def_id = self.def_id(); - with(|cx| cx.span_of_an_item(def_id)) + self.def_id().span() } /// Return registered tool attributes with the given attribute name. diff --git a/compiler/rustc_public/src/lib.rs b/compiler/rustc_public/src/lib.rs index 5da79196dd4ed..e38265e5f0f56 100644 --- a/compiler/rustc_public/src/lib.rs +++ b/compiler/rustc_public/src/lib.rs @@ -155,7 +155,7 @@ impl CrateItem { } pub fn span(&self) -> Span { - with(|cx| cx.span_of_an_item(self.0)) + self.0.span() } pub fn kind(&self) -> ItemKind { diff --git a/compiler/rustc_public/src/unstable/convert/stable/mod.rs b/compiler/rustc_public/src/unstable/convert/stable/mod.rs index add52fc18caaa..4d550487525f3 100644 --- a/compiler/rustc_public/src/unstable/convert/stable/mod.rs +++ b/compiler/rustc_public/src/unstable/convert/stable/mod.rs @@ -82,6 +82,18 @@ impl<'tcx> Stable<'tcx> for rustc_span::Symbol { } } +impl<'tcx> Stable<'tcx> for rustc_span::def_id::DefId { + type T = crate::DefId; + + fn stable<'cx>( + &self, + tables: &mut Tables<'cx, BridgeTys>, + _: &CompilerCtxt<'cx, BridgeTys>, + ) -> Self::T { + tables.create_def_id(*self) + } +} + impl<'tcx> Stable<'tcx> for rustc_span::Span { type T = crate::ty::Span; diff --git a/compiler/rustc_public_bridge/src/context/impls.rs b/compiler/rustc_public_bridge/src/context/impls.rs index 56aa22378072a..4418d68c5c3ac 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -554,8 +554,8 @@ impl<'tcx, B: Bridge> CompilerCtxt<'tcx, B> { ) } - /// `Span` of an item. - pub fn span_of_an_item(&self, def_id: DefId) -> Span { + /// `Span` of a `DefId`. + pub fn span_of_a_def(&self, def_id: DefId) -> Span { self.tcx.def_span(def_id) }