}
ty::Predicate::RegionOutlives(ref data) => {
- match tcx.no_late_bound_regions(data) {
+ match data.no_late_bound_regions() {
None => vec![],
Some(ty::OutlivesPredicate(r_a, r_b)) => {
vec![ImpliedBound::RegionSubRegion(r_b, r_a)]
}
ty::Predicate::TypeOutlives(ref data) => {
- match tcx.no_late_bound_regions(data) {
+ match data.no_late_bound_regions() {
None => vec![],
Some(ty::OutlivesPredicate(ty_a, r_b)) => {
let ty_a = self.resolve_type_vars_if_possible(&ty_a);
predicates
.into_iter()
.filter_map(|p| p.as_ref().to_opt_type_outlives())
- .filter_map(|p| self.tcx().no_late_bound_regions(&p))
+ .filter_map(|p| p.no_late_bound_regions())
.filter(|p| p.0 == ty)
.map(|p| p.1)
.collect()
ty::Predicate::TypeOutlives(ref binder) => {
// Check if there are higher-ranked regions.
- match selcx.tcx().no_late_bound_regions(binder) {
+ match binder.no_late_bound_regions() {
// If there are, inspect the underlying type further.
None => {
// Convert from `Binder<OutlivesPredicate<Ty, Region>>` to `Binder<Ty>`.
let binder = binder.map_bound_ref(|pred| pred.0);
// Check if the type has any bound regions.
- match selcx.tcx().no_late_bound_regions(&binder) {
+ match binder.no_late_bound_regions() {
// If so, this obligation is an error (for now). Eventually we should be
// able to support additional cases here, like `for<'a> &'a str: 'a`.
None => {
let infcx = selcx.infcx();
// We don't do cross-snapshot caching of obligations with escaping regions,
// so there's no cache key to use
- infcx.tcx.no_late_bound_regions(&predicate)
+ predicate.no_late_bound_regions()
.map(|predicate| ProjectionCacheKey {
// We don't attempt to match up with a specific type-variable state
// from a specific call to `opt_normalize_projection_type` - if
// T: Trait
// so it seems ok if we (conservatively) fail to accept that `Unsize`
// obligation above. Should be possible to extend this in the future.
- let source = match self.tcx().no_late_bound_regions(&obligation.self_ty()) {
+ let source = match obligation.self_ty().no_late_bound_regions() {
Some(t) => t,
None => {
// Don't add any candidates if there are bound regions.
// assemble_candidates_for_unsizing should ensure there are no late bound
// regions here. See the comment there for more details.
let source = self.infcx.shallow_resolve(
- tcx.no_late_bound_regions(&obligation.self_ty()).unwrap());
+ obligation.self_ty().no_late_bound_regions().unwrap());
let target = obligation.predicate.skip_binder().trait_ref.substs.type_at(1);
let target = self.infcx.shallow_resolve(target);
Binder(value)
}
- pub fn no_late_bound_regions<T>(self, value: &Binder<T>) -> Option<T>
- where T : TypeFoldable<'tcx>
- {
- if value.0.has_escaping_regions() {
- None
- } else {
- Some(value.0.clone())
- }
- }
-
/// Returns a set of all late-bound regions that are constrained
/// by `value`, meaning that if we instantiate those LBR with
/// variables and equate `value` with something else, those
{
ty::Binder(f(self.0))
}
+
+ /// Unwraps and returns the value within, but only if it contains
+ /// no bound regions at all. (In other words, if this binder --
+ /// and indeed any enclosing binder -- doesn't bind anything at
+ /// all.) Otherwise, returns `None`.
+ ///
+ /// (One could imagine having a method that just unwraps a single
+ /// binder, but permits late-bound regions bound by enclosing
+ /// binders, but that would require adjusting the debruijn
+ /// indices, and given the shallow binding structure we often use,
+ /// would not be that useful.)
+ pub fn no_late_bound_regions<'tcx>(self) -> Option<T>
+ where T : TypeFoldable<'tcx>
+ {
+ if self.skip_binder().has_escaping_regions() {
+ None
+ } else {
+ Some(self.skip_binder().clone())
+ }
+ }
}
/// Represents the projection of an associated type. In explicit UFCS
let tcx = infcx.tcx;
let gcx = tcx.global_tcx();
let def_id = tcx.hir.local_def_id(ctor_id);
- let sig = gcx.no_late_bound_regions(&gcx.fn_sig(def_id))
+ let sig = gcx.fn_sig(def_id).no_late_bound_regions()
.expect("LBR in ADT constructor signature");
let sig = gcx.erase_regions(&sig);
let param_env = gcx.param_env(def_id);
{
let did = tcx.require_lang_item(lang_item);
let poly_sig = tcx.fn_sig(did);
- let sig = tcx.no_late_bound_regions(&poly_sig).unwrap();
+ let sig = poly_sig.no_late_bound_regions().unwrap();
let lhs_ty = lhs.ty(local_decls, tcx);
let rhs_ty = rhs.ty(local_decls, tcx);
let place_ty = place.ty(local_decls, tcx).to_ty(tcx);
let pat_ty = self.instantiate_value_path(segments, opt_ty, def, pat.span, pat.id);
// Replace constructor type with constructed type for tuple struct patterns.
let pat_ty = pat_ty.fn_sig(tcx).output();
- let pat_ty = tcx.no_late_bound_regions(&pat_ty).expect("expected fn type");
+ let pat_ty = pat_ty.no_late_bound_regions().expect("expected fn type");
self.demand_eqtype(pat.span, expected, pat_ty);
let mut structural_to_nomimal = FxHashMap();
let sig = tcx.fn_sig(def_id);
- let sig = tcx.no_late_bound_regions(&sig).unwrap();
+ let sig = sig.no_late_bound_regions().unwrap();
if intr.inputs.len() != sig.inputs().len() {
span_err!(tcx.sess, it.span, E0444,
"platform-specific intrinsic has invalid number of \
poly_trait_ref: ty::PolyTraitRef<'tcx>)
-> Ty<'tcx>
{
- if let Some(trait_ref) = self.tcx().no_late_bound_regions(&poly_trait_ref) {
+ if let Some(trait_ref) = poly_trait_ref.no_late_bound_regions() {
self.tcx().mk_projection(item_def_id, trait_ref.substs)
} else {
// no late-bound regions, we can just ignore the binder