@@ -771,12 +771,17 @@ impl TypedAstContext {
771771 ty. map ( |ty| ( expr_id, ty) )
772772 }
773773
774- pub fn type_for_kind ( & self , kind : & CTypeKind ) -> Option < CTypeId > {
774+ pub fn try_type_for_kind ( & self , kind : & CTypeKind ) -> Option < CTypeId > {
775775 self . c_types
776776 . iter ( )
777777 . find_map ( |( id, k) | if kind == & k. kind { Some ( * id) } else { None } )
778778 }
779779
780+ pub fn type_for_kind ( & self , kind : & CTypeKind ) -> CTypeId {
781+ self . try_type_for_kind ( kind)
782+ . expect ( "could not find type for CTypeKind::{kind:?}" )
783+ }
784+
780785 pub fn resolve_type_id ( & self , typ : CTypeId ) -> CTypeId {
781786 use CTypeKind :: * ;
782787 let ty = match self . index ( typ) . kind {
@@ -875,9 +880,7 @@ impl TypedAstContext {
875880 pub fn fn_declref_ty_with_declared_args ( & self , func_expr : CExprId ) -> Option < CQualTypeId > {
876881 if let Some ( func_decl @ CDeclKind :: Function { .. } ) = self . fn_declref_decl ( func_expr) {
877882 let kind_with_declared_args = self . fn_decl_ty_with_declared_args ( func_decl) ;
878- let specific_typ = self
879- . type_for_kind ( & kind_with_declared_args)
880- . unwrap_or_else ( || panic ! ( "no type for kind {kind_with_declared_args:?}" ) ) ;
883+ let specific_typ = self . type_for_kind ( & kind_with_declared_args) ;
881884 return Some ( CQualTypeId :: new ( specific_typ) ) ;
882885 }
883886 None
@@ -1344,10 +1347,7 @@ impl TypedAstContext {
13441347 CUnTypeOp :: AlignOf => CTypeKind :: Size ,
13451348 CUnTypeOp :: PreferredAlignOf => CTypeKind :: Size ,
13461349 } ;
1347- let ty = self
1348- . ast_context
1349- . type_for_kind ( & kind)
1350- . expect ( "CTypeKind::Size should be size_t" ) ;
1350+ let ty = self . ast_context . type_for_kind ( & kind) ;
13511351 Some ( CQualTypeId :: new ( ty) )
13521352 }
13531353 _ => return ,
@@ -2062,7 +2062,7 @@ impl CUnOp {
20622062 }
20632063 Not => {
20642064 return ast_context
2065- . type_for_kind ( & CTypeKind :: Int )
2065+ . try_type_for_kind ( & CTypeKind :: Int )
20662066 . map ( CQualTypeId :: new)
20672067 }
20682068 Real | Imag => {
0 commit comments