Skip to content

Commit 6bf17d2

Browse files
committed
Instantiate all bound vars universally
1 parent cdb96be commit 6bf17d2

File tree

4 files changed

+36
-25
lines changed

4 files changed

+36
-25
lines changed

src/librustc/infer/higher_ranked/mod.rs

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
5353
// First, we instantiate each bound region in the supertype with a
5454
// fresh placeholder region.
5555
let (b_prime, placeholder_map) =
56-
self.infcx.replace_late_bound_regions_with_placeholders(b);
56+
self.infcx.replace_bound_vars_with_placeholders(b);
5757

5858
// Next, we instantiate each bound region in the subtype
5959
// with a fresh region variable. These region variables --
@@ -115,7 +115,7 @@ impl<'a, 'gcx, 'tcx> CombineFields<'a, 'gcx, 'tcx> {
115115
// First, we instantiate each bound region in the matcher
116116
// with a placeholder region.
117117
let ((a_match, a_value), placeholder_map) =
118-
self.infcx.replace_late_bound_regions_with_placeholders(a_pair);
118+
self.infcx.replace_bound_vars_with_placeholders(a_pair);
119119

120120
debug!("higher_ranked_match: a_match={:?}", a_match);
121121
debug!("higher_ranked_match: placeholder_map={:?}", placeholder_map);
@@ -314,10 +314,10 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
314314
region_vars
315315
}
316316

317-
/// Replace all regions bound by `binder` with placeholder regions and
318-
/// return a map indicating which bound-region was replaced with what
319-
/// placeholder region. This is the first step of checking subtyping
320-
/// when higher-ranked things are involved.
317+
/// Replace all regions (resp. types) bound by `binder` with placeholder
318+
/// regions (resp. types) and return a map indicating which bound-region
319+
/// was replaced with what placeholder region. This is the first step of
320+
/// checking subtyping when higher-ranked things are involved.
321321
///
322322
/// **Important:** you must call this function from within a snapshot.
323323
/// Moreover, before committing the snapshot, you must eventually call
@@ -330,26 +330,37 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
330330
/// the [rustc guide].
331331
///
332332
/// [rustc guide]: https://rust-lang-nursery.github.io/rustc-guide/traits/hrtb.html
333-
pub fn replace_late_bound_regions_with_placeholders<T>(
333+
pub fn replace_bound_vars_with_placeholders<T>(
334334
&self,
335-
binder: &ty::Binder<T>,
335+
binder: &ty::Binder<T>
336336
) -> (T, PlaceholderMap<'tcx>)
337337
where
338-
T : TypeFoldable<'tcx>,
338+
T: TypeFoldable<'tcx>
339339
{
340340
let next_universe = self.create_next_universe();
341341

342-
let (result, map) = self.tcx.replace_late_bound_regions(binder, |br| {
342+
let fld_r = |br| {
343343
self.tcx.mk_region(ty::RePlaceholder(ty::PlaceholderRegion {
344344
universe: next_universe,
345345
name: br,
346346
}))
347-
});
347+
};
348+
349+
let fld_t = |bound_ty: ty::BoundTy| {
350+
self.tcx.mk_ty(ty::Placeholder(ty::PlaceholderType {
351+
universe: next_universe,
352+
name: bound_ty.var,
353+
}))
354+
};
355+
356+
let (result, map) = self.tcx.replace_bound_vars(binder, fld_r, fld_t);
348357

349-
debug!("replace_late_bound_regions_with_placeholders(binder={:?}, result={:?}, map={:?})",
350-
binder,
351-
result,
352-
map);
358+
debug!(
359+
"replace_bound_vars_with_placeholders(binder={:?}, result={:?}, map={:?})",
360+
binder,
361+
result,
362+
map
363+
);
353364

354365
(result, map)
355366
}
@@ -530,7 +541,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
530541

531542
/// Pops the placeholder regions found in `placeholder_map` from the region
532543
/// inference context. Whenever you create placeholder regions via
533-
/// `replace_late_bound_regions_with_placeholders`, they must be popped before you
544+
/// `replace_bound_vars_with_placeholders`, they must be popped before you
534545
/// commit the enclosing snapshot (if you do not commit, e.g. within a
535546
/// probe or as a result of an error, then this is not necessary, as
536547
/// popping happens as part of the rollback).

src/librustc/infer/mod.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ pub struct InferCtxt<'a, 'gcx: 'a + 'tcx, 'tcx: 'a> {
227227
universe: Cell<ty::UniverseIndex>,
228228
}
229229

230-
/// A map returned by `replace_late_bound_regions_with_placeholders()`
230+
/// A map returned by `replace_bound_vars_with_placeholders()`
231231
/// indicating the placeholder region that each late-bound region was
232232
/// replaced with.
233233
pub type PlaceholderMap<'tcx> = BTreeMap<ty::BoundRegion, ty::Region<'tcx>>;
@@ -935,7 +935,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
935935
b,
936936
},
937937
placeholder_map,
938-
) = self.replace_late_bound_regions_with_placeholders(predicate);
938+
) = self.replace_bound_vars_with_placeholders(predicate);
939939

