@@ -2199,7 +2199,7 @@ impl Param {
2199
2199
pub fn as_local ( & self , db : & dyn HirDatabase ) -> Option < Local > {
2200
2200
let parent = match self . func {
2201
2201
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 ,
2203
2203
_ => return None ,
2204
2204
} ;
2205
2205
let body = db. body ( parent) ;
@@ -2237,7 +2237,7 @@ impl Param {
2237
2237
}
2238
2238
. map ( |value| InFile { file_id, value } )
2239
2239
}
2240
- Callee :: Closure ( closure) => {
2240
+ Callee :: Closure ( closure, _ ) => {
2241
2241
let InternedClosure ( owner, expr_id) = db. lookup_intern_closure ( closure. into ( ) ) ;
2242
2242
let ( _, source_map) = db. body_with_source_map ( owner) ;
2243
2243
let ast @ InFile { file_id, value } = source_map. expr_syntax ( expr_id) . ok ( ) ?;
@@ -4316,16 +4316,23 @@ impl Type {
4316
4316
}
4317
4317
4318
4318
pub fn as_callable ( & self , db : & dyn HirDatabase ) -> Option < Callable > {
4319
- let mut the_ty = & self . ty ;
4320
4319
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 ( ) ) ,
4326
4321
TyKind :: Function ( _) => Callee :: FnPtr ,
4327
4322
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
+ }
4329
4336
let sig = hir_ty:: callable_sig_from_fnonce ( & self . ty , self . env . clone ( ) , db) ?;
4330
4337
return Some ( Callable {
4331
4338
ty : self . clone ( ) ,
@@ -4336,7 +4343,7 @@ impl Type {
4336
4343
}
4337
4344
} ;
4338
4345
4339
- let sig = the_ty . callable_sig ( db) ?;
4346
+ let sig = self . ty . callable_sig ( db) ?;
4340
4347
Some ( Callable { ty : self . clone ( ) , sig, callee, is_bound_method : false } )
4341
4348
}
4342
4349
@@ -4953,13 +4960,13 @@ pub struct Callable {
4953
4960
sig : CallableSig ,
4954
4961
callee : Callee ,
4955
4962
/// Whether this is a method that was called with method call syntax.
4956
- pub ( crate ) is_bound_method : bool ,
4963
+ is_bound_method : bool ,
4957
4964
}
4958
4965
4959
- #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
4966
+ #[ derive( Clone , PartialEq , Eq , Hash , Debug ) ]
4960
4967
enum Callee {
4961
4968
Def ( CallableDefId ) ,
4962
- Closure ( ClosureId ) ,
4969
+ Closure ( ClosureId , Substitution ) ,
4963
4970
FnPtr ,
4964
4971
Other ,
4965
4972
}
@@ -4968,22 +4975,25 @@ pub enum CallableKind {
4968
4975
Function ( Function ) ,
4969
4976
TupleStruct ( Struct ) ,
4970
4977
TupleEnumVariant ( Variant ) ,
4971
- Closure ,
4978
+ Closure ( Closure ) ,
4972
4979
FnPtr ,
4973
4980
/// Some other type that implements `FnOnce`.
4974
4981
Other ,
4975
4982
}
4976
4983
4977
4984
impl Callable {
4978
4985
pub fn kind ( & self ) -> CallableKind {
4979
- use Callee :: * ;
4980
4986
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 ,
4987
4997
}
4988
4998
}
4989
4999
pub fn receiver_param ( & self , db : & dyn HirDatabase ) -> Option < ( SelfParam , Type ) > {
@@ -5004,7 +5014,7 @@ impl Callable {
5004
5014
. enumerate ( )
5005
5015
. skip ( if self . is_bound_method { 1 } else { 0 } )
5006
5016
. 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 } )
5008
5018
. collect ( )
5009
5019
}
5010
5020
pub fn return_type ( & self ) -> Type {
0 commit comments