Skip to content

Commit 91fd862

Browse files
instantiate_own doesn't need to return a pair of vectors
1 parent fc11ee0 commit 91fd862

File tree

6 files changed

+39
-27
lines changed

6 files changed

+39
-27
lines changed

compiler/rustc_hir_analysis/src/check/compare_impl_item.rs

+13-12
Original file line numberDiff line numberDiff line change
@@ -209,9 +209,11 @@ fn compare_method_predicate_entailment<'tcx>(
209209
//
210210
// We then register the obligations from the impl_m and check to see
211211
// if all constraints hold.
212-
hybrid_preds
213-
.predicates
214-
.extend(trait_m_predicates.instantiate_own(tcx, trait_to_placeholder_substs).predicates);
212+
hybrid_preds.predicates.extend(
213+
trait_m_predicates
214+
.instantiate_own(tcx, trait_to_placeholder_substs)
215+
.map(|(predicate, _)| predicate),
216+
);
215217

216218
// Construct trait parameter environment and then shift it into the placeholder viewpoint.
217219
// The key step here is to update the caller_bounds's predicates to be
@@ -230,7 +232,7 @@ fn compare_method_predicate_entailment<'tcx>(
230232
debug!("compare_impl_method: caller_bounds={:?}", param_env.caller_bounds());
231233

