use hir::def_id::DefId;
use infer::{self, GenericKind, InferCtxt, RegionObligation, SubregionOrigin, VerifyBound};
use syntax::ast;
-use traits;
+use traits::{self, ObligationCause};
use ty::outlives::Component;
use ty::subst::{Subst, Substs};
-use ty::{self, Ty, TyCtxt, TypeFoldable};
+use ty::{self, Region, Ty, TyCtxt, TypeFoldable};
impl<'cx, 'gcx, 'tcx> InferCtxt<'cx, 'gcx, 'tcx> {
/// Registers that the given region obligation must be resolved
.push((body_id, obligation));
}
+ pub fn register_region_obligation_with_cause(
+ &self,
+ sup_type: Ty<'tcx>,
+ sub_region: Region<'tcx>,
+ cause: &ObligationCause<'tcx>,
+ ) {
+ let origin = SubregionOrigin::from_obligation_cause(cause, || {
+ infer::RelateParamBound(cause.span, sup_type)
+ });
+
+ self.register_region_obligation(
+ cause.body_id,
+ RegionObligation {
+ sup_type,
+ sub_region,
+ origin,
+ },
+ );
+ }
+
/// Trait queries just want to pass back type obligations "as is"
pub fn take_registered_region_obligations(&self) -> Vec<(ast::NodeId, RegionObligation<'tcx>)> {
::std::mem::replace(&mut *self.region_obligations.borrow_mut(), vec![])
let mut my_region_obligations = Vec::with_capacity(self.region_obligations.borrow().len());
{
let mut r_o = self.region_obligations.borrow_mut();
- my_region_obligations.extend(
- r_o.drain_filter(|(ro_body_id, _)| *ro_body_id == body_id)
- .map(|(_, obligation)| obligation)
- );
+ my_region_obligations.extend(r_o.drain_filter(|(ro_body_id, _)| {
+ *ro_body_id == body_id
+ }).map(|(_, obligation)| obligation));
}
let outlives = &mut TypeOutlives::new(
for RegionObligation {
sup_type,
sub_region,
- cause,
+ origin,
} in my_region_obligations
{
debug!(
- "process_registered_region_obligations: sup_type={:?} sub_region={:?} cause={:?}",
- sup_type, sub_region, cause
+ "process_registered_region_obligations: sup_type={:?} sub_region={:?} origin={:?}",
+ sup_type, sub_region, origin
);
- let origin = SubregionOrigin::from_obligation_cause(&cause, || {
- infer::RelateParamBound(cause.span, sup_type)
- });
-
let sup_type = self.resolve_type_vars_if_possible(&sup_type);
outlives.type_must_outlive(origin, sup_type, sub_region);
}
let origin = origin.clone();
match component {
Component::Region(region1) => {
- self.delegate.push_sub_region_constraint(origin, region, region1);
+ self.delegate
+ .push_sub_region_constraint(origin, region, region1);
}
Component::Param(param_ty) => {
self.param_ty_must_outlive(origin, region, param_ty);
}
for r in projection_ty.substs.regions() {
- self.delegate.push_sub_region_constraint(origin.clone(), region, r);
+ self.delegate
+ .push_sub_region_constraint(origin.clone(), region, r);
}
return;
);
// see the extensive comment in projection_must_outlive
- let ty = self
- .tcx
+ let ty = self.tcx
.mk_projection(projection_ty.item_def_id, projection_ty.substs);
let recursive_bound = self.recursive_type_bound(ty);
}
fn recursive_type_bound(&self, ty: Ty<'tcx>) -> VerifyBound<'tcx> {
- let mut bounds = ty.walk_shallow().map(|subty| self.type_bound(subty)).collect::<Vec<_>>();
+ let mut bounds = ty.walk_shallow()
+ .map(|subty| self.type_bound(subty))
+ .collect::<Vec<_>>();
let mut regions = ty.regions();
regions.retain(|r| !r.is_late_bound()); // ignore late-bound regions
self.verify_generic_bound(origin, kind, a, bound)
}
}
-
use rustc_data_structures::fx::{FxHashMap, FxHashSet};
use infer::region_constraints::{Constraint, RegionConstraintData};
-use infer::{InferCtxt, RegionObligation};
+use infer::InferCtxt;
use ty::fold::TypeFolder;
use ty::{Region, RegionVid};
binder.map_bound_ref(|pred| pred.0).no_late_bound_regions(),
) {
(None, Some(t_a)) => {
- select.infcx().register_region_obligation(
- ast::DUMMY_NODE_ID,
- RegionObligation {
- sup_type: t_a,
- sub_region: select.infcx().tcx.types.re_static,
- cause: dummy_cause.clone(),
- },
+ select.infcx().register_region_obligation_with_cause(
+ t_a,
+ select.infcx().tcx.types.re_static,
+ &dummy_cause,
);
}
(Some(ty::OutlivesPredicate(t_a, r_b)), _) => {
- select.infcx().register_region_obligation(
- ast::DUMMY_NODE_ID,
- RegionObligation {
- sup_type: t_a,
- sub_region: r_b,
- cause: dummy_cause.clone(),
- },
+ select.infcx().register_region_obligation_with_cause(
+ t_a,
+ r_b,
+ &dummy_cause,
);
}
_ => {}
// option. This file may not be copied, modified, or distributed
// except according to those terms.
-use infer::{RegionObligation, InferCtxt};
+use infer::InferCtxt;
use mir::interpret::GlobalId;
use ty::{self, Ty, TypeFoldable, ToPolyTraitRef, ToPredicate};
use ty::error::ExpectedFound;
Some(t_a) => {
let r_static = self.selcx.tcx().types.re_static;
if self.register_region_obligations {
- self.selcx.infcx().register_region_obligation(
- obligation.cause.body_id,
- RegionObligation {
- sup_type: t_a,
- sub_region: r_static,
- cause: obligation.cause.clone(),
- });
+ self.selcx.infcx().register_region_obligation_with_cause(
+ t_a,
+ r_static,
+ &obligation.cause,
+ );
}
ProcessResult::Changed(vec![])
}
// If there aren't, register the obligation.
Some(ty::OutlivesPredicate(t_a, r_b)) => {
if self.register_region_obligations {
- self.selcx.infcx().register_region_obligation(
- obligation.cause.body_id,
- RegionObligation {
- sup_type: t_a,
- sub_region: r_b,
- cause: obligation.cause.clone()
- });
+ self.selcx.infcx().register_region_obligation_with_cause(
+ t_a,
+ r_b,
+ &obligation.cause,
+ );
}
ProcessResult::Changed(vec![])
}