@@ -11,8 +11,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
11
11
associated_item,
12
12
associated_item_def_ids,
13
13
associated_items,
14
- associated_items_for_impl_trait_in_trait ,
15
- associated_item_for_impl_trait_in_trait ,
14
+ associated_types_for_impl_traits_in_associated_fn ,
15
+ associated_type_for_impl_trait_in_trait ,
16
16
impl_item_implementor_ids,
17
17
..* providers
18
18
} ;
@@ -24,7 +24,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
24
24
hir:: ItemKind :: Trait ( .., ref trait_item_refs) => {
25
25
if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
26
26
// We collect RPITITs for each trait method's return type and create a
27
- // corresponding associated item using associated_items_for_impl_trait_in_trait
27
+ // corresponding associated item using associated_types_for_impl_traits_in_associated_fn
28
28
// query.
29
29
tcx. arena . alloc_from_iter (
30
30
trait_item_refs
@@ -39,7 +39,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
39
39
. flat_map ( |trait_item_ref| {
40
40
let trait_fn_def_id =
41
41
trait_item_ref. id . owner_id . def_id . to_def_id ( ) ;
42
- tcx. associated_items_for_impl_trait_in_trait ( trait_fn_def_id)
42
+ tcx. associated_types_for_impl_traits_in_associated_fn (
43
+ trait_fn_def_id,
44
+ )
43
45
} )
44
46
. map ( |def_id| * def_id) ,
45
47
) ,
@@ -56,7 +58,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
56
58
if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
57
59
// We collect RPITITs for each trait method's return type, on the impl side too and
58
60
// create a corresponding associated item using
59
- // associated_items_for_impl_trait_in_trait query.
61
+ // associated_types_for_impl_traits_in_associated_fn query.
60
62
tcx. arena . alloc_from_iter (
61
63
impl_
62
64
. items
@@ -72,7 +74,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
72
74
. flat_map ( |impl_item_ref| {
73
75
let impl_fn_def_id =
74
76
impl_item_ref. id . owner_id . def_id . to_def_id ( ) ;
75
- tcx. associated_items_for_impl_trait_in_trait ( impl_fn_def_id)
77
+ tcx. associated_types_for_impl_traits_in_associated_fn (
78
+ impl_fn_def_id,
79
+ )
76
80
} )
77
81
. map ( |def_id| * def_id)
78
82
} ) ) ,
@@ -176,13 +180,19 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
176
180
}
177
181
}
178
182
179
- /// Given an `fn_def_id` of a trait or of an impl that implements a given trait:
180
- /// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns
181
- /// the associated items that correspond to each impl trait in return position for that trait.
182
- /// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
183
- /// creates and returns the associated items that correspond to each impl trait in return position
184
- /// of the implemented trait.
185
- fn associated_items_for_impl_trait_in_trait ( tcx : TyCtxt < ' _ > , fn_def_id : DefId ) -> & ' _ [ DefId ] {
183
+ /// Given an `fn_def_id` of a trait or a trait implementation:
184
+ ///
185
+ /// if `fn_def_id` is a function defined inside a trait, then it synthesizes
186
+ /// a new def id corresponding to a new associated type for each return-
187
+ /// position `impl Trait` in the signature.
188
+ ///
189
+ /// if `fn_def_id` is a function inside of an impl, then for each synthetic
190
+ /// associated type generated for the corresponding trait function described
191
+ /// above, synthesize a corresponding associated type in the impl.
192
+ fn associated_types_for_impl_traits_in_associated_fn (
193
+ tcx : TyCtxt < ' _ > ,
194
+ fn_def_id : DefId ,
195
+ ) -> & ' _ [ DefId ] {
186
196
let parent_def_id = tcx. parent ( fn_def_id) ;
187
197
188
198
match tcx. def_kind ( parent_def_id) {
@@ -206,7 +216,7 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
206
216
visitor. visit_fn_ret_ty ( output) ;
207
217
208
218
tcx. arena . alloc_from_iter ( visitor. rpits . iter ( ) . map ( |opaque_ty_def_id| {
209
- tcx. associated_item_for_impl_trait_in_trait ( opaque_ty_def_id) . to_def_id ( )
219
+ tcx. associated_type_for_impl_trait_in_trait ( opaque_ty_def_id) . to_def_id ( )
210
220
} ) )
211
221
} else {
212
222
& [ ]
@@ -217,9 +227,9 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
217
227
let Some ( trait_fn_def_id) = tcx. associated_item ( fn_def_id) . trait_item_def_id else { return & [ ] } ;
218
228
219
229
tcx. arena . alloc_from_iter (
220
- tcx. associated_items_for_impl_trait_in_trait ( trait_fn_def_id) . iter ( ) . map (
230
+ tcx. associated_types_for_impl_traits_in_associated_fn ( trait_fn_def_id) . iter ( ) . map (
221
231
move |trait_assoc_def_id| {
222
- impl_associated_item_for_impl_trait_in_trait (
232
+ associated_type_for_impl_trait_in_impl (
223
233
tcx,
224
234
trait_assoc_def_id. expect_local ( ) ,
225
235
fn_def_id. expect_local ( ) ,
@@ -231,16 +241,17 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
231
241
}
232
242
233
243
def_kind => bug ! (
234
- "associated_items_for_impl_trait_in_trait : {:?} should be Trait or Impl but is {:?}" ,
244
+ "associated_types_for_impl_traits_in_associated_fn : {:?} should be Trait or Impl but is {:?}" ,
235
245
parent_def_id,
236
246
def_kind
237
247
) ,
238
248
}
239
249
}
240
250
241
- /// Given an `opaque_ty_def_id` corresponding to an impl trait in trait, create and return the
242
- /// corresponding associated item.
243
- fn associated_item_for_impl_trait_in_trait (
251
+ /// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
252
+ /// function from a trait, synthesize an associated type for that `impl Trait`
253
+ /// that inherits properties that we infer from the method and the opaque type.
254
+ fn associated_type_for_impl_trait_in_trait (
244
255
tcx : TyCtxt < ' _ > ,
245
256
opaque_ty_def_id : LocalDefId ,
246
257
) -> LocalDefId {
@@ -335,10 +346,12 @@ fn associated_item_for_impl_trait_in_trait(
335
346
local_def_id
336
347
}
337
348
338
- /// Given an `trait_assoc_def_id` that corresponds to a previously synthesized impl trait in trait
339
- /// into an associated type and an `impl_def_id` corresponding to an impl block, create and return
340
- /// the corresponding associated item inside the impl block.
341
- fn impl_associated_item_for_impl_trait_in_trait (
349
+ /// Given an `trait_assoc_def_id` corresponding to an associated item synthesized
350
+ /// from an `impl Trait` in an associated function from a trait, and an
351
+ /// `impl_fn_def_id` that represents an implementation of the associated function
352
+ /// that the `impl Trait` comes from, synthesize an associated type for that `impl Trait`
353
+ /// that inherits properties that we infer from the method and the associated type.
354
+ fn associated_type_for_impl_trait_in_impl (
342
355
tcx : TyCtxt < ' _ > ,
343
356
trait_assoc_def_id : LocalDefId ,
344
357
impl_fn_def_id : LocalDefId ,
0 commit comments