diff --git a/compiler/rustc_public/src/compiler_interface.rs b/compiler/rustc_public/src/compiler_interface.rs index 82ee546c5991..b0ea1e0f5b84 100644 --- a/compiler/rustc_public/src/compiler_interface.rs +++ b/compiler/rustc_public/src/compiler_interface.rs @@ -562,12 +562,12 @@ pub(crate) fn mir_const_pretty(&self, cnst: &MirConst) -> String { 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 02297c531762..e534004af4d3 100644 --- a/compiler/rustc_public/src/crate_def.rs +++ b/compiler/rustc_public/src/crate_def.rs @@ -34,6 +34,10 @@ pub fn trimmed_name(&self) -> Symbol { 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 @@ fn krate(&self) -> Crate { /// 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 5da79196dd4e..e38265e5f0f5 100644 --- a/compiler/rustc_public/src/lib.rs +++ b/compiler/rustc_public/src/lib.rs @@ -155,7 +155,7 @@ pub fn has_body(&self) -> bool { } 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 add52fc18caa..4d550487525f 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 @@ fn stable(&self, _: &mut Tables<'_, BridgeTys>, _: &CompilerCtxt<'_, BridgeTys>) } } +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 56aa22378072..4418d68c5c3a 100644 --- a/compiler/rustc_public_bridge/src/context/impls.rs +++ b/compiler/rustc_public_bridge/src/context/impls.rs @@ -554,8 +554,8 @@ pub fn def_ty_with_args(&self, item: DefId, args_ref: GenericArgsRef<'tcx>) -> T ) } - /// `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) }