mirror of
https://github.com/rust-lang/rust.git
synced 2026-04-27 18:57:42 +03:00
Add DefId::parent() accessor in rustc_public
This commit is contained in:
@@ -249,6 +249,14 @@ pub(crate) fn def_name(&self, def_id: DefId, trimmed: bool) -> Symbol {
|
||||
cx.def_name(did, trimmed)
|
||||
}
|
||||
|
||||
/// Returns the parent of the given `DefId`.
|
||||
pub(crate) fn def_parent(&self, def_id: DefId) -> Option<DefId> {
|
||||
let mut tables = self.tables.borrow_mut();
|
||||
let cx = &*self.cx.borrow();
|
||||
let did = tables[def_id];
|
||||
cx.def_parent(did).map(|did| tables.create_def_id(did))
|
||||
}
|
||||
|
||||
/// Return registered tool attributes with the given attribute name.
|
||||
///
|
||||
/// FIXME(jdonszelmann): may panic on non-tool attributes. After more attribute work, non-tool
|
||||
|
||||
@@ -29,6 +29,12 @@ pub fn name(&self) -> Symbol {
|
||||
pub fn trimmed_name(&self) -> Symbol {
|
||||
with(|cx| cx.def_name(*self, true))
|
||||
}
|
||||
|
||||
/// Return the parent of this definition, or `None` if this is the root of a
|
||||
/// crate.
|
||||
pub fn parent(&self) -> Option<DefId> {
|
||||
with(|cx| cx.def_parent(*self))
|
||||
}
|
||||
}
|
||||
|
||||
/// A trait for retrieving information about a particular definition.
|
||||
|
||||
@@ -268,6 +268,11 @@ pub fn def_name(&self, def_id: DefId, trimmed: bool) -> String {
|
||||
}
|
||||
}
|
||||
|
||||
/// Returns the parent of the given `DefId`.
|
||||
pub fn def_parent(&self, def_id: DefId) -> Option<DefId> {
|
||||
self.tcx.opt_parent(def_id)
|
||||
}
|
||||
|
||||
/// Return registered tool attributes with the given attribute name.
|
||||
///
|
||||
/// FIXME(jdonszelmann): may panic on non-tool attributes. After more attribute work, non-tool
|
||||
|
||||
Reference in New Issue
Block a user