Update some names and comments

This commit is contained in:
Michael Goulet 2023-03-17 03:45:14 +00:00
parent da7c50c089
commit 4fd66d70cb
7 changed files with 47 additions and 32 deletions

View File

@ -3068,7 +3068,7 @@ impl<'o, 'tcx> dyn AstConv<'tcx> + 'o {
// generate the def_id of an associated type for the trait and return as // generate the def_id of an associated type for the trait and return as
// type a projection. // type a projection.
let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty() { let def_id = if in_trait && tcx.lower_impl_trait_in_trait_to_assoc_ty() {
tcx.associated_item_for_impl_trait_in_trait(local_def_id).to_def_id() tcx.associated_type_for_impl_trait_in_trait(local_def_id).to_def_id()
} else { } else {
local_def_id.to_def_id() local_def_id.to_def_id()
}; };

View File

@ -254,7 +254,7 @@ provide! { tcx, def_id, other, cdata,
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys"))) .process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
} }
associated_items_for_impl_trait_in_trait => { table_defaulted_array } associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
visibility => { cdata.get_visibility(def_id.index) } visibility => { cdata.get_visibility(def_id.index) }
adt_def => { cdata.get_adt_def(def_id.index, tcx) } adt_def => { cdata.get_adt_def(def_id.index, tcx) }

View File

@ -1198,8 +1198,8 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
record!(self.tables.trait_impl_trait_tys[def_id] <- table); record!(self.tables.trait_impl_trait_tys[def_id] <- table);
} }
if should_encode_fn_impl_trait_in_trait(tcx, def_id) { if should_encode_fn_impl_trait_in_trait(tcx, def_id) {
let table = tcx.associated_items_for_impl_trait_in_trait(def_id); let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
record_defaulted_array!(self.tables.associated_items_for_impl_trait_in_trait[def_id] <- table); record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
} }
} }

View File

