@@ -14,7 +14,7 @@ use ra_db::{salsa::InternKey, CrateId};
1414use super :: { builtin, AssocTyValue , ChalkContext , Impl } ;
1515use crate :: {
1616 db:: HirDatabase , display:: HirDisplay , method_resolution:: TyFingerprint , utils:: generics,
17- DebruijnIndex , GenericPredicate , Substs , Ty , TypeCtor ,
17+ CallableDef , DebruijnIndex , GenericPredicate , Substs , Ty , TypeCtor ,
1818} ;
1919use chalk_rust_ir:: WellKnownTrait ;
2020use mapping:: { convert_where_clauses, generic_predicate_to_inline_bound, make_binders} ;
@@ -54,10 +54,9 @@ impl<'a> chalk_solve::RustIrDatabase<Interner> for ChalkContext<'a> {
5454
5555 fn fn_def_datum (
5656 & self ,
57- _fn_def_id : chalk_ir:: FnDefId < Interner > ,
57+ fn_def_id : chalk_ir:: FnDefId < Interner > ,
5858 ) -> Arc < chalk_rust_ir:: FnDefDatum < Interner > > {
59- // We don't yet provide any FnDefs to Chalk
60- unimplemented ! ( )
59+ self . db . fn_def_datum ( self . krate , fn_def_id)
6160 }
6261
6362 fn impls_for_trait (
@@ -405,6 +404,26 @@ fn type_alias_associated_ty_value(
405404 Arc :: new ( value)
406405}
407406
407+ pub ( crate ) fn fn_def_datum_query (
408+ db : & dyn HirDatabase ,
409+ _krate : CrateId ,
410+ fn_def_id : FnDefId ,
411+ ) -> Arc < FnDefDatum > {
412+ let callable_def: CallableDef = from_chalk ( db, fn_def_id) ;
413+ let generic_params = generics ( db. upcast ( ) , callable_def. into ( ) ) ;
414+ let sig = db. callable_item_signature ( callable_def) ;
415+ let bound_vars = Substs :: bound_vars ( & generic_params, DebruijnIndex :: INNERMOST ) ;
416+ let where_clauses = convert_where_clauses ( db, callable_def. into ( ) , & bound_vars) ;
417+ let bound = chalk_rust_ir:: FnDefDatumBound {
418+ // Note: Chalk doesn't actually use this information yet as far as I am aware, but we provide it anyway
419+ argument_types : sig. value . params ( ) . iter ( ) . map ( |ty| ty. clone ( ) . to_chalk ( db) ) . collect ( ) ,
420+ return_type : sig. value . ret ( ) . clone ( ) . to_chalk ( db) ,
421+ where_clauses,
422+ } ;
423+ let datum = FnDefDatum { id : fn_def_id, binders : make_binders ( bound, sig. num_binders ) } ;
424+ Arc :: new ( datum)
425+ }
426+
408427impl From < AdtId > for crate :: TypeCtorId {
409428 fn from ( struct_id : AdtId ) -> Self {
410429 struct_id. 0
@@ -417,6 +436,18 @@ impl From<crate::TypeCtorId> for AdtId {
417436 }
418437}
419438
439+ impl From < FnDefId > for crate :: CallableDefId {
440+ fn from ( fn_def_id : FnDefId ) -> Self {
441+ InternKey :: from_intern_id ( fn_def_id. 0 )
442+ }
443+ }
444+
445+ impl From < crate :: CallableDefId > for FnDefId {
446+ fn from ( callable_def_id : crate :: CallableDefId ) -> Self {
447+ chalk_ir:: FnDefId ( callable_def_id. as_intern_id ( ) )
448+ }
449+ }
450+
420451impl From < ImplId > for crate :: traits:: GlobalImplId {
421452 fn from ( impl_id : ImplId ) -> Self {
422453 InternKey :: from_intern_id ( impl_id. 0 )
0 commit comments