Skip to content

Commit 6b9236e

Browse files
committed
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`
2 parents ec362f0 + 05f6890 commit 6b9236e

File tree

20 files changed

+47
-40
lines changed

20 files changed

+47
-40
lines changed

compiler/rustc_borrowck/src/diagnostics/conflict_errors.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ impl<'cx, 'tcx> MirBorrowckCtxt<'cx, 'tcx> {
695695
.find_map(find_fn_kind_from_did),
696696
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => tcx
697697
.explicit_item_bounds(def_id)
698-
.arg_iter_copied(tcx, args)
698+
.iter_instantiated_copied(tcx, args)
699699
.find_map(|(clause, span)| find_fn_kind_from_did((clause, span))),
700700
ty::Closure(_, args) => match args.as_closure().kind() {
701701
ty::ClosureKind::Fn => Some(hir::Mutability::Not),

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -867,7 +867,7 @@ impl<'tcx> TypeFolder<TyCtxt<'tcx>> for ImplTraitInTraitCollector<'_, 'tcx> {
867867
});
868868
self.types.insert(proj.def_id, (infer_ty, proj.args));
869869
// Recurse into bounds
870-
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).arg_iter_copied(self.interner(), proj.args) {
870+
for (pred, pred_span) in self.interner().explicit_item_bounds(proj.def_id).iter_instantiated_copied(self.interner(), proj.args) {
871871
let pred = pred.fold_with(self);
872872
let pred = self.ocx.normalize(
873873
&ObligationCause::misc(self.span, self.body_id),
@@ -2149,7 +2149,7 @@ pub(super) fn check_type_bounds<'tcx>(
21492149

21502150
let obligations: Vec<_> = tcx
21512151
.explicit_item_bounds(trait_ty.def_id)
2152-
.arg_iter_copied(tcx, rebased_args)
2152+
.iter_instantiated_copied(tcx, rebased_args)
21532153
.map(|(concrete_ty_bound, span)| {
21542154
debug!("check_type_bounds: concrete_ty_bound = {:?}", concrete_ty_bound);
21552155
traits::Obligation::new(tcx, mk_cause(span), param_env, concrete_ty_bound)

compiler/rustc_hir_analysis/src/check/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -409,7 +409,7 @@ fn fn_sig_suggestion<'tcx>(
409409
let asyncness = if tcx.asyncness(assoc.def_id).is_async() {
410410
output = if let ty::Alias(_, alias_ty) = *output.kind() {
411411
tcx.explicit_item_bounds(alias_ty.def_id)
412-
.arg_iter_copied(tcx, alias_ty.args)
412+
.iter_instantiated_copied(tcx, alias_ty.args)
413413
.find_map(|(bound, _)| bound.as_projection_clause()?.no_bound_vars()?.term.ty())
414414
.unwrap_or_else(|| {
415415
span_bug!(

compiler/rustc_hir_analysis/src/check/wfcheck.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -1567,7 +1567,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
15671567
});
15681568
for (bound, bound_span) in tcx
15691569
.explicit_item_bounds(opaque_ty.def_id)
1570-
.arg_iter_copied(tcx, opaque_ty.args)
1570+
.iter_instantiated_copied(tcx, opaque_ty.args)
15711571
{
15721572
let bound = self.wfcx.normalize(bound_span, None, bound);
15731573
self.wfcx.register_obligations(traits::wf::predicate_obligations(

compiler/rustc_hir_analysis/src/variance/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -145,7 +145,7 @@ fn variance_of_opaque(tcx: TyCtxt<'_>, item_def_id: LocalDefId) -> &[ty::Varianc
145145
let mut collector =
146146
OpaqueTypeLifetimeCollector { tcx, root_def_id: item_def_id.to_def_id(), variances };
147147
let id_args = ty::GenericArgs::identity_for_item(tcx, item_def_id);
148-
for (pred, _) in tcx.explicit_item_bounds(item_def_id).arg_iter_copied(tcx, id_args) {
148+
for (pred, _) in tcx.explicit_item_bounds(item_def_id).iter_instantiated_copied(tcx, id_args) {
149149
debug!(?pred);
150150

151151
// We only ignore opaque type args if the opaque type is the outermost type.

compiler/rustc_hir_typeck/src/_match.rs

+4-2
Original file line numberDiff line numberDiff line change
@@ -551,8 +551,10 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
551551
}
552552

553553
for ty in [first_ty, second_ty] {
554-
for (clause, _) in
555-
self.tcx.explicit_item_bounds(rpit_def_id).arg_iter_copied(self.tcx, args)
554+
for (clause, _) in self
555+
.tcx
556+
.explicit_item_bounds(rpit_def_id)
557+
.iter_instantiated_copied(self.tcx, args)
556558
{
557559
let pred = clause.kind().rebind(match clause.kind().skip_binder() {
558560
ty::ClauseKind::Trait(trait_pred) => {

compiler/rustc_hir_typeck/src/closure.rs

+3-3
Original file line numberDiff line numberDiff line change
@@ -177,7 +177,7 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
177177
expected_ty,
178178
self.tcx
179179
.explicit_item_bounds(def_id)
180-
.arg_iter_copied(self.tcx, args)
180+
.iter_instantiated_copied(self.tcx, args)
181181
.map(|(c, s)| (c.as_predicate(), s)),
182182
),
183183
ty::Dynamic(ref object_type, ..) => {
@@ -720,13 +720,13 @@ impl<'a, 'tcx> FnCtxt<'a, 'tcx> {
720720
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => self
721721
.tcx
722722
.explicit_item_bounds(def_id)
723-
.arg_iter_copied(self.tcx, args)
723+
.iter_instantiated_copied(self.tcx, args)
724724
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
725725
ty::Error(_) => return None,
726726
ty::Alias(ty::Projection, proj) if self.tcx.is_impl_trait_in_trait(proj.def_id) => self
727727
.tcx
728728
.explicit_item_bounds(proj.def_id)
729-
.arg_iter_copied(self.tcx, proj.args)
729+
.iter_instantiated_copied(self.tcx, proj.args)
730730
.find_map(|(p, s)| get_future_output(p.as_predicate(), s))?,
731731
_ => span_bug!(
732732
self.tcx.def_span(expr_def_id),

compiler/rustc_infer/src/infer/error_reporting/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -403,7 +403,7 @@ impl<'tcx> InferCtxt<'tcx> {
403403
let future_trait = self.tcx.require_lang_item(LangItem::Future, None);
404404
let item_def_id = self.tcx.associated_item_def_ids(future_trait)[0];
405405

406-
self.tcx.explicit_item_bounds(def_id).arg_iter_copied(self.tcx, args).find_map(
406+
self.tcx.explicit_item_bounds(def_id).iter_instantiated_copied(self.tcx, args).find_map(
407407
|(predicate, _)| {
408408
predicate
409409
.kind()

compiler/rustc_infer/src/infer/opaque_types.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -591,7 +591,7 @@ impl<'tcx> InferCtxt<'tcx> {
591591
let tcx = self.tcx;
592592
let item_bounds = tcx.explicit_item_bounds(def_id);
593593

594-
for (predicate, _) in item_bounds.arg_iter_copied(tcx, args) {
594+
for (predicate, _) in item_bounds.iter_instantiated_copied(tcx, args) {
595595
let predicate = predicate.fold_with(&mut BottomUpFolder {
596596
tcx,
597597
ty_op: |ty| match *ty.kind() {

compiler/rustc_infer/src/infer/outlives/verify.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -295,7 +295,7 @@ impl<'cx, 'tcx> VerifyBoundCx<'cx, 'tcx> {
295295
let bounds = tcx.item_bounds(alias_ty.def_id);
296296
trace!("{:#?}", bounds.skip_binder());
297297
bounds
298-
.arg_iter(tcx, alias_ty.args)
298+
.iter_instantiated(tcx, alias_ty.args)
299299
.filter_map(|p| p.as_type_outlives_clause())
300300
.filter_map(|p| p.no_bound_vars())
301301
.map(|OutlivesPredicate(_, r)| r)

compiler/rustc_lint/src/opaque_hidden_inferred_bound.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -117,7 +117,7 @@ impl<'tcx> LateLintPass<'tcx> for OpaqueHiddenInferredBound {
117117
for (assoc_pred, assoc_pred_span) in cx
118118
.tcx
119119
.explicit_item_bounds(proj.projection_ty.def_id)
120-
.arg_iter_copied(cx.tcx, &proj.projection_ty.args)
120+
.iter_instantiated_copied(cx.tcx, &proj.projection_ty.args)
121121
{
122122
let assoc_pred = assoc_pred.fold_with(proj_replacer);
123123
let Ok(assoc_pred) = traits::fully_normalize(

compiler/rustc_middle/src/ty/generic_args.rs

+17-13
Original file line numberDiff line numberDiff line change
@@ -610,8 +610,12 @@ impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>
610610
where
611611
I::Item: TypeFoldable<TyCtxt<'tcx>>,
612612
{
613-
pub fn arg_iter(self, tcx: TyCtxt<'tcx>, args: &'s [GenericArg<'tcx>]) -> ArgIter<'s, 'tcx, I> {
614-
ArgIter { it: self.value.into_iter(), tcx, args }
613+
pub fn iter_instantiated(
614+
self,
615+
tcx: TyCtxt<'tcx>,
616+
args: &'s [GenericArg<'tcx>],
617+
) -> IterInstantiated<'s, 'tcx, I> {
618+
IterInstantiated { it: self.value.into_iter(), tcx, args }
615619
}
616620

617621
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
@@ -621,13 +625,13 @@ where
621625
}
622626
}
623627

624-
pub struct ArgIter<'s, 'tcx, I: IntoIterator> {
628+
pub struct IterInstantiated<'s, 'tcx, I: IntoIterator> {
625629
it: I::IntoIter,
626630
tcx: TyCtxt<'tcx>,
627631
args: &'s [GenericArg<'tcx>],
628632
}
629633

630-
impl<'tcx, I: IntoIterator> Iterator for ArgIter<'_, 'tcx, I>
634+
impl<'tcx, I: IntoIterator> Iterator for IterInstantiated<'_, 'tcx, I>
631635
where
632636
I::Item: TypeFoldable<TyCtxt<'tcx>>,
633637
{
@@ -642,7 +646,7 @@ where
642646
}
643647
}
644648

645-
impl<'tcx, I: IntoIterator> DoubleEndedIterator for ArgIter<'_, 'tcx, I>
649+
impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiated<'_, 'tcx, I>
646650
where
647651
I::IntoIter: DoubleEndedIterator,
648652
I::Item: TypeFoldable<TyCtxt<'tcx>>,
@@ -652,7 +656,7 @@ where
652656
}
653657
}
654658

655-
impl<'tcx, I: IntoIterator> ExactSizeIterator for ArgIter<'_, 'tcx, I>
659+
impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiated<'_, 'tcx, I>
656660
where
657661
I::IntoIter: ExactSizeIterator,
658662
I::Item: TypeFoldable<TyCtxt<'tcx>>,
@@ -664,12 +668,12 @@ where
664668
I::Item: Deref,
665669
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
666670
{
667-
pub fn arg_iter_copied(
671+
pub fn iter_instantiated_copied(
668672
self,
669673
tcx: TyCtxt<'tcx>,
670674
args: &'s [GenericArg<'tcx>],
671-
) -> ArgIterCopied<'s, 'tcx, I> {
672-
ArgIterCopied { it: self.value.into_iter(), tcx, args }
675+
) -> IterInstantiatedCopied<'s, 'tcx, I> {
676+
IterInstantiatedCopied { it: self.value.into_iter(), tcx, args }
673677
}
674678

675679
/// Similar to [`instantiate_identity`](EarlyBinder::instantiate_identity),
@@ -681,13 +685,13 @@ where
681685
}
682686
}
683687

684-
pub struct ArgIterCopied<'a, 'tcx, I: IntoIterator> {
688+
pub struct IterInstantiatedCopied<'a, 'tcx, I: IntoIterator> {
685689
it: I::IntoIter,
686690
tcx: TyCtxt<'tcx>,
687691
args: &'a [GenericArg<'tcx>],
688692
}
689693

690-
impl<'tcx, I: IntoIterator> Iterator for ArgIterCopied<'_, 'tcx, I>
694+
impl<'tcx, I: IntoIterator> Iterator for IterInstantiatedCopied<'_, 'tcx, I>
691695
where
692696
I::Item: Deref,
693697
<I::Item as Deref>::Target: Copy + TypeFoldable<TyCtxt<'tcx>>,
@@ -703,7 +707,7 @@ where
703707
}
704708
}
705709

706-
impl<'tcx, I: IntoIterator> DoubleEndedIterator for ArgIterCopied<'_, 'tcx, I>
710+
impl<'tcx, I: IntoIterator> DoubleEndedIterator for IterInstantiatedCopied<'_, 'tcx, I>
707711
where
708712
I::IntoIter: DoubleEndedIterator,
709713
I::Item: Deref,
@@ -716,7 +720,7 @@ where
716720
}
717721
}
718722

719-
impl<'tcx, I: IntoIterator> ExactSizeIterator for ArgIterCopied<'_, 'tcx, I>
723+
impl<'tcx, I: IntoIterator> ExactSizeIterator for IterInstantiatedCopied<'_, 'tcx, I>
720724
where
721725
I::IntoIter: ExactSizeIterator,
722726
I::Item: Deref,

compiler/rustc_middle/src/ty/generics.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -347,7 +347,7 @@ impl<'tcx> GenericPredicates<'tcx> {
347347
tcx: TyCtxt<'tcx>,
348348
args: GenericArgsRef<'tcx>,
349349
) -> impl Iterator<Item = (Clause<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator {
350-
EarlyBinder::bind(self.predicates).arg_iter_copied(tcx, args)
350+
EarlyBinder::bind(self.predicates).iter_instantiated_copied(tcx, args)
351351
}
352352

353353
#[instrument(level = "debug", skip(self, tcx))]

compiler/rustc_middle/src/ty/print/pretty.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -928,7 +928,7 @@ pub trait PrettyPrinter<'tcx>:
928928
let mut is_sized = false;
929929
let mut lifetimes = SmallVec::<[ty::Region<'tcx>; 1]>::new();
930930

931-
for (predicate, _) in bounds.arg_iter_copied(tcx, args) {
931+
for (predicate, _) in bounds.iter_instantiated_copied(tcx, args) {
932932
let bound_predicate = predicate.kind();
933933

934934
match bound_predicate.skip_binder() {

compiler/rustc_trait_selection/src/solve/assembly/structural_traits.rs

+3-2
Original file line numberDiff line numberDiff line change
@@ -148,7 +148,7 @@ pub(in crate::solve) fn instantiate_constituent_tys_for_sized_trait<'tcx>(
148148

149149
ty::Adt(def, args) => {
150150
let sized_crit = def.sized_constraint(ecx.tcx());
151-
Ok(sized_crit.arg_iter_copied(ecx.tcx(), args).collect())
151+
Ok(sized_crit.iter_instantiated_copied(ecx.tcx(), args).collect())
152152
}
153153
}
154154
}
@@ -353,7 +353,8 @@ pub(in crate::solve) fn predicates_for_object_candidate<'tcx>(
353353
// FIXME(associated_const_equality): Also add associated consts to
354354
// the requirements here.
355355
if item.kind == ty::AssocKind::Type {
356-
requirements.extend(tcx.item_bounds(item.def_id).arg_iter(tcx, trait_ref.args));
356+
requirements
357+
.extend(tcx.item_bounds(item.def_id).iter_instantiated(tcx, trait_ref.args));
357358
}
358359
}
359360

compiler/rustc_trait_selection/src/traits/select/mod.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -2133,7 +2133,7 @@ impl<'tcx> SelectionContext<'_, 'tcx> {
21332133
Where(
21342134
obligation
21352135
.predicate
2136-
.rebind(sized_crit.arg_iter_copied(self.tcx(), args).collect()),
2136+
.rebind(sized_crit.iter_instantiated_copied(self.tcx(), args).collect()),
21372137
)
21382138
}
21392139

compiler/rustc_ty_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ fn sized_constraint_for_ty<'tcx>(
4242
let adt_tys = adt.sized_constraint(tcx);
4343
debug!("sized_constraint_for_ty({:?}) intermediate = {:?}", ty, adt_tys);
4444
adt_tys
45-
.arg_iter_copied(tcx, args)
45+
.iter_instantiated_copied(tcx, args)
4646
.flat_map(|ty| sized_constraint_for_ty(tcx, adtdef, ty))
4747
.collect()
4848
}
@@ -297,7 +297,7 @@ impl<'tcx> TypeVisitor<TyCtxt<'tcx>> for ImplTraitInTraitFinder<'_, 'tcx> {
297297
for bound in self
298298
.tcx
299299
.item_bounds(unshifted_alias_ty.def_id)
300-
.arg_iter(self.tcx, unshifted_alias_ty.args)
300+
.iter_instantiated(self.tcx, unshifted_alias_ty.args)
301301
{
302302
bound.visit_with(self);
303303
}

src/librustdoc/clean/mod.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -441,7 +441,7 @@ fn clean_projection<'tcx>(
441441
let bounds = cx
442442
.tcx
443443
.explicit_item_bounds(ty.skip_binder().def_id)
444-
.arg_iter_copied(cx.tcx, ty.skip_binder().args)
444+
.iter_instantiated_copied(cx.tcx, ty.skip_binder().args)
445445
.map(|(pred, _)| pred)
446446
.collect::<Vec<_>>();
447447
return clean_middle_opaque_bounds(cx, bounds);
@@ -2071,7 +2071,7 @@ pub(crate) fn clean_middle_ty<'tcx>(
20712071
let bounds = cx
20722072
.tcx
20732073
.explicit_item_bounds(def_id)
2074-
.arg_iter_copied(cx.tcx, args)
2074+
.iter_instantiated_copied(cx.tcx, args)
20752075
.map(|(bound, _)| bound)
20762076
.collect::<Vec<_>>();
20772077
let ty = clean_middle_opaque_bounds(cx, bounds);

src/tools/clippy/clippy_lints/src/future_not_send.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,7 @@ impl<'tcx> LateLintPass<'tcx> for FutureNotSend {
6666
if let ty::Alias(ty::Opaque, AliasTy { def_id, args, .. }) = *ret_ty.kind() {
6767
let preds = cx.tcx.explicit_item_bounds(def_id);
6868
let mut is_future = false;
69-
for (p, _span) in preds.arg_iter_copied(cx.tcx, args) {
69+
for (p, _span) in preds.iter_instantiated_copied(cx.tcx, args) {
7070
if let Some(trait_pred) = p.as_trait_clause() {
7171
if Some(trait_pred.skip_binder().trait_ref.def_id) == cx.tcx.lang_items().future_trait() {
7272
is_future = true;

src/tools/clippy/clippy_utils/src/ty.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -663,7 +663,7 @@ pub fn ty_sig<'tcx>(cx: &LateContext<'tcx>, ty: Ty<'tcx>) -> Option<ExprFnSig<'t
663663
ty::Alias(ty::Opaque, ty::AliasTy { def_id, args, .. }) => sig_from_bounds(
664664
cx,
665665
ty,
666-
cx.tcx.item_bounds(def_id).arg_iter(cx.tcx, args),
666+
cx.tcx.item_bounds(def_id).iter_instantiated(cx.tcx, args),
667667
cx.tcx.opt_parent(def_id),
668668
),
669669
ty::FnPtr(sig) => Some(ExprFnSig::Sig(sig, None)),
@@ -739,7 +739,7 @@ fn sig_for_projection<'tcx>(cx: &LateContext<'tcx>, ty: AliasTy<'tcx>) -> Option
739739
let mut output = None;
740740
let lang_items = cx.tcx.lang_items();
741741

742-
for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).arg_iter_copied(cx.tcx, ty.args) {
742+
for (pred, _) in cx.tcx.explicit_item_bounds(ty.def_id).iter_instantiated_copied(cx.tcx, ty.args) {
743743
match pred.kind().skip_binder() {
744744
ty::ClauseKind::Trait(p)
745745
if (lang_items.fn_trait() == Some(p.def_id())

0 commit comments

Comments
 (0)