Skip to content

Commit ede3c39

Browse files
authored
Rollup merge of #109249 - compiler-errors:new-rpitit-comments, r=spastorino
Update names/comments for new return-position impl trait in trait lowering strategy r? `@spastorino` totally cosmetic
2 parents 9d0eac4 + 4fd66d7 commit ede3c39

File tree

7 files changed

+47
-32
lines changed

7 files changed

+47
-32
lines changed

compiler/rustc_hir_analysis/src/astconv/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -3068,7 +3068,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
30683068
// generate the def_id of an associated type for the trait and return as
30693069
// type a projection.
30703070
let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty() {
3071-
tcx.associated_item_for_impl_trait_in_trait(local_def_id).to_def_id()
3071+
tcx.associated_type_for_impl_trait_in_trait(local_def_id).to_def_id()
30723072
} else {
30733073
local_def_id.to_def_id()
30743074
};

compiler/rustc_metadata/src/rmeta/decoder/cstore_impl.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,7 @@ provide! { tcx, def_id, other, cdata,
254254
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
255255
}
256256

257-
associated_items_for_impl_trait_in_trait => { table_defaulted_array }
257+
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
258258

259259
visibility => { cdata.get_visibility(def_id.index) }
260260
adt_def => { cdata.get_adt_def(def_id.index, tcx) }

compiler/rustc_metadata/src/rmeta/encoder.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1198,8 +1198,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
11981198
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
11991199
}
12001200
if should_encode_fn_impl_trait_in_trait(tcx, def_id) {
1201-
let table = tcx.associated_items_for_impl_trait_in_trait(def_id);
1202-
record_defaulted_array!(self.tables.associated_items_for_impl_trait_in_trait[def_id] <- table);
1201+
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
1202+
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
12031203
}
12041204
}
12051205

compiler/rustc_metadata/src/rmeta/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -354,7 +354,7 @@ define_tables! {
354354
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
355355
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
356356
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
357-
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>,
357+
associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
358358
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,
359359
unused_generic_params: Table<DefIndex, UnusedGenericParams>,
360360

compiler/rustc_middle/src/query/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -785,15 +785,15 @@ rustc_queries! {
785785
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
786786
/// creates and returns the associated items that correspond to each impl trait in return position
787787
/// of the implemented trait.
788-
query associated_items_for_impl_trait_in_trait(fn_def_id: DefId) -> &'tcx [DefId] {
788+
query associated_types_for_impl_traits_in_associated_fn(fn_def_id: DefId) -> &'tcx [DefId] {
789789
desc { |tcx| "creating associated items for impl trait in trait returned by `{}`", tcx.def_path_str(fn_def_id) }
790790
cache_on_disk_if { fn_def_id.is_local() }
791791
separate_provide_extern
792792
}
793793

794794
/// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
795795
/// associated item.
796-
query associated_item_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
796+
query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
797797
desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
798798
cache_on_disk_if { true }
799799
separate_provide_extern

compiler/rustc_middle/src/ty/mod.rs

+3-1
Original file line numberDiff line numberDiff line change
@@ -2579,7 +2579,9 @@ impl<'tcx> TyCtxt<'tcx> {
25792579
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
25802580

25812581
if self.lower_impl_trait_in_trait_to_assoc_ty() {
2582-
return !self.associated_items_for_impl_trait_in_trait(trait_item_def_id).is_empty();
2582+
return !self
2583+
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
2584+
.is_empty();
25832585
}
25842586

25852587
// FIXME(RPITIT): This does a somewhat manual walk through the signature

compiler/rustc_ty_utils/src/assoc.rs

+37-24
Original file line numberDiff line numberDiff line change
@@ -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

Comments
 (0)