@@ -60,9 +60,37 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
60
60
// FIXME: keep track of these
61
61
Arc :: new ( rust_ir:: AdtRepr { c : false , packed : false , int : None } )
62
62
}
63
- fn discriminant_type ( & self , _ty : chalk_ir:: Ty < Interner > ) -> chalk_ir:: Ty < Interner > {
64
- // FIXME: keep track of this
65
- chalk_ir:: TyKind :: Scalar ( chalk_ir:: Scalar :: Uint ( chalk_ir:: UintTy :: U32 ) ) . intern ( Interner )
63
+ fn discriminant_type ( & self , ty : chalk_ir:: Ty < Interner > ) -> chalk_ir:: Ty < Interner > {
64
+ if let chalk_ir:: TyKind :: Adt ( id, _) = ty. kind ( Interner ) {
65
+ if let hir_def:: AdtId :: EnumId ( e) = id. 0 {
66
+ let enum_data = self . db . enum_data ( e) ;
67
+ let ty = enum_data. repr . unwrap_or_default ( ) . discr_type ( ) ;
68
+ return chalk_ir:: TyKind :: Scalar ( match ty {
69
+ hir_def:: layout:: IntegerType :: Pointer ( is_signed) => match is_signed {
70
+ true => chalk_ir:: Scalar :: Int ( chalk_ir:: IntTy :: Isize ) ,
71
+ false => chalk_ir:: Scalar :: Uint ( chalk_ir:: UintTy :: Usize ) ,
72
+ } ,
73
+ hir_def:: layout:: IntegerType :: Fixed ( size, is_signed) => match is_signed {
74
+ true => chalk_ir:: Scalar :: Int ( match size {
75
+ hir_def:: layout:: Integer :: I8 => chalk_ir:: IntTy :: I8 ,
76
+ hir_def:: layout:: Integer :: I16 => chalk_ir:: IntTy :: I16 ,
77
+ hir_def:: layout:: Integer :: I32 => chalk_ir:: IntTy :: I32 ,
78
+ hir_def:: layout:: Integer :: I64 => chalk_ir:: IntTy :: I64 ,
79
+ hir_def:: layout:: Integer :: I128 => chalk_ir:: IntTy :: I128 ,
80
+ } ) ,
81
+ false => chalk_ir:: Scalar :: Uint ( match size {
82
+ hir_def:: layout:: Integer :: I8 => chalk_ir:: UintTy :: U8 ,
83
+ hir_def:: layout:: Integer :: I16 => chalk_ir:: UintTy :: U16 ,
84
+ hir_def:: layout:: Integer :: I32 => chalk_ir:: UintTy :: U32 ,
85
+ hir_def:: layout:: Integer :: I64 => chalk_ir:: UintTy :: U64 ,
86
+ hir_def:: layout:: Integer :: I128 => chalk_ir:: UintTy :: U128 ,
87
+ } ) ,
88
+ } ,
89
+ } )
90
+ . intern ( Interner ) ;
91
+ }
92
+ }
93
+ chalk_ir:: TyKind :: Scalar ( chalk_ir:: Scalar :: Uint ( chalk_ir:: UintTy :: U8 ) ) . intern ( Interner )
66
94
}
67
95
fn impl_datum ( & self , impl_id : ImplId ) -> Arc < ImplDatum > {
68
96
self . db . impl_datum ( self . krate , impl_id)
0 commit comments