Auto merge of #113801 - compiler-errors:iter-instantiated, r=oli-obk

Rename `arg_iter` to `iter_instantiated`

`arg_iter` doesn't make sense, and doesn't really indicate what it's doing (returning an iterator that ~~substitutes~~ instantiates its elements).

`iter_instantiated_copied` is kinda awkward but i don't really wanna bikeshed it.

r? `@oli-obk`
This commit is contained in:
bors 2023-07-18 05:33:23 +00:00
commit 6b9236ed5a
20 changed files with 47 additions and 40 deletions

View File

@ -695,7 +695,7 @@ fn suggest_borrow_fn_like(
.find_map(find_fn_kind_from_did),
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
.explicit_item_bounds(def_id)
.arg_iter_copied(tcx, args)
.iter_instantiated_copied(tcx, args)
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
ty::Closure(_, args) => match args.as_closure().kind() {
ty::ClosureKind::Fn => Some(hir::Mutability::Not),

View File

@ -867,7 +867,7 @@ fn fold_ty(&mut self, ty: Ty<'tcx>) -> Ty<'tcx> {
});
self.types.insert(proj.def_id, (infer_ty, proj.args));
// Recurse into bounds
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).arg_iter_copied(self.interner(), proj.args) {
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).iter_instantiated_copied(self.interner(), proj.args) {
let pred = pred.fold_with(self);
let pred = self.ocx.normalize(
&ObligationCause::misc(self.span, self.body_id),
@ -2149,7 +2149,7 @@ pub(super) fn check_type_bounds<'tcx>(
let obligations: Vec<_> = tcx
.explicit_item_bounds(trait_ty.def_id)
.arg_iter_copied(tcx, rebased_args)
.iter_instantiated_copied(tcx, rebased_args)
.map(|(concrete_ty_bound, span)| {
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)

View File

@ -409,7 +409,7 @@ fn fn_sig_suggestion<'tcx>(
let asyncness = if tcx.asyncness(assoc.def_id).is_async() {
output = if let ty::Alias(_, alias_ty) = *output.kind() {
tcx.explicit_item_bounds(alias_ty.def_id)
.arg_iter_copied(tcx, alias_ty.args)
.iter_instantiated_copied(tcx, alias_ty.args)
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
.unwrap_or_else(|| {
span_bug!(

View File

@ -1567,7 +1567,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> ControlFlow<!> {
});
for (bound, bound_span) in tcx
.explicit_item_bounds(opaque_ty.def_id)
.arg_iter_copied(tcx, opaque_ty.args)
.iter_instantiated_copied(tcx, opaque_ty.args)
{
let bound = self.wfcx.normalize(bound_span, None, bound);
self.wfcx.register_obligations(traits::wf::predicate_obligations(

View File

@ -145,7 +145,7 @@ fn visit_ty(&mut self, t: Ty<'tcx>) -> ControlFlow<Self::BreakTy> {
let mut collector =
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
let id_args = ty::GenericArgs::identity_for_item(tcx, item_def_id);
for (pred, _) in tcx.explicit_item_bounds(item_def_id).arg_iter_copied(tcx, id_args) {
for (pred, _) in tcx.explicit_item_bounds(item_def_id).iter_instantiated_copied(tcx, id_args) {
debug!(?pred);
// We only ignore opaque type args if the opaque type is the outermost type.

View File

@ -551,8 +551,10 @@ pub(crate) fn opt_suggest_box_span(
}
for ty in [first_ty, second_ty] {
for (clause, _) in
self.tcx.explicit_item_bounds(rpit_def_id).arg_iter_copied(self.tcx, args)
for (clause, _) in self
.tcx
.explicit_item_bounds(rpit_def_id)
.iter_instantiated_copied(self.tcx, args)
{
let pred = clause.kind().rebind(match clause.kind().skip_binder() {
ty::ClauseKind::Trait(trait_pred) => {

View File

@ -177,7 +177,7 @@ fn deduce_closure_signature(
expected_ty,
self.tcx
.explicit_item_bounds(def_id)
.arg_iter_copied(self.tcx, args)
.iter_instantiated_copied(self.tcx, args)
.map(|(c, s)| (c.as_predicate(), s)),
),
ty::Dynamic(ref object_type, ..) => {
@ -720,13 +720,13 @@ fn deduce_future_output_from_obligations(
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self
.tcx
.explicit_item_bounds(def_id)
.arg_iter_copied(self.tcx, args)
.iter_instantiated_copied(self.tcx, args)
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
ty::Error(_) => return None,
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
.tcx
.explicit_item_bounds(proj.def_id)
.arg_iter_copied(self.tcx, proj.args)
.iter_instantiated_copied(self.tcx, proj.args)
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
_ => span_bug!(
self.tcx.def_span(expr_def_id),

View File

@ -403,7 +403,7 @@ pub fn get_impl_future_output_ty(&self, ty: Ty<'tcx>) -> Option<Ty<'tcx>> {
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
self.tcx.explicit_item_bounds(def_id).arg_iter_copied(self.tcx, args).find_map(
self.tcx.explicit_item_bounds(def_id).iter_instantiated_copied(self.tcx, args).find_map(
|(predicate, _)| {
predicate
.kind()

View File

@ -591,7 +591,7 @@ pub fn add_item_bounds_for_hidden_type(
let tcx = self.tcx;
let item_bounds = tcx.explicit_item_bounds(def_id);
for (predicate, _) in item_bounds.arg_iter_copied(tcx, args) {
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
let predicate = predicate.fold_with(&mut BottomUpFolder {
tcx,
ty_op: |ty| match *ty.kind() {

View File

@ -295,7 +295,7 @@ pub fn declared_bounds_from_definition(
let bounds = tcx.item_bounds(alias_ty.def_id);
trace!("{:#?}", bounds.skip_binder());
bounds
.arg_iter(tcx, alias_ty.args)
.iter_instantiated(tcx, alias_ty.args)
.filter_map(|p| p.as_type_outlives_clause())
.filter_map(|p| p.no_bound_vars())
.map(|OutlivesPredicate(_, r)| r)

View File

@ -117,7 +117,7 @@ fn check_item(&mut self, cx: &LateContext<'tcx>, item: &'tcx hir::Item<'tcx>) {
for (assoc_pred, assoc_pred_span) in cx
.tcx
.explicit_item_bounds(proj.projection_ty.def_id)
.arg_iter_copied(cx.tcx, &proj.projection_ty.args)
.iter_instantiated_copied(cx.tcx, &proj.projection_ty.args)
{
let assoc_pred = assoc_pred.fold_with(proj_replacer);
let Ok(assoc_pred) = traits::fully_normalize(

View File

@ -610,8 +610,12 @@ impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>
where
I::Item: TypeFoldable<TyCtxt<'tcx>>,
{
pub fn arg_iter(self, tcx: TyCtxt<'tcx>, args: &'s [GenericArg<'tcx>]) -> ArgIter<'s, 'tcx, I> {
ArgIter { it: self.value.into_iter(), tcx, args }
pub fn iter_instantiated(
self,
tcx: TyCtxt<'tcx>,
args: &'s [GenericArg<'tcx>],
) -> IterInstantiated<'s, 'tcx, I> {
IterInstantiated { it: self.value.into_iter(), tcx, args }
}
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
@ -621,13 +625,13 @@ pub fn instantiate_identity_iter(self) -> I::IntoIter {
}
}
pub struct ArgIter<'s, 'tcx, I: IntoIterator> {
pub struct IterInstantiated<'s, 'tcx, I: IntoIterator> {
it: I::IntoIter,
tcx: TyCtxt<'tcx>,
args: &'s [GenericArg<'tcx>],
}
impl<'tcx, I: IntoIterator> Iterator for ArgIter<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> Iterator for IterInstantiated<'_, 'tcx, I>
where
I::Item: TypeFoldable<TyCtxt<'tcx>>,
{
@ -642,7 +646,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
impl<'tcx, I: IntoIterator> DoubleEndedIterator for ArgIter<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiated<'_, 'tcx, I>
where
I::IntoIter: DoubleEndedIterator,
I::Item: TypeFoldable<TyCtxt<'tcx>>,
@ -652,7 +656,7 @@ fn next_back(&mut self) -> Option<Self::Item> {
}
}
impl<'tcx, I: IntoIterator> ExactSizeIterator for ArgIter<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiated<'_, 'tcx, I>
where
I::IntoIter: ExactSizeIterator,
I::Item: TypeFoldable<TyCtxt<'tcx>>,
@ -664,12 +668,12 @@ impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>
I::Item: Deref,
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
{
pub fn arg_iter_copied(
pub fn iter_instantiated_copied(
self,
tcx: TyCtxt<'tcx>,
args: &'s [GenericArg<'tcx>],
) -> ArgIterCopied<'s, 'tcx, I> {
ArgIterCopied { it: self.value.into_iter(), tcx, args }
) -> IterInstantiatedCopied<'s, 'tcx, I> {
IterInstantiatedCopied { it: self.value.into_iter(), tcx, args }
}
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
@ -681,13 +685,13 @@ pub fn instantiate_identity_iter_copied(
}
}
pub struct ArgIterCopied<'a, 'tcx, I: IntoIterator> {
pub struct IterInstantiatedCopied<'a, 'tcx, I: IntoIterator> {
it: I::IntoIter,
tcx: TyCtxt<'tcx>,
args: &'a [GenericArg<'tcx>],
}
impl<'tcx, I: IntoIterator> Iterator for ArgIterCopied<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> Iterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::Item: Deref,
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
@ -703,7 +707,7 @@ fn size_hint(&self) -> (usize, Option<usize>) {
}
}
impl<'tcx, I: IntoIterator> DoubleEndedIterator for ArgIterCopied<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::IntoIter: DoubleEndedIterator,
I::Item: Deref,
@ -716,7 +720,7 @@ fn next_back(&mut self) -> Option<Self::Item> {
}
}
impl<'tcx, I: IntoIterator> ExactSizeIterator for ArgIterCopied<'_, 'tcx, I>
impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, 'tcx, I>
where
I::IntoIter: ExactSizeIterator,
I::Item: Deref,

View File

@ -347,7 +347,7 @@ pub fn instantiate_own(
tcx: TyCtxt<'tcx>,
args: GenericArgsRef<'tcx>,
) -> impl Iterator<Item = (Clause<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator {
EarlyBinder::bind(self.predicates).arg_iter_copied(tcx, args)
EarlyBinder::bind(self.predicates).iter_instantiated_copied(tcx, args)
}
#[instrument(level = "debug", skip(self, tcx))]

View File

@ -928,7 +928,7 @@ fn pretty_print_opaque_impl_type(
let mut is_sized = false;
let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new();
for (predicate, _) in bounds.arg_iter_copied(tcx, args) {
for (predicate, _) in bounds.iter_instantiated_copied(tcx, args) {
let bound_predicate = predicate.kind();
match bound_predicate.skip_binder() {

View File

@ -148,7 +148,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
ty::Adt(def, args) => {
let sized_crit = def.sized_constraint(ecx.tcx());
Ok(sized_crit.arg_iter_copied(ecx.tcx(), args).collect())
Ok(sized_crit.iter_instantiated_copied(ecx.tcx(), args).collect())
}
}
}
@ -353,7 +353,8 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
// FIXME(associated_const_equality): Also add associated consts to
// the requirements here.
if item.kind == ty::AssocKind::Type {
requirements.extend(tcx.item_bounds(item.def_id).arg_iter(tcx, trait_ref.args));
requirements
.extend(tcx.item_bounds(item.def_id).iter_instantiated(tcx, trait_ref.args));
}
}

View File

@ -2133,7 +2133,7 @@ fn sized_conditions(
Where(
obligation
.predicate
.rebind(sized_crit.arg_iter_copied(self.tcx(), args).collect()),
.rebind(sized_crit.iter_instantiated_copied(self.tcx(), args).collect()),
)
}

View File

@ -42,7 +42,7 @@ fn sized_constraint_for_ty<'tcx>(
let adt_tys = adt.sized_constraint(tcx);
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
adt_tys
.arg_iter_copied(tcx, args)
.iter_instantiated_copied(tcx, args)
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
.collect()
}
@ -297,7 +297,7 @@ fn visit_ty(&mut self, ty: Ty<'tcx>) -> std::ops::ControlFlow<Self::BreakTy> {
for bound in self
.tcx
.item_bounds(unshifted_alias_ty.def_id)
.arg_iter(self.tcx, unshifted_alias_ty.args)
.iter_instantiated(self.tcx, unshifted_alias_ty.args)
{
bound.visit_with(self);
}

View File

@ -441,7 +441,7 @@ fn clean_projection<'tcx>(
let bounds = cx
.tcx
.explicit_item_bounds(ty.skip_binder().def_id)
.arg_iter_copied(cx.tcx, ty.skip_binder().args)
.iter_instantiated_copied(cx.tcx, ty.skip_binder().args)
.map(|(pred, _)| pred)
.collect::<Vec<_>>();
return clean_middle_opaque_bounds(cx, bounds);
@ -2071,7 +2071,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
let bounds = cx
.tcx
.explicit_item_bounds(def_id)
.arg_iter_copied(cx.tcx, args)
.iter_instantiated_copied(cx.tcx, args)
.map(|(bound, _)| bound)
.collect::<Vec<_>>();
let ty = clean_middle_opaque_bounds(cx, bounds);

View File

@ -66,7 +66,7 @@ fn check_fn(
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() {
let preds = cx.tcx.explicit_item_bounds(def_id);
let mut is_future = false;
for (p, _span) in preds.arg_iter_copied(cx.tcx, args) {
for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) {
if let Some(trait_pred) = p.as_trait_clause() {
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
is_future = true;

View File

@ -663,7 +663,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => sig_from_bounds(
cx,
ty,
cx.tcx.item_bounds(def_id).arg_iter(cx.tcx, args),
cx.tcx.item_bounds(def_id).iter_instantiated(cx.tcx, args),
cx.tcx.opt_parent(def_id),
),
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
@ -739,7 +739,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
let mut output = None;
let lang_items = cx.tcx.lang_items();
for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).arg_iter_copied(cx.tcx, ty.args) {
for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).iter_instantiated_copied(cx.tcx, ty.args) {
match pred.kind().skip_binder() {
ty::ClauseKind::Trait(p)
if (lang_items.fn_trait() == Some(p.def_id())