@@ -2199,7 +2199,7 @@ impl Param {
21992199 pub fn as_local ( & self , db : & dyn HirDatabase ) -> Option < Local > {
22002200 let parent = match self . func {
22012201 Callee :: Def ( CallableDefId :: FunctionId ( it) ) => DefWithBodyId :: FunctionId ( it) ,
2202- Callee :: Closure ( closure) => db. lookup_intern_closure ( closure. into ( ) ) . 0 ,
2202+ Callee :: Closure ( closure, _ ) => db. lookup_intern_closure ( closure. into ( ) ) . 0 ,
22032203 _ => return None ,
22042204 } ;
22052205 let body = db. body ( parent) ;
@@ -2237,7 +2237,7 @@ impl Param {
22372237 }
22382238 . map ( |value| InFile { file_id, value } )
22392239 }
2240- Callee :: Closure ( closure) => {
2240+ Callee :: Closure ( closure, _ ) => {
22412241 let InternedClosure ( owner, expr_id) = db. lookup_intern_closure ( closure. into ( ) ) ;
22422242 let ( _, source_map) = db. body_with_source_map ( owner) ;
22432243 let ast @ InFile { file_id, value } = source_map. expr_syntax ( expr_id) . ok ( ) ?;
@@ -4316,16 +4316,23 @@ impl Type {
43164316 }
43174317
43184318 pub fn as_callable ( & self , db : & dyn HirDatabase ) -> Option < Callable > {
4319- let mut the_ty = & self . ty ;
43204319 let callee = match self . ty . kind ( Interner ) {
4321- TyKind :: Ref ( _, _, ty) if ty. as_closure ( ) . is_some ( ) => {
4322- the_ty = ty;
4323- Callee :: Closure ( ty. as_closure ( ) . unwrap ( ) )
4324- }
4325- TyKind :: Closure ( id, _) => Callee :: Closure ( * id) ,
4320+ TyKind :: Closure ( id, subst) => Callee :: Closure ( * id, subst. clone ( ) ) ,
43264321 TyKind :: Function ( _) => Callee :: FnPtr ,
43274322 TyKind :: FnDef ( ..) => Callee :: Def ( self . ty . callable_def ( db) ?) ,
4328- _ => {
4323+ 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+ }
4335+ }
43294336 let sig = hir_ty:: callable_sig_from_fnonce ( & self . ty , self . env . clone ( ) , db) ?;
43304337 return Some ( Callable {
43314338 ty : self . clone ( ) ,
@@ -4336,7 +4343,7 @@ impl Type {
43364343 }
43374344 } ;
43384345
4339- let sig = the_ty . callable_sig ( db) ?;
4346+ let sig = self . ty . callable_sig ( db) ?;
43404347 Some ( Callable { ty : self . clone ( ) , sig, callee, is_bound_method : false } )
43414348 }
43424349
@@ -4953,13 +4960,13 @@ pub struct Callable {
49534960 sig : CallableSig ,
49544961 callee : Callee ,
49554962 /// Whether this is a method that was called with method call syntax.
4956- pub ( crate ) is_bound_method : bool ,
4963+ is_bound_method : bool ,
49574964}
49584965
4959- #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
4966+ #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
49604967enum Callee {
49614968 Def ( CallableDefId ) ,
4962- Closure ( ClosureId ) ,
4969+ Closure ( ClosureId , Substitution ) ,
49634970 FnPtr ,
49644971 Other ,
49654972}
@@ -4968,22 +4975,25 @@ pub enum CallableKind {
49684975 Function ( Function ) ,
49694976 TupleStruct ( Struct ) ,
49704977 TupleEnumVariant ( Variant ) ,
4971- Closure ,
4978+ Closure ( Closure ) ,
49724979 FnPtr ,
49734980 /// Some other type that implements `FnOnce`.
49744981 Other ,
49754982}
49764983
49774984impl Callable {
49784985 pub fn kind ( & self ) -> CallableKind {
4979- use Callee :: * ;
49804986 match self . callee {
4981- Def ( CallableDefId :: FunctionId ( it) ) => CallableKind :: Function ( it. into ( ) ) ,
4982- Def ( CallableDefId :: StructId ( it) ) => CallableKind :: TupleStruct ( it. into ( ) ) ,
4983- Def ( CallableDefId :: EnumVariantId ( it) ) => CallableKind :: TupleEnumVariant ( it. into ( ) ) ,
4984- Closure ( _) => CallableKind :: Closure ,
4985- FnPtr => CallableKind :: FnPtr ,
4986- Other => CallableKind :: Other ,
4987+ Callee :: Def ( CallableDefId :: FunctionId ( it) ) => CallableKind :: Function ( it. into ( ) ) ,
4988+ Callee :: Def ( CallableDefId :: StructId ( it) ) => CallableKind :: TupleStruct ( it. into ( ) ) ,
4989+ Callee :: Def ( CallableDefId :: EnumVariantId ( it) ) => {
4990+ CallableKind :: TupleEnumVariant ( it. into ( ) )
4991+ }
4992+ Callee :: Closure ( id, ref subst) => {
4993+ CallableKind :: Closure ( Closure { id, subst : subst. clone ( ) } )
4994+ }
4995+ Callee :: FnPtr => CallableKind :: FnPtr ,
4996+ Callee :: Other => CallableKind :: Other ,
49874997 }
49884998 }
49894999 pub fn receiver_param ( & self , db : & dyn HirDatabase ) -> Option < ( SelfParam , Type ) > {
@@ -5004,7 +5014,7 @@ impl Callable {
50045014 . enumerate ( )
50055015 . skip ( if self . is_bound_method { 1 } else { 0 } )
50065016 . map ( |( idx, ty) | ( idx, self . ty . derived ( ty. clone ( ) ) ) )
5007- . map ( |( idx, ty) | Param { func : self . callee , idx, ty } )
5017+ . map ( |( idx, ty) | Param { func : self . callee . clone ( ) , idx, ty } )
50085018 . collect ( )
50095019 }
50105020 pub fn return_type ( & self ) -> Type {
0 commit comments