232234
let impl_m_own_bounds = impl_m_predicates.instantiate_own(tcx, impl_to_placeholder_substs);
233-
for (predicate, span) in iter::zip(impl_m_own_bounds.predicates, impl_m_own_bounds.spans) {
235+
for (predicate, span) in impl_m_own_bounds {
234236
let normalize_cause = traits::ObligationCause::misc(span, impl_m_hir_id);
235237
let predicate = ocx.normalize(&normalize_cause, param_env, predicate);
236238

@@ -1828,8 +1830,7 @@ fn compare_type_predicate_entailment<'tcx>(
18281830
check_region_bounds_on_impl_item(tcx, impl_ty, trait_ty, false)?;
18291831

18301832
let impl_ty_own_bounds = impl_ty_predicates.instantiate_own(tcx, impl_substs);
1831-
1832-
if impl_ty_own_bounds.is_empty() {
1833+
if impl_ty_own_bounds.len() == 0 {
18331834
// Nothing to check.
18341835
return Ok(());
18351836
}
@@ -1844,9 +1845,11 @@ fn compare_type_predicate_entailment<'tcx>(
18441845
// associated type in the trait are assumed.
18451846
let impl_predicates = tcx.predicates_of(impl_ty_predicates.parent.unwrap());
18461847
let mut hybrid_preds = impl_predicates.instantiate_identity(tcx);
1847-
hybrid_preds
1848-
.predicates
1849-
.extend(trait_ty_predicates.instantiate_own(tcx, trait_to_impl_substs).predicates);
1848+
hybrid_preds.predicates.extend(
1849+
trait_ty_predicates
1850+
.instantiate_own(tcx, trait_to_impl_substs)
1851+
.map(|(predicate, _)| predicate),
1852+
);
18501853

18511854
debug!("compare_type_predicate_entailment: bounds={:?}", hybrid_preds);
18521855

@@ -1862,9 +1865,7 @@ fn compare_type_predicate_entailment<'tcx>(
18621865

18631866
debug!("compare_type_predicate_entailment: caller_bounds={:?}", param_env.caller_bounds());
18641867

1865-
assert_eq!(impl_ty_own_bounds.predicates.len(), impl_ty_own_bounds.spans.len());
1866-
for (span, predicate) in std::iter::zip(impl_ty_own_bounds.spans, impl_ty_own_bounds.predicates)
1867-
{
1868+
for (predicate, span) in impl_ty_own_bounds {
18681869
let cause = ObligationCause::misc(span, impl_ty_hir_id);
18691870
let predicate = ocx.normalize(&cause, param_env, predicate);
18701871

compiler/rustc_middle/src/ty/generics.rs

+3-9
Original file line numberDiff line numberDiff line change
@@ -341,15 +341,9 @@ impl<'tcx> GenericPredicates<'tcx> {
341341
&self,
342342
tcx: TyCtxt<'tcx>,
343343
substs: SubstsRef<'tcx>,
344-
) -> InstantiatedPredicates<'tcx> {
345-
InstantiatedPredicates {
346-
predicates: self
347-
.predicates
348-
.iter()
349-
.map(|(p, _)| EarlyBinder(*p).subst(tcx, substs))
350-
.collect(),
351-
spans: self.predicates.iter().map(|(_, sp)| *sp).collect(),
352-
}
344+
) -> impl Iterator<Item = (Predicate<'tcx>, Span)> + DoubleEndedIterator + ExactSizeIterator
345+
{
346+
EarlyBinder(self.predicates).subst_iter_copied(tcx, substs)
353347
}
354348

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

compiler/rustc_middle/src/ty/subst.rs

+15
Original file line numberDiff line numberDiff line change
@@ -639,6 +639,13 @@ where
639639
}
640640
}
641641

642+
impl<'tcx, I: IntoIterator> ExactSizeIterator for SubstIter<'_, 'tcx, I>
643+
where
644+
I::IntoIter: ExactSizeIterator,
645+
I::Item: TypeFoldable<'tcx>,
646+
{
647+
}
648+
642649
impl<'tcx, 's, I: IntoIterator> EarlyBinder<I>
643650
where
644651
I::Item: Deref,
@@ -686,6 +693,14 @@ where
686693
}
687694
}
688695

696+
impl<'tcx, I: IntoIterator> ExactSizeIterator for SubstIterCopied<'_, 'tcx, I>
697+
where
698+
I::IntoIter: ExactSizeIterator,
699+
I::Item: Deref,
700+
<I::Item as Deref>::Target: Copy + TypeFoldable<'tcx>,
701+
{
702+
}
703+
689704
pub struct EarlyBinderIter<T> {
690705
t: T,
691706
}

compiler/rustc_trait_selection/src/traits/project.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -2303,10 +2303,10 @@ fn assoc_ty_own_obligations<'cx, 'tcx>(
23032303
nested: &mut Vec<PredicateObligation<'tcx>>,
23042304
) {
23052305
let tcx = selcx.tcx();
2306-
let own = tcx
2306+
let predicates = tcx
23072307
.predicates_of(obligation.predicate.def_id)
23082308
.instantiate_own(tcx, obligation.predicate.substs);
2309-
for (predicate, span) in std::iter::zip(own.predicates, own.spans) {
2309+
for (predicate, span) in predicates {
23102310
let normalized = normalize_with_depth_to(
23112311
selcx,
23122312
obligation.param_env,

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

+2-3
Original file line numberDiff line numberDiff line change
@@ -185,9 +185,8 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
185185
})?);
186186

187187
if let ty::Alias(ty::Projection, ..) = placeholder_self_ty.kind() {
188-
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs).predicates;
189-
debug!(?predicates, "projection predicates");
190-
for predicate in predicates {
188+
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
189+
for (predicate, _) in predicates {
191190
let normalized = normalize_with_depth_to(
192191
self,
193192
obligation.param_env,

compiler/rustc_trait_selection/src/traits/vtable.rs

+4-1
Original file line numberDiff line numberDiff line change
@@ -261,7 +261,10 @@ fn vtable_entries<'tcx>(
261261
// Note that this method could then never be called, so we
262262
// do not want to try and codegen it, in that case (see #23435).
263263
let predicates = tcx.predicates_of(def_id).instantiate_own(tcx, substs);
264-
if impossible_predicates(tcx, predicates.predicates) {
264+
if impossible_predicates(
265+
tcx,
266+
predicates.map(|(predicate, _)| predicate).collect(),
267+
) {
265268
debug!("vtable_entries: predicates do not hold");
266269
return VtblEntry::Vacant;
267270
}

0 commit comments

Comments
 (0)