iter_identity is a better name

This commit is contained in:
Michael Goulet 2024-07-06 11:54:22 -04:00
parent 289deb9ed7
commit 58aad3c72c
11 changed files with 26 additions and 37 deletions

View File

@ -477,7 +477,7 @@ fn check_gat_where_clauses(tcx: TyCtxt<'_>, trait_def_id: LocalDefId) {
param_env, param_env,
item_def_id, item_def_id,
tcx.explicit_item_bounds(item_def_id) tcx.explicit_item_bounds(item_def_id)
.instantiate_identity_iter_copied() .iter_identity_copied()
.collect::<Vec<_>>(), .collect::<Vec<_>>(),
&FxIndexSet::default(), &FxIndexSet::default(),
gat_def_id, gat_def_id,
@ -1204,8 +1204,7 @@ fn check_associated_type_bounds(wfcx: &WfCheckingCtxt<'_, '_>, item: ty::AssocIt
let bounds = wfcx.tcx().explicit_item_bounds(item.def_id); let bounds = wfcx.tcx().explicit_item_bounds(item.def_id);
debug!("check_associated_type_bounds: bounds={:?}", bounds); debug!("check_associated_type_bounds: bounds={:?}", bounds);
let wf_obligations = let wf_obligations = bounds.iter_identity_copied().flat_map(|(bound, bound_span)| {
bounds.instantiate_identity_iter_copied().flat_map(|(bound, bound_span)| {
let normalized_bound = wfcx.normalize(span, None, bound); let normalized_bound = wfcx.normalize(span, None, bound);
traits::wf::clause_obligations( traits::wf::clause_obligations(
wfcx.infcx, wfcx.infcx,

View File

@ -1752,10 +1752,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
fcx.probe(|_| { fcx.probe(|_| {
let ocx = ObligationCtxt::new(fcx); let ocx = ObligationCtxt::new(fcx);
ocx.register_obligations( ocx.register_obligations(
fcx.tcx fcx.tcx.item_super_predicates(rpit_def_id).iter_identity().filter_map(
.item_super_predicates(rpit_def_id) |clause| {
.instantiate_identity_iter()
.filter_map(|clause| {
let predicate = clause let predicate = clause
.kind() .kind()
.map_bound(|clause| match clause { .map_bound(|clause| match clause {
@ -1776,7 +1774,8 @@ impl<'tcx, 'exprs, E: AsCoercionSite> CoerceMany<'tcx, 'exprs, E> {
fcx.param_env, fcx.param_env,
predicate, predicate,
)) ))
}), },
),
); );
ocx.select_where_possible().is_empty() ocx.select_where_possible().is_empty()
}) })

View File

@ -76,9 +76,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
// For every projection predicate in the opaque type's explicit bounds, // For every projection predicate in the opaque type's explicit bounds,
// check that the type that we're assigning actually satisfies the bounds // check that the type that we're assigning actually satisfies the bounds
// of the associated type. // of the associated type.
for (pred, pred_span) in for (pred, pred_span) in cx.tcx.explicit_item_bounds(def_id).iter_identity_copied() {
cx.tcx.explicit_item_bounds(def_id).instantiate_identity_iter_copied()
{
infcx.enter_forall(pred.kind(), |predicate| { infcx.enter_forall(pred.kind(), |predicate| {
let ty::ClauseKind::Projection(proj) = predicate else { let ty::ClauseKind::Projection(proj) = predicate else {
return; return;

View File

@ -298,9 +298,7 @@ impl<'tcx> LateLintPass<'tcx> for UnusedResults {
ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => { ty::Alias(ty::Opaque | ty::Projection, ty::AliasTy { def_id: def, .. }) => {
elaborate( elaborate(
cx.tcx, cx.tcx,
cx.tcx cx.tcx.explicit_item_super_predicates(def).iter_identity_copied(),
.explicit_item_super_predicates(def)
.instantiate_identity_iter_copied(),
) )
// We only care about self bounds for the impl-trait // We only care about self bounds for the impl-trait
.filter_only_self() .filter_only_self()

View File

@ -394,7 +394,7 @@ impl<'tcx> GenericPredicates<'tcx> {
} }
pub fn instantiate_own_identity(&self) -> impl Iterator<Item = (Clause<'tcx>, Span)> { pub fn instantiate_own_identity(&self) -> impl Iterator<Item = (Clause<'tcx>, Span)> {
EarlyBinder::bind(self.predicates).instantiate_identity_iter_copied() EarlyBinder::bind(self.predicates).iter_identity_copied()
} }
#[instrument(level = "debug", skip(self, tcx))] #[instrument(level = "debug", skip(self, tcx))]

View File

@ -203,7 +203,7 @@ fn bounds_reference_self(tcx: TyCtxt<'_>, trait_def_id: DefId) -> SmallVec<[Span
tcx.associated_items(trait_def_id) tcx.associated_items(trait_def_id)
.in_definition_order() .in_definition_order()
.filter(|item| item.kind == ty::AssocKind::Type) .filter(|item| item.kind == ty::AssocKind::Type)
.flat_map(|item| tcx.explicit_item_bounds(item.def_id).instantiate_identity_iter_copied()) .flat_map(|item| tcx.explicit_item_bounds(item.def_id).iter_identity_copied())
.filter_map(|c| predicate_references_self(tcx, c)) .filter_map(|c| predicate_references_self(tcx, c))
.collect() .collect()
} }

View File

@ -169,10 +169,8 @@ impl<'tcx> OpaqueTypeCollector<'tcx> {
// Collect opaque types nested within the associated type bounds of this opaque type. // Collect opaque types nested within the associated type bounds of this opaque type.
// We use identity args here, because we already know that the opaque type uses // We use identity args here, because we already know that the opaque type uses
// only generic parameters, and thus instantiating would not give us more information. // only generic parameters, and thus instantiating would not give us more information.
for (pred, span) in self for (pred, span) in
.tcx self.tcx.explicit_item_bounds(alias_ty.def_id).iter_identity_copied()
.explicit_item_bounds(alias_ty.def_id)
.instantiate_identity_iter_copied()
{ {
trace!(?pred); trace!(?pred);
self.visit_spanned(span, pred); self.visit_spanned(span, pred);

View File

@ -62,7 +62,7 @@ pub fn walk_types<'tcx, V: SpannedTypeVisitor<'tcx>>(
} }
} }
DefKind::OpaqueTy => { DefKind::OpaqueTy => {
for (pred, span) in tcx.explicit_item_bounds(item).instantiate_identity_iter_copied() { for (pred, span) in tcx.explicit_item_bounds(item).iter_identity_copied() {
try_visit!(visitor.visit(span, pred)); try_visit!(visitor.visit(span, pred));
} }
} }

View File

@ -448,7 +448,7 @@ where
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity), /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
/// but on an iterator of `TypeFoldable` values. /// but on an iterator of `TypeFoldable` values.
pub fn instantiate_identity_iter(self) -> Iter::IntoIter { pub fn iter_identity(self) -> Iter::IntoIter {
self.value.into_iter() self.value.into_iter()
} }
} }
@ -515,9 +515,7 @@ where
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity), /// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
/// but on an iterator of values that deref to a `TypeFoldable`. /// but on an iterator of values that deref to a `TypeFoldable`.
pub fn instantiate_identity_iter_copied( pub fn iter_identity_copied(self) -> impl Iterator<Item = <Iter::Item as Deref>::Target> {
self,
) -> impl Iterator<Item = <Iter::Item as Deref>::Target> {
self.value.into_iter().map(|v| *v) self.value.into_iter().map(|v| *v)
} }
} }

View File

@ -1404,8 +1404,7 @@ pub(crate) fn clean_middle_assoc_item<'tcx>(
let mut predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates; let mut predicates = tcx.explicit_predicates_of(assoc_item.def_id).predicates;
if let ty::TraitContainer = assoc_item.container { if let ty::TraitContainer = assoc_item.container {
let bounds = let bounds = tcx.explicit_item_bounds(assoc_item.def_id).iter_identity_copied();
tcx.explicit_item_bounds(assoc_item.def_id).instantiate_identity_iter_copied();
predicates = tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied())); predicates = tcx.arena.alloc_from_iter(bounds.chain(predicates.iter().copied()));
} }
let mut generics = clean_ty_generics( let mut generics = clean_ty_generics(

View File

@ -99,7 +99,7 @@ pub fn contains_ty_adt_constructor_opaque<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'
for (predicate, _span) in cx for (predicate, _span) in cx
.tcx .tcx
.explicit_item_super_predicates(def_id) .explicit_item_super_predicates(def_id)
.instantiate_identity_iter_copied() .iter_identity_copied()
{ {
match predicate.kind().skip_binder() { match predicate.kind().skip_binder() {
// For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through // For `impl Trait<U>`, it will register a predicate of `T: Trait<U>`, so we go through