@@ -18,7 +18,9 @@ use std::sync::Arc;
1818
1919use chalk_ir:: { cast:: Cast , ConstValue , DebruijnIndex , Mutability , Safety , Scalar , TypeFlags } ;
2020use hir_def:: {
21+ adt:: { ReprData , ReprKind } ,
2122 body:: Body ,
23+ builtin_type:: BuiltinType ,
2224 data:: { ConstData , StaticData } ,
2325 expr:: { BindingAnnotation , ExprId , PatId } ,
2426 lang_item:: LangItemTarget ,
@@ -67,12 +69,16 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
6769 DefWithBodyId :: ConstId ( c) => ctx. collect_const ( & db. const_data ( c) ) ,
6870 DefWithBodyId :: FunctionId ( f) => ctx. collect_fn ( f) ,
6971 DefWithBodyId :: StaticId ( s) => ctx. collect_static ( & db. static_data ( s) ) ,
70- DefWithBodyId :: VariantId ( _v) => {
71- // db.enum_data(v.parent)
72- // FIXME: This should return the `repr(...)` type of the enum
73- ctx. return_ty = TyBuilder :: builtin ( hir_def:: builtin_type:: BuiltinType :: Uint (
74- hir_def:: builtin_type:: BuiltinUint :: U32 ,
75- ) ) ;
72+ DefWithBodyId :: VariantId ( v) => {
73+ ctx. return_ty = match db. enum_data ( v. parent ) . repr {
74+ Some ( ReprData { kind : ReprKind :: BuiltinInt { builtin, .. } , .. } ) => {
75+ TyBuilder :: builtin ( match builtin {
76+ Either :: Left ( builtin) => BuiltinType :: Int ( builtin) ,
77+ Either :: Right ( builtin) => BuiltinType :: Uint ( builtin) ,
78+ } )
79+ }
80+ _ => TyBuilder :: builtin ( BuiltinType :: Uint ( hir_def:: builtin_type:: BuiltinUint :: U32 ) ) ,
81+ } ;
7682 }
7783 }
7884
0 commit comments