Skip to content

Commit 1f33145

Browse files
committed
make no_late_bound_regions a method on Binder<T>
1 parent 5562663 commit 1f33145

File tree

12 files changed

+33
-23
lines changed

12 files changed

+33
-23
lines changed

src/librustc/infer/outlives/implied_bounds.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
126126
}
127127

128128
ty::Predicate::RegionOutlives(ref data) => {
129-
match tcx.no_late_bound_regions(data) {
129+
match data.no_late_bound_regions() {
130130
None => vec![],
131131
Some(ty::OutlivesPredicate(r_a, r_b)) => {
132132
vec![ImpliedBound::RegionSubRegion(r_b, r_a)]
@@ -135,7 +135,7 @@ impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
135135
}
136136

137137
ty::Predicate::TypeOutlives(ref data) => {
138-
match tcx.no_late_bound_regions(data) {
138+
match data.no_late_bound_regions() {
139139
None => vec![],
140140
Some(ty::OutlivesPredicate(ty_a, r_b)) => {
141141
let ty_a = self.resolve_type_vars_if_possible(&ty_a);

src/librustc/infer/outlives/obligations.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -604,7 +604,7 @@ impl<'cx, 'gcx, 'tcx> TypeOutlives<'cx, 'gcx, 'tcx> {
604604
predicates
605605
.into_iter()
606606
.filter_map(|p| p.as_ref().to_opt_type_outlives())
607-
.filter_map(|p| self.tcx().no_late_bound_regions(&p))
607+
.filter_map(|p| p.no_late_bound_regions())
608608
.filter(|p| p.0 == ty)
609609
.map(|p| p.1)
610610
.collect()

src/librustc/traits/fulfill.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -400,14 +400,14 @@ fn process_predicate<'a, 'gcx, 'tcx>(
400400

401401
ty::Predicate::TypeOutlives(ref binder) => {
402402
// Check if there are higher-ranked regions.
403-
match selcx.tcx().no_late_bound_regions(binder) {
403+
match binder.no_late_bound_regions() {
404404
// If there are, inspect the underlying type further.
405405
None => {
406406
// Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
407407
let binder = binder.map_bound_ref(|pred| pred.0);
408408

409409
// Check if the type has any bound regions.
410-
match selcx.tcx().no_late_bound_regions(&binder) {
410+
match binder.no_late_bound_regions() {
411411
// If so, this obligation is an error (for now). Eventually we should be
412412
// able to support additional cases here, like `for<'a> &'a str: 'a`.
413413
None => {

src/librustc/traits/project.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1559,7 +1559,7 @@ impl<'cx, 'gcx, 'tcx> ProjectionCacheKey<'tcx> {
15591559
let infcx = selcx.infcx();
15601560
// We don't do cross-snapshot caching of obligations with escaping regions,
15611561
// so there's no cache key to use
1562-
infcx.tcx.no_late_bound_regions(&predicate)
1562+
predicate.no_late_bound_regions()
15631563
.map(|predicate| ProjectionCacheKey {
15641564
// We don't attempt to match up with a specific type-variable state
15651565
// from a specific call to `opt_normalize_projection_type` - if

src/librustc/traits/select.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1834,7 +1834,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
18341834
// T: Trait
18351835
// so it seems ok if we (conservatively) fail to accept that `Unsize`
18361836
// obligation above. Should be possible to extend this in the future.
1837-
let source = match self.tcx().no_late_bound_regions(&obligation.self_ty()) {
1837+
let source = match obligation.self_ty().no_late_bound_regions() {
18381838
Some(t) => t,
18391839
None => {
18401840
// Don't add any candidates if there are bound regions.
@@ -2784,7 +2784,7 @@ impl<'cx, 'gcx, 'tcx> SelectionContext<'cx, 'gcx, 'tcx> {
27842784
// assemble_candidates_for_unsizing should ensure there are no late bound
27852785
// regions here. See the comment there for more details.
27862786
let source = self.infcx.shallow_resolve(
2787-
tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
2787+
obligation.self_ty().no_late_bound_regions().unwrap());
27882788
let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
27892789
let target = self.infcx.shallow_resolve(target);
27902790

src/librustc/ty/fold.rs

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -364,16 +364,6 @@ impl<'a, 'gcx, 'tcx> TyCtxt<'a, 'gcx, 'tcx> {
364364
Binder(value)
365365
}
366366

367-
pub fn no_late_bound_regions<T>(self, value: &Binder<T>) -> Option<T>
368-
where T : TypeFoldable<'tcx>
369-
{
370-
if value.0.has_escaping_regions() {
371-
None
372-
} else {
373-
Some(value.0.clone())
374-
}
375-
}
376-
377367
/// Returns a set of all late-bound regions that are constrained
378368
/// by `value`, meaning that if we instantiate those LBR with
379369
/// variables and equate `value` with something else, those

src/librustc/ty/sty.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -680,6 +680,26 @@ impl<T> Binder<T> {
680680
{
681681
ty::Binder(f(self.0))
682682
}
683+
684+
/// Unwraps and returns the value within, but only if it contains
685+
/// no bound regions at all. (In other words, if this binder --
686+
/// and indeed any enclosing binder -- doesn't bind anything at
687+
/// all.) Otherwise, returns `None`.
688+
///
689+
/// (One could imagine having a method that just unwraps a single
690+
/// binder, but permits late-bound regions bound by enclosing
691+
/// binders, but that would require adjusting the debruijn
692+
/// indices, and given the shallow binding structure we often use,
693+
/// would not be that useful.)
694+
pub fn no_late_bound_regions<'tcx>(self) -> Option<T>
695+
where T : TypeFoldable<'tcx>
696+
{
697+
if self.skip_binder().has_escaping_regions() {
698+
None
699+
} else {
700+
Some(self.skip_binder().clone())
701+
}
702+
}
683703
}
684704

685705
/// Represents the projection of an associated type. In explicit UFCS

src/librustc_mir/shim.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -833,7 +833,7 @@ pub fn build_adt_ctor<'a, 'gcx, 'tcx>(infcx: &infer::InferCtxt<'a, 'gcx, 'tcx>,
833833
let tcx = infcx.tcx;
834834
let gcx = tcx.global_tcx();
835835
let def_id = tcx.hir.local_def_id(ctor_id);
836-
let sig = gcx.no_late_bound_regions(&gcx.fn_sig(def_id))
836+
let sig = gcx.fn_sig(def_id).no_late_bound_regions()
837837
.expect("LBR in ADT constructor signature");
838838
let sig = gcx.erase_regions(&sig);
839839
let param_env = gcx.param_env(def_id);

src/librustc_mir/transform/lower_128bit.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ fn check_lang_item_type<'a, 'tcx, D>(
144144
{
145145
let did = tcx.require_lang_item(lang_item);
146146
let poly_sig = tcx.fn_sig(did);
147-
let sig = tcx.no_late_bound_regions(&poly_sig).unwrap();
147+
let sig = poly_sig.no_late_bound_regions().unwrap();
148148
let lhs_ty = lhs.ty(local_decls, tcx);
149149
let rhs_ty = rhs.ty(local_decls, tcx);
150150
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);

src/librustc_typeck/check/_match.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -800,7 +800,7 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
800800
let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id);
801801
// Replace constructor type with constructed type for tuple struct patterns.
802802
let pat_ty = pat_ty.fn_sig(tcx).output();
803-
let pat_ty = tcx.no_late_bound_regions(&pat_ty).expect("expected fn type");
803+
let pat_ty = pat_ty.no_late_bound_regions().expect("expected fn type");
804804

805805
self.demand_eqtype(pat.span, expected, pat_ty);
806806

0 commit comments

Comments
 (0)