@@ -140,7 +140,7 @@ pub use {
140140 display:: { ClosureStyle , HirDisplay , HirDisplayError , HirWrite } ,
141141 layout:: LayoutError ,
142142 mir:: { MirEvalError , MirLowerError } ,
143- PointerCast , Safety ,
143+ FnAbi , PointerCast , Safety ,
144144 } ,
145145 // FIXME: Properly encapsulate mir
146146 hir_ty:: { mir, Interner as ChalkTyInterner } ,
@@ -2227,7 +2227,7 @@ impl Param {
22272227 let InFile { file_id, value } = Function { id : func } . source ( db) ?;
22282228 let params = value. param_list ( ) ?;
22292229 if let Some ( self_param) = params. self_param ( ) {
2230- if let Some ( idx) = self . idx . checked_sub ( 1 as usize ) {
2230+ if let Some ( idx) = self . idx . checked_sub ( 1 ) {
22312231 params. params ( ) . nth ( idx) . map ( Either :: Right )
22322232 } else {
22332233 Some ( Either :: Left ( self_param) )
@@ -4321,23 +4321,26 @@ impl Type {
43214321 TyKind :: Function ( _) => Callee :: FnPtr ,
43224322 TyKind :: FnDef ( ..) => Callee :: Def ( self . ty . callable_def ( db) ?) ,
43234323 kind => {
4324- // This branch shouldn't be necessary?
4325- if let TyKind :: Ref ( _, _, ty) = kind {
4326- if let TyKind :: Closure ( closure, subst) = ty. kind ( Interner ) {
4327- let sig = ty. callable_sig ( db) ?;
4328- return Some ( Callable {
4329- ty : self . clone ( ) ,
4330- sig,
4331- callee : Callee :: Closure ( * closure, subst. clone ( ) ) ,
4332- is_bound_method : false ,
4333- } ) ;
4334- }
4324+ // This will happen when it implements fn or fn mut, since we add an autoborrow adjustment
4325+ let ( ty, kind) = if let TyKind :: Ref ( _, _, ty) = kind {
4326+ ( ty, ty. kind ( Interner ) )
4327+ } else {
4328+ ( & self . ty , kind)
4329+ } ;
4330+ if let TyKind :: Closure ( closure, subst) = kind {
4331+ let sig = ty. callable_sig ( db) ?;
4332+ return Some ( Callable {
4333+ ty : self . clone ( ) ,
4334+ sig,
4335+ callee : Callee :: Closure ( * closure, subst. clone ( ) ) ,
4336+ is_bound_method : false ,
4337+ } ) ;
43354338 }
4336- let sig = hir_ty:: callable_sig_from_fnonce ( & self . ty , self . env . clone ( ) , db) ?;
4339+ let ( fn_trait , sig) = hir_ty:: callable_sig_from_fn_trait ( ty, self . env . clone ( ) , db) ?;
43374340 return Some ( Callable {
43384341 ty : self . clone ( ) ,
43394342 sig,
4340- callee : Callee :: Other ,
4343+ callee : Callee :: FnImpl ( fn_trait ) ,
43414344 is_bound_method : false ,
43424345 } ) ;
43434346 }
@@ -4968,7 +4971,7 @@ enum Callee {
49684971 Def ( CallableDefId ) ,
49694972 Closure ( ClosureId , Substitution ) ,
49704973 FnPtr ,
4971- Other ,
4974+ FnImpl ( FnTrait ) ,
49724975}
49734976
49744977pub enum CallableKind {
@@ -4977,8 +4980,7 @@ pub enum CallableKind {
49774980 TupleEnumVariant ( Variant ) ,
49784981 Closure ( Closure ) ,
49794982 FnPtr ,
4980- /// Some other type that implements `FnOnce`.
4981- Other ,
4983+ FnImpl ( FnTrait ) ,
49824984}
49834985
49844986impl Callable {
@@ -4993,7 +4995,7 @@ impl Callable {
49934995 CallableKind :: Closure ( Closure { id, subst : subst. clone ( ) } )
49944996 }
49954997 Callee :: FnPtr => CallableKind :: FnPtr ,
4996- Callee :: Other => CallableKind :: Other ,
4998+ Callee :: FnImpl ( fn_ ) => CallableKind :: FnImpl ( fn_ ) ,
49974999 }
49985000 }
49995001 pub fn receiver_param ( & self , db : & dyn HirDatabase ) -> Option < ( SelfParam , Type ) > {
@@ -5023,6 +5025,10 @@ impl Callable {
50235025 pub fn sig ( & self ) -> & CallableSig {
50245026 & self . sig
50255027 }
5028+
5029+ pub fn ty ( & self ) -> & Type {
5030+ & self . ty
5031+ }
50265032}
50275033
50285034#[ derive( Clone , Debug , Eq , PartialEq ) ]
0 commit comments