940940
let cause_span = cause.span;
941941
let ok = self.at(cause, param_env).sub_exp(a_is_expected, a, b)?;
@@ -952,7 +952,7 @@ impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
952952
) -> UnitResult<'tcx> {
953953
self.commit_if_ok(|snapshot| {
954954
let (ty::OutlivesPredicate(r_a, r_b), placeholder_map) =
955-
self.replace_late_bound_regions_with_placeholders(predicate);
955+
self.replace_bound_vars_with_placeholders(predicate);
956956
let origin = SubregionOrigin::from_obligation_cause(cause, || {
957957
RelateRegionParamBound(cause.span)
958958
});

src/librustc/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -204,7 +204,7 @@ pub fn poly_project_and_unify_type<'cx, 'gcx, 'tcx>(
204204
let infcx = selcx.infcx();
205205
infcx.commit_if_ok(|snapshot| {
206206
let (placeholder_predicate, placeholder_map) =
207-
infcx.replace_late_bound_regions_with_placeholders(&obligation.predicate);
207+
infcx.replace_bound_vars_with_placeholders(&obligation.predicate);
208208

209209
let skol_obligation = obligation.with(placeholder_predicate);
210210
let r = match project_and_unify_type(selcx, &skol_obligation) {

src/librustc/traits/select.rs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1726,7 +1726,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
17261726
let poly_trait_predicate = self.infcx()
17271727
.resolve_type_vars_if_possible(&obligation.predicate);
17281728
let (skol_trait_predicate, placeholder_map) = self.infcx()
1729-
.replace_late_bound_regions_with_placeholders(&poly_trait_predicate);
1729+
.replace_bound_vars_with_placeholders(&poly_trait_predicate);
17301730
debug!(
17311731
"match_projection_obligation_against_definition_bounds: \
17321732
skol_trait_predicate={:?} placeholder_map={:?}",
@@ -2685,7 +2685,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
26852685

26862686
self.in_snapshot(|this, snapshot| {
26872687
let (skol_ty, placeholder_map) = this.infcx()
2688-
.replace_late_bound_regions_with_placeholders(&ty);
2688+
.replace_bound_vars_with_placeholders(&ty);
26892689
let Normalized {
26902690
value: normalized_ty,
26912691
mut obligations,
@@ -2919,7 +2919,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
29192919
let trait_obligations: Vec<PredicateObligation<'_>> = self.in_snapshot(|this, snapshot| {
29202920
let poly_trait_ref = obligation.predicate.to_poly_trait_ref();
29212921
let (trait_ref, placeholder_map) = this.infcx()
2922-
.replace_late_bound_regions_with_placeholders(&poly_trait_ref);
2922+
.replace_bound_vars_with_placeholders(&poly_trait_ref);
29232923
let cause = obligation.derived_cause(ImplDerivedObligation);
29242924
this.impl_or_trait_obligations(
29252925
cause,
@@ -3122,7 +3122,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
31223122

31233123
self.in_snapshot(|this, snapshot| {
31243124
let (predicate, placeholder_map) = this.infcx()
3125-
.replace_late_bound_regions_with_placeholders(&obligation.predicate);
3125+
.replace_bound_vars_with_placeholders(&obligation.predicate);
31263126
let trait_ref = predicate.trait_ref;
31273127
let trait_def_id = trait_ref.def_id;
31283128
let substs = trait_ref.substs;
@@ -3585,7 +3585,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
35853585
}
35863586

35873587
let (skol_obligation, placeholder_map) = self.infcx()
3588-
.replace_late_bound_regions_with_placeholders(&obligation.predicate);
3588+
.replace_bound_vars_with_placeholders(&obligation.predicate);
35893589
let skol_obligation_trait_ref = skol_obligation.trait_ref;
35903590

35913591
let impl_substs = self.infcx

0 commit comments

Comments
 (0)