Skip to content

Commit

Permalink
Auto merge of rust-lang#113801 - compiler-errors:iter-instantiated, r…
Browse files Browse the repository at this point in the history
…=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`
  • Loading branch information
bors committed Jul 18, 2023
2 parents ec362f0 + 05f6890 commit 6b9236e
Show file tree
Hide file tree
Showing 20 changed files with 47 additions and 40 deletions.
2 changes: 1 addition & 1 deletion compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs
Original file line number Diff line number Diff line change
Expand Up @@ -695,7 +695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
.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),
Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_hir_analysis/src/check/compare_impl_item.rs
Original file line number Diff line number Diff line change
Expand Up @@ -867,7 +867,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, '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),
Expand Down Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/check/wfcheck.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1567,7 +1567,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
});
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(
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_hir_analysis/src/variance/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
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.
Expand Down
6 changes: 4 additions & 2 deletions compiler/rustc_hir_typeck/src/_match.rs
Original file line number Diff line number Diff line change
Expand Up @@ -551,8 +551,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
}

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) => {
Expand Down
6 changes: 3 additions & 3 deletions compiler/rustc_hir_typeck/src/closure.rs
Original file line number Diff line number Diff line change
Expand Up @@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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, ..) => {
Expand Down Expand Up @@ -720,13 +720,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
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),
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/error_reporting/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -403,7 +403,7 @@ impl<'tcx> InferCtxt<'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()
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/opaque_types.rs
Original file line number Diff line number Diff line change
Expand Up @@ -591,7 +591,7 @@ impl<'tcx> InferCtxt<'tcx> {
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() {
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_infer/src/infer/outlives/verify.rs
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
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)
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
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(
Expand Down
30 changes: 17 additions & 13 deletions compiler/rustc_middle/src/ty/generic_args.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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),
Expand All @@ -621,13 +625,13 @@ where
}
}

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>>,
{
Expand All @@ -642,7 +646,7 @@ where
}
}

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>>,
Expand All @@ -652,7 +656,7 @@ where
}
}

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>>,
Expand All @@ -664,12 +668,12 @@ where
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),
Expand All @@ -681,13 +685,13 @@ where
}
}

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>>,
Expand All @@ -703,7 +707,7 @@ where
}
}

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,
Expand All @@ -716,7 +720,7 @@ where
}
}

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,
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/generics.rs
Original file line number Diff line number Diff line change
Expand Up @@ -347,7 +347,7 @@ impl<'tcx> GenericPredicates<'tcx> {
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))]
Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_middle/src/ty/print/pretty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -928,7 +928,7 @@ pub trait PrettyPrinter<'tcx>:
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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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())
}
}
}
Expand Down Expand Up @@ -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));
}
}

Expand Down
2 changes: 1 addition & 1 deletion compiler/rustc_trait_selection/src/traits/select/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -2133,7 +2133,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
Where(
obligation
.predicate
.rebind(sized_crit.arg_iter_copied(self.tcx(), args).collect()),
.rebind(sized_crit.iter_instantiated_copied(self.tcx(), args).collect()),
)
}

Expand Down
4 changes: 2 additions & 2 deletions compiler/rustc_ty_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down Expand Up @@ -297,7 +297,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
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);
}
Expand Down
4 changes: 2 additions & 2 deletions src/librustdoc/clean/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion src/tools/clippy/clippy_lints/src/future_not_send.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
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;
Expand Down
4 changes: 2 additions & 2 deletions src/tools/clippy/clippy_utils/src/ty.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)),
Expand Down Expand Up @@ -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())
Expand Down

0 comments on commit 6b9236e

Please sign in to comment.