@@ -11,8 +11,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
1111 associated_item,
1212 associated_item_def_ids,
1313 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 ,
1616 impl_item_implementor_ids,
1717 ..* providers
1818 } ;
@@ -24,7 +24,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
2424 hir:: ItemKind :: Trait ( .., ref trait_item_refs) => {
2525 if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
2626 // 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
2828 // query.
2929 tcx. arena . alloc_from_iter (
3030 trait_item_refs
@@ -39,7 +39,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
3939 . flat_map ( |trait_item_ref| {
4040 let trait_fn_def_id =
4141 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+ )
4345 } )
4446 . map ( |def_id| * def_id) ,
4547 ) ,
@@ -56,7 +58,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
5658 if tcx. lower_impl_trait_in_trait_to_assoc_ty ( ) {
5759 // We collect RPITITs for each trait method's return type, on the impl side too and
5860 // 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.
6062 tcx. arena . alloc_from_iter (
6163 impl_
6264 . items
@@ -72,7 +74,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
7274 . flat_map ( |impl_item_ref| {
7375 let impl_fn_def_id =
7476 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+ )
7680 } )
7781 . map ( |def_id| * def_id)
7882 } ) ) ,
@@ -176,13 +180,19 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
176180 }
177181}
178182
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 ] {
186196 let parent_def_id = tcx. parent ( fn_def_id) ;
187197
188198 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) -
206216 visitor. visit_fn_ret_ty ( output) ;
207217
208218 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 ( )
210220 } ) )
211221 } else {
212222 & [ ]
@@ -217,9 +227,9 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
217227 let Some ( trait_fn_def_id) = tcx. associated_item ( fn_def_id) . trait_item_def_id else { return & [ ] } ;
218228
219229 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 (
221231 move |trait_assoc_def_id| {
222- impl_associated_item_for_impl_trait_in_trait (
232+ associated_type_for_impl_trait_in_impl (
223233 tcx,
224234 trait_assoc_def_id. expect_local ( ) ,
225235 fn_def_id. expect_local ( ) ,
@@ -231,16 +241,17 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
231241 }
232242
233243 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 {:?}" ,
235245 parent_def_id,
236246 def_kind
237247 ) ,
238248 }
239249}
240250
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 (
244255 tcx : TyCtxt < ' _ > ,
245256 opaque_ty_def_id : LocalDefId ,
246257) -> LocalDefId {
@@ -335,10 +346,12 @@ fn associated_item_for_impl_trait_in_trait(
335346 local_def_id
336347}
337348
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 (
342355 tcx : TyCtxt < ' _ > ,
343356 trait_assoc_def_id : LocalDefId ,
344357 impl_fn_def_id : LocalDefId ,
0 commit comments