@@ -20,7 +20,7 @@ use rustc_index::IndexVec;
2020use rustc_metadata:: rendered_const;
2121use rustc_middle:: span_bug;
2222use rustc_middle:: ty:: fast_reject:: SimplifiedType ;
23- use rustc_middle:: ty:: { self , TyCtxt , Visibility } ;
23+ use rustc_middle:: ty:: { self , Ty , TyCtxt , Visibility } ;
2424use rustc_resolve:: rustdoc:: {
2525 DocFragment , add_doc_fragment, attrs_to_doc_fragments, inner_docs, span_of_fragments,
2626} ;
@@ -1758,6 +1758,40 @@ impl PrimitiveType {
17581758 }
17591759 }
17601760
1761+ pub ( crate ) fn from_ty ( ty : Ty < ' _ > ) -> Option < Self > {
1762+ match ty. kind ( ) {
1763+ ty:: Array ( ..) => Some ( Self :: Array ) ,
1764+ ty:: Bool => Some ( Self :: Bool ) ,
1765+ ty:: Char => Some ( Self :: Char ) ,
1766+ ty:: FnDef ( ..) | ty:: FnPtr ( ..) => Some ( Self :: Fn ) ,
1767+ ty:: Int ( int) => Some ( Self :: from ( * int) ) ,
1768+ ty:: Uint ( uint) => Some ( Self :: from ( * uint) ) ,
1769+ ty:: Float ( float) => Some ( Self :: from ( * float) ) ,
1770+ ty:: Never => Some ( Self :: Never ) ,
1771+ ty:: Pat ( ..) => Some ( Self :: Pat ) ,
1772+ ty:: RawPtr ( ..) => Some ( Self :: RawPointer ) ,
1773+ ty:: Ref ( ..) => Some ( Self :: Reference ) ,
1774+ ty:: Slice ( ..) => Some ( Self :: Slice ) ,
1775+ ty:: Str => Some ( Self :: Str ) ,
1776+ ty:: Tuple ( elems) if elems. is_empty ( ) => Some ( Self :: Unit ) ,
1777+ ty:: Tuple ( _) => Some ( Self :: Tuple ) ,
1778+ ty:: Adt ( ..)
1779+ | ty:: Alias ( ..)
1780+ | ty:: Bound ( ..)
1781+ | ty:: Closure ( ..)
1782+ | ty:: Coroutine ( ..)
1783+ | ty:: CoroutineClosure ( ..)
1784+ | ty:: CoroutineWitness ( ..)
1785+ | ty:: Dynamic ( ..)
1786+ | ty:: Error ( ..)
1787+ | ty:: Foreign ( ..)
1788+ | ty:: Infer ( ..)
1789+ | ty:: Param ( ..)
1790+ | ty:: Placeholder ( ..)
1791+ | ty:: UnsafeBinder ( ..) => None ,
1792+ }
1793+ }
1794+
17611795 pub ( crate ) fn simplified_types ( ) -> & ' static SimplifiedTypes {
17621796 use PrimitiveType :: * ;
17631797 use ty:: { FloatTy , IntTy , UintTy } ;
0 commit comments