File tree Expand file tree Collapse file tree 2 files changed +14
-0
lines changed
compiler/rustc_public/src Expand file tree Collapse file tree 2 files changed +14
-0
lines changed Original file line number Diff line number Diff line change @@ -249,6 +249,14 @@ impl<'tcx> CompilerInterface<'tcx> {
249249 cx. def_name ( did, trimmed)
250250 }
251251
252+ /// Returns the parent of the given `DefId`.
253+ pub ( crate ) fn def_parent ( & self , def_id : DefId ) -> Option < DefId > {
254+ let mut tables = self . tables . borrow_mut ( ) ;
255+ let cx = & * self . cx . borrow ( ) ;
256+ let did = tables[ def_id] ;
257+ cx. def_parent ( did) . map ( |did| tables. create_def_id ( did) )
258+ }
259+
252260 /// Return registered tool attributes with the given attribute name.
253261 ///
254262 /// FIXME(jdonszelmann): may panic on non-tool attributes. After more attribute work, non-tool
Original file line number Diff line number Diff line change @@ -29,6 +29,12 @@ impl DefId {
2929 pub fn trimmed_name ( & self ) -> Symbol {
3030 with ( |cx| cx. def_name ( * self , true ) )
3131 }
32+
33+ /// Return the parent of this definition, or `None` if this is the root of a
34+ /// crate.
35+ pub fn parent ( & self ) -> Option < DefId > {
36+ with ( |cx| cx. def_parent ( * self ) )
37+ }
3238}
3339
3440/// A trait for retrieving information about a particular definition.
You can’t perform that action at this time.
0 commit comments