@@ -5,7 +5,7 @@ use std::{cmp, collections::HashMap, convert::Infallible, mem};
5
5
use chalk_ir:: {
6
6
cast:: Cast ,
7
7
fold:: { FallibleTypeFolder , TypeFoldable } ,
8
- AliasEq , AliasTy , BoundVar , ConstData , DebruijnIndex , FnSubst , Mutability , TyKind , WhereClause ,
8
+ AliasEq , AliasTy , BoundVar , DebruijnIndex , FnSubst , Mutability , TyKind , WhereClause ,
9
9
} ;
10
10
use hir_def:: {
11
11
data:: adt:: VariantData ,
@@ -26,8 +26,8 @@ use crate::{
26
26
static_lifetime, to_chalk_trait_id,
27
27
traits:: FnTrait ,
28
28
utils:: { self , generics, Generics } ,
29
- Adjust , Adjustment , Binders , BindingMode , ChalkTraitId , ClosureId , ConstValue , DynTy ,
30
- FnPointer , FnSig , Interner , Substitution , Ty , TyExt ,
29
+ Adjust , Adjustment , Binders , BindingMode , ChalkTraitId , ClosureId , DynTy , FnPointer , FnSig ,
30
+ Interner , Substitution , Ty , TyExt ,
31
31
} ;
32
32
33
33
use super :: { Expectation , InferenceContext } ;
@@ -236,6 +236,24 @@ pub(crate) struct CapturedItemWithoutTy {
236
236
237
237
impl CapturedItemWithoutTy {
238
238
fn with_ty ( self , ctx : & mut InferenceContext < ' _ > ) -> CapturedItem {
239
+ let ty = self . place . ty ( ctx) . clone ( ) ;
240
+ let ty = match & self . kind {
241
+ CaptureKind :: ByValue => ty,
242
+ CaptureKind :: ByRef ( bk) => {
243
+ let m = match bk {
244
+ BorrowKind :: Mut { .. } => Mutability :: Mut ,
245
+ _ => Mutability :: Not ,
246
+ } ;
247
+ TyKind :: Ref ( m, static_lifetime ( ) , ty) . intern ( Interner )
248
+ }
249
+ } ;
250
+ return CapturedItem {
251
+ place : self . place ,
252
+ kind : self . kind ,
253
+ span : self . span ,
254
+ ty : replace_placeholder_with_binder ( ctx. db , ctx. owner , ty) ,
255
+ } ;
256
+
239
257
fn replace_placeholder_with_binder (
240
258
db : & dyn HirDatabase ,
241
259
owner : DefWithBodyId ,
@@ -266,56 +284,28 @@ impl CapturedItemWithoutTy {
266
284
let Some ( idx) = self . generics . param_idx ( x) else {
267
285
return Err ( ( ) ) ;
268
286
} ;
269
- Ok ( ConstData {
270
- ty,
271
- value : ConstValue :: BoundVar ( BoundVar :: new ( outer_binder, idx) ) ,
272
- }
273
- . intern ( Interner ) )
287
+ Ok ( BoundVar :: new ( outer_binder, idx) . to_const ( Interner , ty) )
274
288
}
275
289
276
290
fn try_fold_free_placeholder_ty (
277
291
& mut self ,
278
292
idx : chalk_ir:: PlaceholderIndex ,
279
- _outer_binder : DebruijnIndex ,
293
+ outer_binder : DebruijnIndex ,
280
294
) -> std:: result:: Result < Ty , Self :: Error > {
281
295
let x = from_placeholder_idx ( self . db , idx) ;
282
296
let Some ( idx) = self . generics . param_idx ( x) else {
283
297
return Err ( ( ) ) ;
284
298
} ;
285
- Ok ( TyKind :: BoundVar ( BoundVar :: new ( DebruijnIndex :: INNERMOST , idx) )
286
- . intern ( Interner ) )
299
+ Ok ( BoundVar :: new ( outer_binder, idx) . to_ty ( Interner ) )
287
300
}
288
301
}
289
- let g_def = match owner {
290
- DefWithBodyId :: FunctionId ( f) => Some ( f. into ( ) ) ,
291
- DefWithBodyId :: StaticId ( _) => None ,
292
- DefWithBodyId :: ConstId ( f) => Some ( f. into ( ) ) ,
293
- DefWithBodyId :: VariantId ( f) => Some ( f. into ( ) ) ,
294
- } ;
295
- let Some ( generics) = g_def. map ( |g_def| generics ( db. upcast ( ) , g_def) ) else {
302
+ let Some ( generics) = owner. as_generic_def_id ( ) . map ( |g_def| generics ( db. upcast ( ) , g_def) ) else {
296
303
return Binders :: empty ( Interner , ty) ;
297
304
} ;
298
305
let filler = & mut Filler { db, generics } ;
299
306
let result = ty. clone ( ) . try_fold_with ( filler, DebruijnIndex :: INNERMOST ) . unwrap_or ( ty) ;
300
307
make_binders ( db, & filler. generics , result)
301
308
}
302
- let ty = self . place . ty ( ctx) . clone ( ) ;
303
- let ty = match & self . kind {
304
- CaptureKind :: ByValue => ty,
305
- CaptureKind :: ByRef ( bk) => {
306
- let m = match bk {
307
- BorrowKind :: Mut { .. } => Mutability :: Mut ,
308
- _ => Mutability :: Not ,
309
- } ;
310
- TyKind :: Ref ( m, static_lifetime ( ) , ty) . intern ( Interner )
311
- }
312
- } ;
313
- CapturedItem {
314
- place : self . place ,
315
- kind : self . kind ,
316
- span : self . span ,
317
- ty : replace_placeholder_with_binder ( ctx. db , ctx. owner , ty) ,
318
- }
319
309
}
320
310
}
321
311
0 commit comments