@@ -10,9 +10,10 @@ use chalk_solve::rust_ir::{self, OpaqueTyDatumBound, WellKnownTrait};
10
10
11
11
use base_db:: CrateId ;
12
12
use hir_def:: {
13
+ data:: adt:: StructFlags ,
13
14
hir:: Movability ,
14
15
lang_item:: { LangItem , LangItemTarget } ,
15
- AssocItemId , BlockId , GenericDefId , HasModule , ItemContainerId , Lookup , TypeAliasId ,
16
+ AssocItemId , BlockId , GenericDefId , HasModule , ItemContainerId , Lookup , TypeAliasId , VariantId ,
16
17
} ;
17
18
use hir_expand:: name:: name;
18
19
@@ -159,6 +160,7 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
159
160
debug ! ( "impls_for_trait returned {} impls" , result. len( ) ) ;
160
161
result
161
162
}
163
+
162
164
fn impl_provided_for ( & self , auto_trait_id : TraitId , kind : & chalk_ir:: TyKind < Interner > ) -> bool {
163
165
debug ! ( "impl_provided_for {:?}, {:?}" , auto_trait_id, kind) ;
164
166
@@ -183,22 +185,22 @@ impl chalk_solve::RustIrDatabase<Interner> for ChalkContext<'_> {
183
185
( TyKind :: Adt ( id_a, _) , TyKind :: Adt ( id_b, _) ) => id_a == id_b,
184
186
( TyKind :: AssociatedType ( id_a, _) , TyKind :: AssociatedType ( id_b, _) ) => id_a == id_b,
185
187
( TyKind :: Scalar ( scalar_a) , TyKind :: Scalar ( scalar_b) ) => scalar_a == scalar_b,
186
- ( TyKind :: Str , TyKind :: Str ) => true ,
188
+ ( TyKind :: Error , TyKind :: Error )
189
+ | ( TyKind :: Str , TyKind :: Str )
190
+ | ( TyKind :: Slice ( _) , TyKind :: Slice ( _) )
191
+ | ( TyKind :: Never , TyKind :: Never )
192
+ | ( TyKind :: Array ( _, _) , TyKind :: Array ( _, _) ) => true ,
187
193
( TyKind :: Tuple ( arity_a, _) , TyKind :: Tuple ( arity_b, _) ) => arity_a == arity_b,
188
194
( TyKind :: OpaqueType ( id_a, _) , TyKind :: OpaqueType ( id_b, _) ) => id_a == id_b,
189
- ( TyKind :: Slice ( _) , TyKind :: Slice ( _) ) => true ,
190
195
( TyKind :: FnDef ( id_a, _) , TyKind :: FnDef ( id_b, _) ) => id_a == id_b,
191
- ( TyKind :: Ref ( id_a, _, _) , TyKind :: Ref ( id_b, _, _) ) => id_a == id_b,
192
- ( TyKind :: Raw ( id_a, _) , TyKind :: Raw ( id_b, _) ) => id_a == id_b,
193
- ( TyKind :: Never , TyKind :: Never ) => true ,
194
- ( TyKind :: Array ( _, _) , TyKind :: Array ( _, _) ) => true ,
196
+ ( TyKind :: Ref ( id_a, _, _) , TyKind :: Ref ( id_b, _, _) )
197
+ | ( TyKind :: Raw ( id_a, _) , TyKind :: Raw ( id_b, _) ) => id_a == id_b,
195
198
( TyKind :: Closure ( id_a, _) , TyKind :: Closure ( id_b, _) ) => id_a == id_b,
196
- ( TyKind :: Coroutine ( id_a, _) , TyKind :: Coroutine ( id_b, _) ) => id_a == id_b ,
197
- ( TyKind :: CoroutineWitness ( id_a, _) , TyKind :: CoroutineWitness ( id_b, _) ) => {
199
+ ( TyKind :: Coroutine ( id_a, _) , TyKind :: Coroutine ( id_b, _) )
200
+ | ( TyKind :: CoroutineWitness ( id_a, _) , TyKind :: CoroutineWitness ( id_b, _) ) => {
198
201
id_a == id_b
199
202
}
200
203
( TyKind :: Foreign ( id_a) , TyKind :: Foreign ( id_b) ) => id_a == id_b,
201
- ( TyKind :: Error , TyKind :: Error ) => true ,
202
204
( _, _) => false ,
203
205
}
204
206
} ;
@@ -653,7 +655,7 @@ pub(crate) fn trait_datum_query(
653
655
coinductive : false , // only relevant for Chalk testing
654
656
// FIXME: set these flags correctly
655
657
marker : false ,
656
- fundamental : false ,
658
+ fundamental : trait_data . fundamental ,
657
659
} ;
658
660
let where_clauses = convert_where_clauses ( db, trait_. into ( ) , & bound_vars) ;
659
661
let associated_ty_ids = trait_data. associated_types ( ) . map ( to_assoc_type_id) . collect ( ) ;
@@ -715,33 +717,44 @@ fn lang_item_from_well_known_trait(trait_: WellKnownTrait) -> LangItem {
715
717
pub ( crate ) fn adt_datum_query (
716
718
db : & dyn HirDatabase ,
717
719
krate : CrateId ,
718
- adt_id : AdtId ,
720
+ chalk_ir :: AdtId ( adt_id) : AdtId ,
719
721
) -> Arc < AdtDatum > {
720
722
debug ! ( "adt_datum {:?}" , adt_id) ;
721
- let chalk_ir:: AdtId ( adt_id) = adt_id;
722
723
let generic_params = generics ( db. upcast ( ) , adt_id. into ( ) ) ;
723
724
let bound_vars_subst = generic_params. bound_vars_subst ( db, DebruijnIndex :: INNERMOST ) ;
724
725
let where_clauses = convert_where_clauses ( db, adt_id. into ( ) , & bound_vars_subst) ;
725
726
726
- let phantom_data_id = db
727
- . lang_item ( krate, LangItem :: PhantomData )
728
- . and_then ( |item| item. as_struct ( ) )
729
- . map ( |item| item. into ( ) ) ;
727
+ let ( fundamental, phantom_data) = match adt_id {
728
+ hir_def:: AdtId :: StructId ( s) => {
729
+ let flags = db. struct_data ( s) . flags ;
730
+ (
731
+ flags. contains ( StructFlags :: IS_FUNDAMENTAL ) ,
732
+ flags. contains ( StructFlags :: IS_PHANTOM_DATA ) ,
733
+ )
734
+ }
735
+ // FIXME set fundamental flags correctly
736
+ hir_def:: AdtId :: UnionId ( _) => ( false , false ) ,
737
+ hir_def:: AdtId :: EnumId ( _) => ( false , false ) ,
738
+ } ;
730
739
let flags = rust_ir:: AdtFlags {
731
740
upstream : adt_id. module ( db. upcast ( ) ) . krate ( ) != krate,
732
- // FIXME set fundamental flags correctly
733
- fundamental : false ,
734
- phantom_data : phantom_data_id == Some ( adt_id) ,
741
+ fundamental,
742
+ phantom_data,
735
743
} ;
736
744
737
- let variant_id_to_fields = |id| {
738
- let field_types = db. field_types ( id) ;
739
- let fields = id
740
- . variant_data ( db. upcast ( ) )
741
- . fields ( )
742
- . iter ( )
743
- . map ( |( idx, _) | field_types[ idx] . clone ( ) . substitute ( Interner , & bound_vars_subst) )
744
- . collect ( ) ;
745
+ let variant_id_to_fields = |id : VariantId | {
746
+ let variant_data = & id. variant_data ( db. upcast ( ) ) ;
747
+ let fields = if variant_data. fields ( ) . is_empty ( ) {
748
+ vec ! [ ]
749
+ } else {
750
+ let field_types = db. field_types ( id) ;
751
+ variant_data
752
+ . fields ( )
753
+ . iter ( )
754
+ . map ( |( idx, _) | field_types[ idx] . clone ( ) . substitute ( Interner , & bound_vars_subst) )
755
+ . filter ( |it| !it. is_unknown ( ) )
756
+ . collect ( )
757
+ } ;
745
758
rust_ir:: AdtVariantDatum { fields }
746
759
} ;
747
760
0 commit comments