@@ -18,7 +18,9 @@ use std::sync::Arc;
18
18
19
19
use chalk_ir:: { cast:: Cast , ConstValue , DebruijnIndex , Mutability , Safety , Scalar , TypeFlags } ;
20
20
use hir_def:: {
21
+ adt:: { ReprData , ReprKind } ,
21
22
body:: Body ,
23
+ builtin_type:: BuiltinType ,
22
24
data:: { ConstData , StaticData } ,
23
25
expr:: { BindingAnnotation , ExprId , PatId } ,
24
26
lang_item:: LangItemTarget ,
@@ -67,12 +69,16 @@ pub(crate) fn infer_query(db: &dyn HirDatabase, def: DefWithBodyId) -> Arc<Infer
67
69
DefWithBodyId :: ConstId ( c) => ctx. collect_const ( & db. const_data ( c) ) ,
68
70
DefWithBodyId :: FunctionId ( f) => ctx. collect_fn ( f) ,
69
71
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
+ } ;
76
82
}
77
83
}
78
84
0 commit comments