@ -354,7 +354,7 @@ define_tables! {
explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>, explicit_item_bounds: Table<DefIndex, LazyArray<(ty::Predicate<'static>, Span)>>,
inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>, inferred_outlives_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>, inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
associated_items_for_impl_trait_in_trait: Table<DefIndex, LazyArray<DefId>>, associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>, opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,
unused_generic_params: Table<DefIndex, UnusedGenericParams>, unused_generic_params: Table<DefIndex, UnusedGenericParams>,

View File

@ -785,7 +785,7 @@ rustc_queries! {
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it /// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
/// creates and returns the associated items that correspond to each impl trait in return position /// creates and returns the associated items that correspond to each impl trait in return position
/// of the implemented trait. /// of the implemented trait.
query associated_items_for_impl_trait_in_trait(fn_def_id: DefId) -> &'tcx [DefId] { query associated_types_for_impl_traits_in_associated_fn(fn_def_id: DefId) -> &'tcx [DefId] {
desc { |tcx| "creating associated items for impl trait in trait returned by `{}`", tcx.def_path_str(fn_def_id) } desc { |tcx| "creating associated items for impl trait in trait returned by `{}`", tcx.def_path_str(fn_def_id) }
cache_on_disk_if { fn_def_id.is_local() } cache_on_disk_if { fn_def_id.is_local() }
separate_provide_extern separate_provide_extern
@ -793,7 +793,7 @@ rustc_queries! {
/// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding /// Given an impl trait in trait `opaque_ty_def_id`, create and return the corresponding
/// associated item. /// associated item.
query associated_item_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId { query associated_type_for_impl_trait_in_trait(opaque_ty_def_id: LocalDefId) -> LocalDefId {
desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) } desc { |tcx| "creates the associated item corresponding to the opaque type `{}`", tcx.def_path_str(opaque_ty_def_id.to_def_id()) }
cache_on_disk_if { true } cache_on_disk_if { true }
separate_provide_extern separate_provide_extern

View File

@ -2579,7 +2579,9 @@ impl<'tcx> TyCtxt<'tcx> {
let Some(trait_item_def_id) = item.trait_item_def_id else { return false; }; let Some(trait_item_def_id) = item.trait_item_def_id else { return false; };
if self.lower_impl_trait_in_trait_to_assoc_ty() { if self.lower_impl_trait_in_trait_to_assoc_ty() {
return !self.associated_items_for_impl_trait_in_trait(trait_item_def_id).is_empty(); return !self
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
.is_empty();
} }
// FIXME(RPITIT): This does a somewhat manual walk through the signature // FIXME(RPITIT): This does a somewhat manual walk through the signature

View File

@ -11,8 +11,8 @@ pub fn provide(providers: &mut ty::query::Providers) {
associated_item, associated_item,
associated_item_def_ids, associated_item_def_ids,
associated_items, associated_items,
associated_items_for_impl_trait_in_trait, associated_types_for_impl_traits_in_associated_fn,
associated_item_for_impl_trait_in_trait, associated_type_for_impl_trait_in_trait,
impl_item_implementor_ids, impl_item_implementor_ids,
..*providers ..*providers
}; };
@ -24,7 +24,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
hir::ItemKind::Trait(.., ref trait_item_refs) => { hir::ItemKind::Trait(.., ref trait_item_refs) => {
if tcx.lower_impl_trait_in_trait_to_assoc_ty() { if tcx.lower_impl_trait_in_trait_to_assoc_ty() {
// We collect RPITITs for each trait method's return type and create a // We collect RPITITs for each trait method's return type and create a
// corresponding associated item using associated_items_for_impl_trait_in_trait // corresponding associated item using associated_types_for_impl_traits_in_associated_fn
// query. // query.
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
trait_item_refs trait_item_refs
@ -39,7 +39,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
.flat_map(|trait_item_ref| { .flat_map(|trait_item_ref| {
let trait_fn_def_id = let trait_fn_def_id =
trait_item_ref.id.owner_id.def_id.to_def_id(); trait_item_ref.id.owner_id.def_id.to_def_id();
tcx.associated_items_for_impl_trait_in_trait(trait_fn_def_id) tcx.associated_types_for_impl_traits_in_associated_fn(
trait_fn_def_id,
)
}) })
.map(|def_id| *def_id), .map(|def_id| *def_id),
), ),
@ -56,7 +58,7 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
if tcx.lower_impl_trait_in_trait_to_assoc_ty() { if tcx.lower_impl_trait_in_trait_to_assoc_ty() {
// We collect RPITITs for each trait method's return type, on the impl side too and // We collect RPITITs for each trait method's return type, on the impl side too and
// create a corresponding associated item using // create a corresponding associated item using
// associated_items_for_impl_trait_in_trait query. // associated_types_for_impl_traits_in_associated_fn query.
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
impl_ impl_
.items .items
@ -72,7 +74,9 @@ fn associated_item_def_ids(tcx: TyCtxt<'_>, def_id: DefId) -> &[DefId] {
.flat_map(|impl_item_ref| { .flat_map(|impl_item_ref| {
let impl_fn_def_id = let impl_fn_def_id =
impl_item_ref.id.owner_id.def_id.to_def_id(); impl_item_ref.id.owner_id.def_id.to_def_id();
tcx.associated_items_for_impl_trait_in_trait(impl_fn_def_id) tcx.associated_types_for_impl_traits_in_associated_fn(
impl_fn_def_id,
)
}) })
.map(|def_id| *def_id) .map(|def_id| *def_id)
})), })),
@ -176,13 +180,19 @@ fn associated_item_from_impl_item_ref(impl_item_ref: &hir::ImplItemRef) -> ty::A
} }
} }
/// Given an `fn_def_id` of a trait or of an impl that implements a given trait: /// Given an `fn_def_id` of a trait or a trait implementation:
/// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns ///
/// the associated items that correspond to each impl trait in return position for that trait. /// if `fn_def_id` is a function defined inside a trait, then it synthesizes
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it /// a new def id corresponding to a new associated type for each return-
/// creates and returns the associated items that correspond to each impl trait in return position /// position `impl Trait` in the signature.
/// of the implemented trait. ///
fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -> &'_ [DefId] { /// if `fn_def_id` is a function inside of an impl, then for each synthetic
/// associated type generated for the corresponding trait function described
/// above, synthesize a corresponding associated type in the impl.
fn associated_types_for_impl_traits_in_associated_fn(
tcx: TyCtxt<'_>,
fn_def_id: DefId,
) -> &'_ [DefId] {
let parent_def_id = tcx.parent(fn_def_id); let parent_def_id = tcx.parent(fn_def_id);
match tcx.def_kind(parent_def_id) { 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) -
visitor.visit_fn_ret_ty(output); visitor.visit_fn_ret_ty(output);
tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| { tcx.arena.alloc_from_iter(visitor.rpits.iter().map(|opaque_ty_def_id| {
tcx.associated_item_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id() tcx.associated_type_for_impl_trait_in_trait(opaque_ty_def_id).to_def_id()
})) }))
} else { } else {
&[] &[]
@ -217,9 +227,9 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
let Some(trait_fn_def_id) = tcx.associated_item(fn_def_id).trait_item_def_id else { return &[] }; let Some(trait_fn_def_id) = tcx.associated_item(fn_def_id).trait_item_def_id else { return &[] };
tcx.arena.alloc_from_iter( tcx.arena.alloc_from_iter(
tcx.associated_items_for_impl_trait_in_trait(trait_fn_def_id).iter().map( tcx.associated_types_for_impl_traits_in_associated_fn(trait_fn_def_id).iter().map(
move |trait_assoc_def_id| { move |trait_assoc_def_id| {
impl_associated_item_for_impl_trait_in_trait( associated_type_for_impl_trait_in_impl(
tcx, tcx,
trait_assoc_def_id.expect_local(), trait_assoc_def_id.expect_local(),
fn_def_id.expect_local(), fn_def_id.expect_local(),
@ -231,16 +241,17 @@ fn associated_items_for_impl_trait_in_trait(tcx: TyCtxt<'_>, fn_def_id: DefId) -
} }
def_kind => bug!( def_kind => bug!(
"associated_items_for_impl_trait_in_trait: {:?} should be Trait or Impl but is {:?}", "associated_types_for_impl_traits_in_associated_fn: {:?} should be Trait or Impl but is {:?}",
parent_def_id, parent_def_id,
def_kind def_kind
), ),
} }
} }
/// Given an `opaque_ty_def_id` corresponding to an impl trait in trait, create and return the /// Given an `opaque_ty_def_id` corresponding to an `impl Trait` in an associated
/// corresponding associated item. /// function from a trait, synthesize an associated type for that `impl Trait`
fn associated_item_for_impl_trait_in_trait( /// that inherits properties that we infer from the method and the opaque type.
fn associated_type_for_impl_trait_in_trait(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
opaque_ty_def_id: LocalDefId, opaque_ty_def_id: LocalDefId,
) -> LocalDefId { ) -> LocalDefId {
@ -335,10 +346,12 @@ fn associated_item_for_impl_trait_in_trait(
local_def_id local_def_id
} }
/// Given an `trait_assoc_def_id` that corresponds to a previously synthesized impl trait in trait /// Given an `trait_assoc_def_id` corresponding to an associated item synthesized
/// into an associated type and an `impl_def_id` corresponding to an impl block, create and return /// from an `impl Trait` in an associated function from a trait, and an
/// the corresponding associated item inside the impl block. /// `impl_fn_def_id` that represents an implementation of the associated function
fn impl_associated_item_for_impl_trait_in_trait( /// that the `impl Trait` comes from, synthesize an associated type for that `impl Trait`
/// that inherits properties that we infer from the method and the associated type.
fn associated_type_for_impl_trait_in_impl(
tcx: TyCtxt<'_>, tcx: TyCtxt<'_>,
trait_assoc_def_id: LocalDefId, trait_assoc_def_id: LocalDefId,
impl_fn_def_id: LocalDefId, impl_fn_def_id: LocalDefId,