Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 288e94c

Browse files
committed
Auto merge of #143783 - bvanjoi:issue-143697-2, r=compiler-errors
compute all rpitit of a trait Fixes #143697 r? `@compiler-errors`
2 parents bfc046a + 736bfa1 commit 288e94c

File tree

11 files changed

+162
-166
lines changed

11 files changed

+162
-166
lines changed

‎compiler/rustc_hir_analysis/src/check/wfcheck.rs

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,9 @@ pub(crate) fn check_trait_item<'tcx>(
326326
let mut res = Ok(());
327327

328328
if matches!(tcx.def_kind(def_id), DefKind::AssocFn) {
329-
for &assoc_ty_def_id in tcx.associated_types_for_impl_traits_in_associated_fn(def_id) {
329+
for &assoc_ty_def_id in
330+
tcx.associated_types_for_impl_traits_in_associated_fn(def_id.to_def_id())
331+
{
330332
res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local()));
331333
}
332334
}

‎compiler/rustc_hir_analysis/src/hir_ty_lowering/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2602,7 +2602,7 @@ impl<'tcx> dyn HirTyLowerer<'tcx> + '_ {
26022602
// do a linear search to map this to the synthetic associated type that
26032603
// it will be lowered to.
26042604
let def_id = if let Some(parent_def_id) = in_trait {
2605-
*tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id)
2605+
*tcx.associated_types_for_impl_traits_in_associated_fn(parent_def_id.to_def_id())
26062606
.iter()
26072607
.find(|rpitit| match tcx.opt_rpitit_info(**rpitit) {
26082608
Some(ty::ImplTraitInTraitData::Trait { opaque_def_id, .. }) => {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -326,7 +326,7 @@ provide! { tcx, def_id, other, cdata,
326326
.process_decoded(tcx, || panic!("{def_id:?} does not have trait_impl_trait_tys")))
327327
}
328328

329-
associated_types_for_impl_traits_in_associated_fn => { table_defaulted_array }
329+
associated_types_for_impl_traits_in_trait_or_impl => { table }
330330

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

‎compiler/rustc_metadata/src/rmeta/encoder.rs

Lines changed: 3 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1382,17 +1382,6 @@ fn should_encode_const(def_kind: DefKind) -> bool {
13821382
}
13831383
}
13841384

1385-
fn should_encode_fn_impl_trait_in_trait<'tcx>(tcx: TyCtxt<'tcx>, def_id: DefId) -> bool {
1386-
if let Some(assoc_item) = tcx.opt_associated_item(def_id)
1387-
&& assoc_item.container == ty::AssocItemContainer::Trait
1388-
&& assoc_item.is_fn()
1389-
{
1390-
true
1391-
} else {
1392-
false
1393-
}
1394-
}
1395-
13961385
impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
13971386
fn encode_attrs(&mut self, def_id: LocalDefId) {
13981387
let tcx = self.tcx;
@@ -1617,9 +1606,9 @@ impl<'a, 'tcx> EncodeContext<'a, 'tcx> {
16171606
{
16181607
record!(self.tables.trait_impl_trait_tys[def_id] <- table);
16191608
}
1620-
if should_encode_fn_impl_trait_in_trait(tcx, def_id) {
1621-
let table = tcx.associated_types_for_impl_traits_in_associated_fn(def_id);
1622-
record_defaulted_array!(self.tables.associated_types_for_impl_traits_in_associated_fn[def_id] <- table);
1609+
if letDefKind::Impl{ .. } | DefKind::Trait = def_kind {
1610+
let table = tcx.associated_types_for_impl_traits_in_trait_or_impl(def_id);
1611+
record!(self.tables.associated_types_for_impl_traits_in_trait_or_impl[def_id] <- table);
16231612
}
16241613
}
16251614

‎compiler/rustc_metadata/src/rmeta/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,6 @@ define_tables! {
403403
explicit_implied_predicates_of: Table<DefIndex, LazyArray<(ty::Clause<'static>, Span)>>,
404404
explicit_implied_const_bounds: Table<DefIndex, LazyArray<(ty::PolyTraitRef<'static>, Span)>>,
405405
inherent_impls: Table<DefIndex, LazyArray<DefIndex>>,
406-
associated_types_for_impl_traits_in_associated_fn: Table<DefIndex, LazyArray<DefId>>,
407406
opt_rpitit_info: Table<DefIndex, Option<LazyValue<ty::ImplTraitInTraitData>>>,
408407
// Reexported names are not associated with individual `DefId`s,
409408
// e.g. a glob import can introduce a lot of names, all with the same `DefId`.
@@ -482,6 +481,7 @@ define_tables! {
482481
assumed_wf_types_for_rpitit: Table<DefIndex, LazyArray<(Ty<'static>, Span)>>,
483482
opaque_ty_origin: Table<DefIndex, LazyValue<hir::OpaqueTyOrigin<DefId>>>,
484483
anon_const_kind: Table<DefIndex, LazyValue<ty::AnonConstKind>>,
484+
associated_types_for_impl_traits_in_trait_or_impl: Table<DefIndex, LazyValue<DefIdMap<Vec<DefId>>>>,
485485
}
486486

487487
#[derive(TyEncodable, TyDecodable)]

‎compiler/rustc_middle/src/query/mod.rs

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,15 +1079,11 @@ rustc_queries! {
10791079
desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
10801080
}
10811081

1082-
/// Given `fn_def_id` of a trait or of an impl that implements a given trait:
1083-
/// if `fn_def_id` is the def id of a function defined inside a trait, then it creates and returns
1084-
/// the associated items that correspond to each impl trait in return position for that trait.
1085-
/// if `fn_def_id` is the def id of a function defined inside an impl that implements a trait, then it
1086-
/// creates and returns the associated items that correspond to each impl trait in return position
1087-
/// of the implemented trait.
1088-
query associated_types_for_impl_traits_in_associated_fn(fn_def_id: DefId) -> &'tcx [DefId] {
1089-
desc { |tcx| "creating associated items for opaque types returned by `{}`", tcx.def_path_str(fn_def_id) }
1090-
cache_on_disk_if { fn_def_id.is_local() }
1082+
/// Given the `item_def_id` of a trait or impl, return a mapping from associated fn def id
1083+
/// to its associated type items that correspond to the RPITITs in its signature.
1084+
query associated_types_for_impl_traits_in_trait_or_impl(item_def_id: DefId) -> &'tcx DefIdMap<Vec<DefId>> {
1085+
arena_cache
1086+
desc { |tcx| "synthesizing RPITIT items for the opaque types for methods in `{}`", tcx.def_path_str(item_def_id) }
10911087
separate_provide_extern
10921088
}
10931089

‎compiler/rustc_middle/src/ty/assoc.rs

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -285,3 +285,22 @@ impl AssocItems {
285285
.find(|item| tcx.hygienic_eq(ident, item.ident(tcx), parent_def_id))
286286
}
287287
}
288+
289+
impl<'tcx> TyCtxt<'tcx> {
290+
/// Given an `fn_def_id` of a trait or a trait implementation:
291+
///
292+
/// if `fn_def_id` is a function defined inside a trait, then it synthesizes
293+
/// a new def id corresponding to a new associated type for each return-
294+
/// position `impl Trait` in the signature.
295+
///
296+
/// if `fn_def_id` is a function inside of an impl, then for each synthetic
297+
/// associated type generated for the corresponding trait function described
298+
/// above, synthesize a corresponding associated type in the impl.
299+
pub fn associated_types_for_impl_traits_in_associated_fn(
300+
self,
301+
fn_def_id: DefId,
302+
) -> &'tcx [DefId] {
303+
let parent_def_id = self.parent(fn_def_id);
304+
&self.associated_types_for_impl_traits_in_trait_or_impl(parent_def_id)[&fn_def_id]
305+
}
306+
}

‎compiler/rustc_middle/src/ty/parameterized.rs

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ impl<A: ParameterizedOverTcx, B: ParameterizedOverTcx> ParameterizedOverTcx for
2323
type Value<'tcx> = (A::Value<'tcx>, B::Value<'tcx>);
2424
}
2525

26+
impl<T: ParameterizedOverTcx> ParameterizedOverTcx for Vec<T> {
27+
type Value<'tcx> = Vec<T::Value<'tcx>>;
28+
}
29+
2630
impl<I: Idx + 'static, T: ParameterizedOverTcx> ParameterizedOverTcx for IndexVec<I, T> {
2731
type Value<'tcx> = IndexVec<I, T::Value<'tcx>>;
2832
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /