@@ -4,15 +4,15 @@ use std::sync::Arc;
4
4
use log:: debug;
5
5
6
6
use chalk_ir:: {
7
- cast:: Cast , family:: ChalkIr , Identifier , ImplId , Parameter , PlaceholderIndex , TypeId ,
8
- TypeKindId , TypeName , UniverseIndex ,
7
+ cast:: Cast , family:: ChalkIr , Identifier , Parameter , PlaceholderIndex , TypeId , TypeKindId ,
8
+ TypeName , UniverseIndex ,
9
9
} ;
10
10
use chalk_rust_ir:: { AssociatedTyDatum , AssociatedTyValue , ImplDatum , StructDatum , TraitDatum } ;
11
11
use ra_db:: CrateId ;
12
12
13
13
use hir_def:: {
14
- lang_item:: LangItemTarget , resolver:: HasResolver , AstItemDef , ContainerId , GenericDefId ,
15
- Lookup , TraitId , TypeAliasId ,
14
+ lang_item:: LangItemTarget , resolver:: HasResolver , AssocItemId , AstItemDef , ContainerId ,
15
+ GenericDefId , ImplId , Lookup , TraitId , TypeAliasId ,
16
16
} ;
17
17
use hir_expand:: name;
18
18
@@ -23,7 +23,6 @@ use crate::{
23
23
db:: HirDatabase ,
24
24
ty:: display:: HirDisplay ,
25
25
ty:: { ApplicationTy , GenericPredicate , ProjectionTy , Substs , TraitRef , Ty , TypeCtor , TypeWalk } ,
26
- ImplBlock ,
27
26
} ;
28
27
29
28
/// This represents a trait whose name we could not resolve.
@@ -435,14 +434,14 @@ where
435
434
fn struct_datum ( & self , struct_id : chalk_ir:: StructId ) -> Arc < StructDatum < ChalkIr > > {
436
435
self . db . struct_datum ( self . krate , struct_id)
437
436
}
438
- fn impl_datum ( & self , impl_id : ImplId ) -> Arc < ImplDatum < ChalkIr > > {
437
+ fn impl_datum ( & self , impl_id : chalk_ir :: ImplId ) -> Arc < ImplDatum < ChalkIr > > {
439
438
self . db . impl_datum ( self . krate , impl_id)
440
439
}
441
440
fn impls_for_trait (
442
441
& self ,
443
442
trait_id : chalk_ir:: TraitId ,
444
443
parameters : & [ Parameter < ChalkIr > ] ,
445
- ) -> Vec < ImplId > {
444
+ ) -> Vec < chalk_ir :: ImplId > {
446
445
debug ! ( "impls_for_trait {:?}" , trait_id) ;
447
446
if trait_id == UNKNOWN_TRAIT {
448
447
return Vec :: new ( ) ;
@@ -614,7 +613,7 @@ pub(crate) fn struct_datum_query(
614
613
pub ( crate ) fn impl_datum_query (
615
614
db : & impl HirDatabase ,
616
615
krate : CrateId ,
617
- impl_id : ImplId ,
616
+ impl_id : chalk_ir :: ImplId ,
618
617
) -> Arc < ImplDatum < ChalkIr > > {
619
618
let _p = ra_prof:: profile ( "impl_datum" ) ;
620
619
debug ! ( "impl_datum {:?}" , impl_id) ;
@@ -629,23 +628,31 @@ pub(crate) fn impl_datum_query(
629
628
fn impl_block_datum (
630
629
db : & impl HirDatabase ,
631
630
krate : CrateId ,
631
+ chalk_id : chalk_ir:: ImplId ,
632
632
impl_id : ImplId ,
633
- impl_block : ImplBlock ,
634
633
) -> Option < Arc < ImplDatum < ChalkIr > > > {
635
- let generic_params = db. generic_params ( impl_block. id . into ( ) ) ;
634
+ let impl_data = db. impl_data ( impl_id) ;
635
+ let resolver = impl_id. resolver ( db) ;
636
+ let target_ty = Ty :: from_hir ( db, & resolver, & impl_data. target_type ) ;
637
+
638
+ // `CoerseUnsized` has one generic parameter for the target type.
639
+ let trait_ref =
640
+ TraitRef :: from_hir ( db, & resolver, impl_data. target_trait . as_ref ( ) ?, Some ( target_ty) ) ?;
641
+
642
+ let generic_params = db. generic_params ( impl_id. into ( ) ) ;
636
643
let bound_vars = Substs :: bound_vars ( & generic_params) ;
637
- let trait_ref = impl_block . target_trait_ref ( db ) ? . subst ( & bound_vars) ;
644
+ let trait_ref = trait_ref . subst ( & bound_vars) ;
638
645
let trait_ = trait_ref. trait_ ;
639
- let impl_type = if impl_block . krate ( db) . crate_id == krate {
646
+ let impl_type = if impl_id . module ( db) . krate == krate {
640
647
chalk_rust_ir:: ImplType :: Local
641
648
} else {
642
649
chalk_rust_ir:: ImplType :: External
643
650
} ;
644
- let where_clauses = convert_where_clauses ( db, impl_block . id . into ( ) , & bound_vars) ;
645
- let negative = impl_block . is_negative ( db ) ;
651
+ let where_clauses = convert_where_clauses ( db, impl_id . into ( ) , & bound_vars) ;
652
+ let negative = impl_data . is_negative ;
646
653
debug ! (
647
654
"impl {:?}: {}{} where {:?}" ,
648
- impl_id ,
655
+ chalk_id ,
649
656
if negative { "!" } else { "" } ,
650
657
trait_ref. display( db) ,
651
658
where_clauses
@@ -660,18 +667,19 @@ fn impl_block_datum(
660
667
661
668
let impl_datum_bound = chalk_rust_ir:: ImplDatumBound { trait_ref, where_clauses } ;
662
669
let trait_data = db. trait_data ( trait_) ;
663
- let associated_ty_value_ids = impl_block
664
- . items ( db )
665
- . into_iter ( )
670
+ let associated_ty_value_ids = impl_data
671
+ . items
672
+ . iter ( )
666
673
. filter_map ( |item| match item {
667
- crate :: AssocItem :: TypeAlias ( type_alias) => Some ( type_alias) ,
674
+ AssocItemId :: TypeAliasId ( type_alias) => Some ( * type_alias) ,
668
675
_ => None ,
669
676
} )
670
- . filter ( |type_alias| {
677
+ . filter ( |& type_alias| {
671
678
// don't include associated types that don't exist in the trait
672
- trait_data. associated_type_by_name ( & type_alias. name ( db) ) . is_some ( )
679
+ let name = & db. type_alias_data ( type_alias) . name ;
680
+ trait_data. associated_type_by_name ( name) . is_some ( )
673
681
} )
674
- . map ( |type_alias| AssocTyValue :: TypeAlias ( type_alias. id ) . to_chalk ( db) )
682
+ . map ( |type_alias| AssocTyValue :: TypeAlias ( type_alias) . to_chalk ( db) )
675
683
. collect ( ) ;
676
684
debug ! ( "impl_datum: {:?}" , impl_datum_bound) ;
677
685
let impl_datum = ImplDatum {
0 commit comments