@@ -37,7 +37,7 @@ impl<'tcx> RustIrDatabase<'tcx> {
37
37
def_id : DefId ,
38
38
bound_vars : SubstsRef < ' tcx > ,
39
39
) -> Vec < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > > {
40
- let predicates = self . interner . tcx . predicates_of ( def_id) . predicates ;
40
+ let predicates = self . interner . tcx . predicates_defined_on ( def_id) . predicates ;
41
41
let mut regions_substitutor =
42
42
lowering:: RegionsSubstitutor :: new ( self . interner . tcx , self . reempty_placeholder ) ;
43
43
predicates
@@ -118,34 +118,27 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
118
118
. map ( |i| chalk_ir:: AssocTypeId ( i. def_id ) )
119
119
. collect ( ) ;
120
120
121
- let well_known = if self . interner . tcx . lang_items ( ) . sized_trait ( ) == Some ( def_id) {
121
+ let lang_items = self . interner . tcx . lang_items ( ) ;
122
+ let well_known = if lang_items. sized_trait ( ) == Some ( def_id) {
122
123
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Sized )
123
- } else if self . interner . tcx . lang_items ( ) . copy_trait ( ) == Some ( def_id) {
124
+ } else if lang_items. copy_trait ( ) == Some ( def_id) {
124
125
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Copy )
125
- } else if self . interner . tcx . lang_items ( ) . clone_trait ( ) == Some ( def_id) {
126
+ } else if lang_items. clone_trait ( ) == Some ( def_id) {
126
127
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Clone )
127
- } else if self . interner . tcx . lang_items ( ) . drop_trait ( ) == Some ( def_id) {
128
+ } else if lang_items. drop_trait ( ) == Some ( def_id) {
128
129
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Drop )
129
- } else if self . interner . tcx . lang_items ( ) . fn_trait ( ) == Some ( def_id) {
130
+ } else if lang_items. fn_trait ( ) == Some ( def_id) {
130
131
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Fn )
131
- } else if self
132
- . interner
133
- . tcx
134
- . lang_items ( )
135
- . fn_once_trait ( )
136
- . map ( |t| def_id == t)
137
- . unwrap_or ( false )
138
- {
132
+ } else if lang_items. fn_once_trait ( ) == Some ( def_id) {
139
133
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: FnOnce )
140
- } else if self
141
- . interner
142
- . tcx
143
- . lang_items ( )
144
- . fn_mut_trait ( )
145
- . map ( |t| def_id == t)
146
- . unwrap_or ( false )
147
- {
134
+ } else if lang_items. fn_mut_trait ( ) == Some ( def_id) {
148
135
Some ( chalk_solve:: rust_ir:: WellKnownTrait :: FnMut )
136
+ } else if lang_items. unsize_trait ( ) == Some ( def_id) {
137
+ Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Unsize )
138
+ } else if lang_items. unpin_trait ( ) == Some ( def_id) {
139
+ Some ( chalk_solve:: rust_ir:: WellKnownTrait :: Unpin )
140
+ } else if lang_items. coerce_unsized_trait ( ) == Some ( def_id) {
141
+ Some ( chalk_solve:: rust_ir:: WellKnownTrait :: CoerceUnsized )
149
142
} else {
150
143
None
151
144
} ;
@@ -281,11 +274,20 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
281
274
where_clauses,
282
275
} ;
283
276
277
+ let associated_ty_value_ids: Vec < _ > = self
278
+ . interner
279
+ . tcx
280
+ . associated_items ( def_id)
281
+ . in_definition_order ( )
282
+ . filter ( |i| i. kind == AssocKind :: Type )
283
+ . map ( |i| chalk_solve:: rust_ir:: AssociatedTyValueId ( i. def_id ) )
284
+ . collect ( ) ;
285
+
284
286
Arc :: new ( chalk_solve:: rust_ir:: ImplDatum {
285
- polarity : chalk_solve :: rust_ir :: Polarity :: Positive ,
287
+ polarity : self . interner . tcx . impl_polarity ( def_id ) . lower_into ( & self . interner ) ,
286
288
binders : chalk_ir:: Binders :: new ( binders, value) ,
287
289
impl_type : chalk_solve:: rust_ir:: ImplType :: Local ,
288
- associated_ty_value_ids : vec ! [ ] ,
290
+ associated_ty_value_ids,
289
291
} )
290
292
}
291
293
@@ -406,24 +408,38 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
406
408
) -> Arc < chalk_solve:: rust_ir:: AssociatedTyValue < RustInterner < ' tcx > > > {
407
409
let def_id = associated_ty_id. 0 ;
408
410
let assoc_item = self . interner . tcx . associated_item ( def_id) ;
409
- let impl_id = match assoc_item. container {
410
- AssocItemContainer :: TraitContainer ( def_id) => def_id,
411
- _ => unimplemented ! ( "Not possible??" ) ,
411
+ let ( impl_id, trait_id) = match assoc_item. container {
412
+ AssocItemContainer :: TraitContainer ( def_id) => ( def_id, def_id) ,
413
+ AssocItemContainer :: ImplContainer ( def_id) => {
414
+ ( def_id, self . interner . tcx . impl_trait_ref ( def_id) . unwrap ( ) . def_id )
415
+ }
412
416
} ;
413
417
match assoc_item. kind {
414
418
AssocKind :: Type => { }
415
419
_ => unimplemented ! ( "Not possible??" ) ,
416
420
}
421
+
422
+ let trait_item = self
423
+ . interner
424
+ . tcx
425
+ . associated_items ( trait_id)
426
+ . find_by_name_and_kind ( self . interner . tcx , assoc_item. ident , assoc_item. kind , trait_id)
427
+ . unwrap ( ) ;
417
428
let bound_vars = bound_vars_for_item ( self . interner . tcx , def_id) ;
418
429
let binders = binders_for ( & self . interner , bound_vars) ;
419
- let ty = self . interner . tcx . type_of ( def_id) ;
430
+ let ty = self
431
+ . interner
432
+ . tcx
433
+ . type_of ( def_id)
434
+ . subst ( self . interner . tcx , bound_vars)
435
+ . lower_into ( & self . interner ) ;
420
436
421
437
Arc :: new ( chalk_solve:: rust_ir:: AssociatedTyValue {
422
438
impl_id : chalk_ir:: ImplId ( impl_id) ,
423
- associated_ty_id : chalk_ir:: AssocTypeId ( def_id) ,
439
+ associated_ty_id : chalk_ir:: AssocTypeId ( trait_item . def_id ) ,
424
440
value : chalk_ir:: Binders :: new (
425
441
binders,
426
- chalk_solve:: rust_ir:: AssociatedTyValueBound { ty : ty . lower_into ( & self . interner ) } ,
442
+ chalk_solve:: rust_ir:: AssociatedTyValueBound { ty } ,
427
443
) ,
428
444
} )
429
445
}
@@ -443,19 +459,61 @@ impl<'tcx> chalk_solve::RustIrDatabase<RustInterner<'tcx>> for RustIrDatabase<'t
443
459
& self ,
444
460
opaque_ty_id : chalk_ir:: OpaqueTyId < RustInterner < ' tcx > > ,
445
461
) -> Arc < chalk_solve:: rust_ir:: OpaqueTyDatum < RustInterner < ' tcx > > > {
446
- let bound_vars = bound_vars_for_item ( self . interner . tcx , opaque_ty_id. 0 ) ;
447
- let binders = binders_for ( & self . interner , bound_vars) ;
462
+ let bound_vars = ty:: fold:: shift_vars (
463
+ self . interner . tcx ,
464
+ & bound_vars_for_item ( self . interner . tcx , opaque_ty_id. 0 ) ,
465
+ 1 ,
466
+ ) ;
448
467
let where_clauses = self . where_clauses_for ( opaque_ty_id. 0 , bound_vars) ;
449
- let bounds = self . bounds_for ( opaque_ty_id. 0 , bound_vars) ;
468
+
469
+ let identity_substs = InternalSubsts :: identity_for_item ( self . interner . tcx , opaque_ty_id. 0 ) ;
470
+
471
+ let bounds =
472
+ self . interner
473
+ . tcx
474
+ . explicit_item_bounds ( opaque_ty_id. 0 )
475
+ . iter ( )
476
+ . map ( |( bound, _) | bound. subst ( self . interner . tcx , & bound_vars) )
477
+ . map ( |bound| {
478
+ bound. fold_with ( & mut ty:: fold:: BottomUpFolder {
479
+ tcx : self . interner . tcx ,
480
+ ty_op : |ty| {
481
+ if let ty:: Opaque ( def_id, substs) = * ty. kind ( ) {
482
+ if def_id == opaque_ty_id. 0 && substs == identity_substs {
483
+ return self . interner . tcx . mk_ty ( ty:: Bound (
484
+ ty:: INNERMOST ,
485
+ ty:: BoundTy :: from ( ty:: BoundVar :: from_u32 ( 0 ) ) ,
486
+ ) ) ;
487
+ }
488
+ }
489
+ ty
490
+ } ,
491
+ lt_op : |lt| lt,
492
+ ct_op : |ct| ct,
493
+ } )
494
+ } )
495
+ . filter_map ( |bound| {
496
+ LowerInto :: <
497
+ Option < chalk_ir:: QuantifiedWhereClause < RustInterner < ' tcx > > >
498
+ > :: lower_into ( bound, & self . interner )
499
+ } )
500
+ . collect ( ) ;
501
+
502
+ // Binder for the bound variable representing the concrete impl Trait type.
503
+ let existential_binder = chalk_ir:: VariableKinds :: from1 (
504
+ & self . interner ,
505
+ chalk_ir:: VariableKind :: Ty ( chalk_ir:: TyVariableKind :: General ) ,
506
+ ) ;
450
507
451
508
let value = chalk_solve:: rust_ir:: OpaqueTyDatumBound {
452
- bounds : chalk_ir:: Binders :: new ( binders . clone ( ) , bounds) ,
453
- where_clauses : chalk_ir:: Binders :: new ( binders , where_clauses) ,
509
+ bounds : chalk_ir:: Binders :: new ( existential_binder . clone ( ) , bounds) ,
510
+ where_clauses : chalk_ir:: Binders :: new ( existential_binder , where_clauses) ,
454
511
} ;
455
512
513
+ let binders = binders_for ( & self . interner , bound_vars) ;
456
514
Arc :: new ( chalk_solve:: rust_ir:: OpaqueTyDatum {
457
515
opaque_ty_id,
458
- bound : chalk_ir:: Binders :: empty ( & self . interner , value) ,
516
+ bound : chalk_ir:: Binders :: new ( binders , value) ,
459
517
} )
460
518
}
461
519
0 commit comments