@@ -1913,12 +1913,6 @@ impl<'tcx> TyCtxt<'tcx> {
19131913 }
19141914 }
19151915
1916- /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
1917- /// If it implements no trait, returns `None`.
1918- pub fn trait_id_of_impl ( self , def_id : DefId ) -> Option < DefId > {
1919- self . impl_trait_ref ( def_id) . map ( |tr| tr. skip_binder ( ) . def_id )
1920- }
1921-
19221916 /// If the given `DefId` is an associated item, returns the `DefId` and `DefKind` of the parent trait or impl.
19231917 pub fn assoc_parent ( self , def_id : DefId ) -> Option < ( DefId , DefKind ) > {
19241918 if !self . def_kind ( def_id) . is_assoc ( ) {
@@ -1983,6 +1977,18 @@ impl<'tcx> TyCtxt<'tcx> {
19831977 Some ( self . impl_trait_header ( def_id) ?. trait_ref )
19841978 }
19851979
1980+ /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
1981+ pub fn impl_trait_id ( self , def_id : DefId ) -> DefId {
1982+ self . impl_opt_trait_id ( def_id)
1983+ . unwrap_or_else ( || panic ! ( "expected impl of trait for {def_id:?}" ) )
1984+ }
1985+
1986+ /// Given the `DefId` of an impl, returns the `DefId` of the trait it implements.
1987+ /// If it implements no trait, returns `None`.
1988+ pub fn impl_opt_trait_id ( self , def_id : DefId ) -> Option < DefId > {
1989+ self . impl_trait_ref ( def_id) . map ( |tr| tr. skip_binder ( ) . def_id )
1990+ }
1991+
19861992 pub fn is_exportable ( self , def_id : DefId ) -> bool {
19871993 self . exportable_items ( def_id. krate ) . contains ( & def_id)
19881994 }
0 commit comments