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 736bfa1

Browse files
Clean up implementation of RPITIT assoc item lowering
1 parent 47e15d9 commit 736bfa1

File tree

9 files changed

+110
-146
lines changed

9 files changed

+110
-146
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@ use rustc_middle::ty::error::{ExpectedFound, TypeError};
1515
use rustc_middle::ty::{
1616
self, BottomUpFolder, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFoldable, TypeFolder,
1717
TypeSuperFoldable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode, Upcast,
18-
associated_types_for_impl_traits_in_associated_fn,
1918
};
2019
use rustc_middle::{bug, span_bug};
2120
use rustc_span::{DUMMY_SP, Span};
@@ -758,7 +757,7 @@ pub(super) fn collect_return_position_impl_trait_in_trait_tys<'tcx>(
758757
// returning `-> Missing<impl Sized>`, that gets converted to `-> {type error}`,
759758
// and when walking through the signature we end up never collecting the def id
760759
// of the `impl Sized`. Insert that here, so we don't ICE later.
761-
for assoc_item in associated_types_for_impl_traits_in_associated_fn(tcx,trait_m.def_id) {
760+
for assoc_item in tcx.associated_types_for_impl_traits_in_associated_fn(trait_m.def_id) {
762761
if !remapped_types.contains_key(assoc_item) {
763762
remapped_types.insert(
764763
*assoc_item,
@@ -2449,7 +2448,8 @@ fn param_env_with_gat_bounds<'tcx>(
24492448
ty::ImplTraitInTraitData::Impl { fn_def_id }
24502449
| ty::ImplTraitInTraitData::Trait { fn_def_id, .. },
24512450
),
2452-
} => associated_types_for_impl_traits_in_associated_fn(tcx, fn_def_id)
2451+
} => tcx
2452+
.associated_types_for_impl_traits_in_associated_fn(fn_def_id)
24532453
.iter()
24542454
.map(|def_id| tcx.associated_item(*def_id))
24552455
.collect(),

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ use rustc_middle::ty::trait_def::TraitSpecializationKind;
2020
use rustc_middle::ty::{
2121
self, AdtKind, GenericArgKind, GenericArgs, GenericParamDefKind, Ty, TyCtxt, TypeFlags,
2222
TypeFoldable, TypeSuperVisitable, TypeVisitable, TypeVisitableExt, TypeVisitor, TypingMode,
23-
Upcast, associated_types_for_impl_traits_in_associated_fn,
23+
Upcast,
2424
};
2525
use rustc_middle::{bug, span_bug};
2626
use rustc_session::parse::feature_err;
@@ -327,7 +327,7 @@ pub(crate) fn check_trait_item<'tcx>(
327327

328328
if matches!(tcx.def_kind(def_id), DefKind::AssocFn) {
329329
for &assoc_ty_def_id in
330-
associated_types_for_impl_traits_in_associated_fn(tcx,def_id.to_def_id())
330+
tcx.associated_types_for_impl_traits_in_associated_fn(def_id.to_def_id())
331331
{
332332
res = res.and(check_associated_item(tcx, assoc_ty_def_id.expect_local()));
333333
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ use rustc_middle::mir::interpret::LitToConstInput;
4040
use rustc_middle::ty::print::PrintPolyTraitRefExt as _;
4141
use rustc_middle::ty::{
4242
self, Const, GenericArgKind, GenericArgsRef, GenericParamDefKind, Ty, TyCtxt, TypeVisitableExt,
43-
TypingMode, Upcast, associated_types_for_impl_traits_in_associated_fn,fold_regions,
43+
TypingMode, Upcast, fold_regions,
4444
};
4545
use rustc_middle::{bug, span_bug};
4646
use rustc_session::lint::builtin::AMBIGUOUS_ASSOCIATED_ITEMS;
@@ -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-
*associated_types_for_impl_traits_in_associated_fn(tcx,parent_def_id.to_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/mod.rs‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -481,7 +481,7 @@ define_tables! {
481481
assumed_wf_types_for_rpitit: Table<DefIndex, LazyArray<(Ty<'static>, Span)>>,
482482
opaque_ty_origin: Table<DefIndex, LazyValue<hir::OpaqueTyOrigin<DefId>>>,
483483
anon_const_kind: Table<DefIndex, LazyValue<ty::AnonConstKind>>,
484-
associated_types_for_impl_traits_in_trait_or_impl: Table<DefIndex, LazyValue<ty::AssocTyForImplTraitInTraitOrImpl>>,
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: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,9 +1079,11 @@ rustc_queries! {
10791079
desc { |tcx| "comparing impl items against trait for `{}`", tcx.def_path_str(impl_id) }
10801080
}
10811081

1082-
query associated_types_for_impl_traits_in_trait_or_impl(did: DefId) -> &'tcx ty::AssocTyForImplTraitInTraitOrImpl {
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>> {
10831085
arena_cache
1084-
desc { |tcx| "creating rpitit for `{}`", tcx.def_path_str(did) }
1086+
desc { |tcx| "synthesizing RPITIT items for the opaque types for methods in `{}`", tcx.def_path_str(item_def_id) }
10851087
separate_provide_extern
10861088
}
10871089

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

Lines changed: 17 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
use rustc_attr_data_structures::{AttributeKind, find_attr};
2-
use rustc_data_structures::fx::FxIndexMap;
32
use rustc_data_structures::sorted_map::SortedIndexMultiMap;
43
use rustc_hir as hir;
54
use rustc_hir::def::{DefKind, Namespace};
@@ -287,22 +286,21 @@ impl AssocItems {
287286
}
288287
}
289288

290-
#[derive(Debug, Clone, PartialEq, Encodable, Decodable, HashStable)]
291-
pub struct AssocTyForImplTraitInTraitOrImpl(pub FxIndexMap<DefId, Vec<DefId>>);
292-
293-
/// Given an `fn_def_id` of a trait or a trait implementation:
294-
///
295-
/// if `fn_def_id` is a function defined inside a trait, then it synthesizes
296-
/// a new def id corresponding to a new associated type for each return-
297-
/// position `impl Trait` in the signature.
298-
///
299-
/// if `fn_def_id` is a function inside of an impl, then for each synthetic
300-
/// associated type generated for the corresponding trait function described
301-
/// above, synthesize a corresponding associated type in the impl.
302-
pub fn associated_types_for_impl_traits_in_associated_fn(
303-
tcx: TyCtxt<'_>,
304-
fn_def_id: DefId,
305-
) -> &'_ [DefId] {
306-
let parent_def_id = tcx.parent(fn_def_id);
307-
&tcx.associated_types_for_impl_traits_in_trait_or_impl(parent_def_id).0[&fn_def_id]
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+
}
308306
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2194,7 +2194,8 @@ impl<'tcx> TyCtxt<'tcx> {
21942194
return false;
21952195
};
21962196

2197-
return !associated_types_for_impl_traits_in_associated_fn(self, trait_item_def_id)
2197+
return !self
2198+
.associated_types_for_impl_traits_in_associated_fn(trait_item_def_id)
21982199
.is_empty();
21992200
}
22002201
}

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

Lines changed: 4 additions & 1 deletion
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
}
@@ -67,7 +71,6 @@ trivially_parameterized_over_tcx! {
6771
crate::mir::ConstQualifs,
6872
ty::AsyncDestructor,
6973
ty::AssocItemContainer,
70-
ty::AssocTyForImplTraitInTraitOrImpl,
7174
ty::Asyncness,
7275
ty::AnonConstKind,
7376
ty::DeducedParamAttrs,

0 commit comments

Comments
(0)

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