use middle::free_region::FreeRegionMap;
use middle::mem_categorization as mc;
use middle::mem_categorization::McResult;
-use middle::region::{self, CodeExtent};
+use middle::region::CodeExtent;
use middle::subst;
use middle::subst::Substs;
use middle::subst::Subst;
use syntax::ast;
use syntax::codemap;
use syntax::codemap::Span;
-use util::nodemap::{DefIdMap, FnvHashMap, NodeMap};
+use util::nodemap::{FnvHashMap, NodeMap};
use self::combine::CombineFields;
use self::region_inference::{RegionVarBindings, RegionSnapshot};
substs: &subst::Substs<'tcx>)
-> ty::ClosureTy<'tcx>
{
- self.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx, substs)
+ // the substitutions in `substs` are already monomorphized,
+ // but we still must normalize associated types
+ let closure_ty = self.tables
+ .borrow()
+ .closure_tys
+ .get(&def_id)
+ .unwrap()
+ .subst(self.tcx, substs);
+
+ if self.normalize {
+ // NOTE: this flag is *always* set to false currently
+ panic!("issue XXXX: must finish fulfill refactor") // normalize_associated_type(self.param_env.tcx, &closure_ty)
+ } else {
+ closure_ty
+ }
}
fn closure_upvars(&self,
substs: &Substs<'tcx>)
-> Option<Vec<ty::ClosureUpvar<'tcx>>>
{
- ty::ctxt::closure_upvars(self, def_id, substs)
+ // the substitutions in `substs` are already monomorphized,
+ // but we still must normalize associated types
+ let result = ty::ctxt::closure_upvars(self, def_id, substs)
+
+ if self.normalize {
+ // NOTE: this flag is *always* set to false currently
+ panic!("issue XXXX: must finish fulfill refactor") // monomorphize::normalize_associated_type(self.param_env.tcx, &result)
+ } else {
+ result
+ }
}
}
value.fold_with(&mut r)
}
+ /// Resolves all type variables in `t` and then, if any were left
+ /// unresolved, substitutes an error type. This is used after the
+ /// main checking when doing a second pass before writeback. The
+ /// justification is that writeback will produce an error for
+ /// these unconstrained type variables.
fn resolve_type_vars_or_error(&self, t: &Ty<'tcx>) -> mc::McResult<Ty<'tcx>> {
let ty = self.resolve_type_vars_if_possible(t);
if ty.has_infer_types() || ty.references_error() { Err(()) } else { Ok(ty) }
// Check whether this is a call to a closure where we
// haven't yet decided on whether the closure is fn vs
// fnmut vs fnonce. If so, we have to defer further processing.
- if fcx.closure_kind(def_id).is_none() {
+ if fcx.infcx().closure_kind(def_id).is_none() {
let closure_ty =
- fcx.closure_type(def_id, substs);
+ fcx.infcx().closure_type(def_id, substs);
let fn_sig =
fcx.infcx().replace_late_bound_regions_with_fresh_var(call_expr.span,
infer::FnCall,
// we should not be invoked until the closure kind has been
// determined by upvar inference
- assert!(fcx.closure_kind(self.closure_def_id).is_some());
+ assert!(fcx.infcx().closure_kind(self.closure_def_id).is_some());
// We may now know enough to figure out fn vs fnmut etc.
match try_overloaded_call_traits(fcx, self.call_expr, self.callee_expr,
};
let source = source.adjust_for_autoref(self.tcx(), reborrow);
- let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
+ let mut selcx = traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
// Use a FIFO queue for this custom fulfillment procedure.
let mut queue = VecDeque::new();
poly_trait_ref.to_predicate());
// Now we want to know if this can be matched
- let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx);
+ let mut selcx = traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
if !selcx.evaluate_obligation(&obligation) {
debug!("--> Cannot match obligation");
return None; // Cannot be matched, no such method resolution is possible.
// We can't use normalize_associated_types_in as it will pollute the
// fcx's fulfillment context after this probe is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
- let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
+ let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
debug!("assemble_inherent_impl_probe: xform_self_ty = {:?}",
// as it will pollute the fcx's fulfillment context after this probe
// is over.
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
- let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx);
+ let mut selcx = &mut traits::SelectionContext::new(self.fcx.infcx(), self.fcx.infcx());
let traits::Normalized { value: xform_self_ty, obligations } =
traits::normalize(selcx, cause, &xform_self_ty);
match probe.kind {
InherentImplCandidate(impl_def_id, ref substs, ref ref_obligations) |
ExtensionImplCandidate(impl_def_id, _, ref substs, _, ref ref_obligations) => {
- let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx);
+ let selcx = &mut traits::SelectionContext::new(self.infcx(), self.fcx.infcx());
let cause = traits::ObligationCause::misc(self.span, self.fcx.body_id);
// Check whether the impl imposes obligations we have to worry about.
let obligation = Obligation::misc(span,
fcx.body_id,
poly_trait_ref.to_predicate());
- let mut selcx = SelectionContext::new(infcx, fcx);
+ let mut selcx = SelectionContext::new(infcx, fcx.infcx());
if selcx.evaluate_obligation(&obligation) {
span_stored_function();
.map(|ty| self.infcx().resolve_type_vars_if_possible(&ty))
}
- fn node_method_origin(&self, method_call: ty::MethodCall)
- -> Option<ty::MethodOrigin<'tcx>>
- {
- self.inh.tables
- .borrow()
- .method_map
- .get(&method_call)
- .map(|method| method.origin.clone())
- }
-
- fn adjustments(&self) -> Ref<NodeMap<ty::AutoAdjustment<'tcx>>> {
- fn project_adjustments<'a, 'tcx>(tables: &'a ty::Tables<'tcx>) -> &'a NodeMap<ty::AutoAdjustment<'tcx>> {
- &tables.adjustments
- }
-
- Ref::map(self.inh.tables.borrow(), project_adjustments)
- }
-
- fn is_method_call(&self, id: ast::NodeId) -> bool {
- self.inh.tables.borrow().method_map.contains_key(&ty::MethodCall::expr(id))
- }
-
- fn temporary_scope(&self, rvalue_id: ast::NodeId) -> Option<CodeExtent> {
- self.param_env().temporary_scope(rvalue_id)
- }
-
- fn upvar_capture(&self, upvar_id: ty::UpvarId) -> Option<ty::UpvarCapture> {
- self.inh.tables.borrow().upvar_capture_map.get(&upvar_id).cloned()
- }
-}
-
-impl<'a, 'tcx> ty::ClosureTyper<'tcx> for FnCtxt<'a, 'tcx> {
- fn param_env<'b>(&'b self) -> &'b ty::ParameterEnvironment<'b,'tcx> {
- &self.inh.infcx.parameter_environment
- }
-
- fn closure_kind(&self,
- def_id: ast::DefId)
- -> Option<ty::ClosureKind>
- {
- self.inh.tables.borrow().closure_kinds.get(&def_id).cloned()
- }
-
- fn closure_type(&self,
- def_id: ast::DefId,
- substs: &subst::Substs<'tcx>)
- -> ty::ClosureTy<'tcx>
- {
- self.inh.tables.borrow().closure_tys.get(&def_id).unwrap().subst(self.tcx(), substs)
- }
-
- fn closure_upvars(&self,
- def_id: ast::DefId,
- substs: &Substs<'tcx>)
- -> Option<Vec<ty::ClosureUpvar<'tcx>>> {
- ty::ctxt::closure_upvars(self, def_id, substs)
- }
-}
-
impl<'a, 'tcx> Inherited<'a, 'tcx> {
fn new(tcx: &'a ty::ctxt<'tcx>,
tables: &'a RefCell<ty::Tables<'tcx>>,
fn normalize_associated_types_in<T>(&self, span: Span, value: &T) -> T
where T : TypeFoldable<'tcx> + HasTypeFlags
{
- self.inh.normalize_associated_types_in(self, span, self.body_id, value)
+ self.inh.normalize_associated_types_in(self.infcx(), span, self.body_id, value)
}
fn normalize_associated_type(&self,
self.inh.fulfillment_cx
.borrow_mut()
.normalize_projection_type(self.infcx(),
- self,
+ self.infcx(),
ty::ProjectionTy {
trait_ref: trait_ref,
item_name: item_name,
self.select_all_obligations_and_apply_defaults();
let mut fulfillment_cx = self.inh.fulfillment_cx.borrow_mut();
- match fulfillment_cx.select_all_or_error(self.infcx(), self) {
+ match fulfillment_cx.select_all_or_error(self.infcx(), self.infcx()) {
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
}
match
self.inh.fulfillment_cx
.borrow_mut()
- .select_where_possible(self.infcx(), self)
+ .select_where_possible(self.infcx(), self.infcx())
{
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
match
self.inh.fulfillment_cx
.borrow_mut()
- .select_new_obligations(self.infcx(), self)
+ .select_new_obligations(self.infcx(), self.infcx())
{
Ok(()) => { }
Err(errors) => { report_fulfillment_errors(self.infcx(), &errors); }
use check::dropck;
use check::FnCtxt;
use middle::free_region::FreeRegionMap;
+use middle::infer::InferCtxt;
use middle::implicator;
use middle::mem_categorization as mc;
use middle::region::CodeExtent;
debug!("relate_free_regions(t={:?})", ty);
let body_scope = CodeExtent::from_node_id(body_id);
let body_scope = ty::ReScope(body_scope);
- let implications = implicator::implications(self.fcx.infcx(), self.fcx, body_id,
+ let implications = implicator::implications(self.fcx.infcx(), self.fcx.infcx(), body_id,
ty, body_scope, span);
// Record any relations between free regions that we observe into the free-region-map.
// If necessary, constrain destructors in the unadjusted form of this
// expression.
let cmt_result = {
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
mc.cat_expr_unadjusted(expr)
};
match cmt_result {
// If necessary, constrain destructors in this expression. This will be
// the adjusted form if there is an adjustment.
let cmt_result = {
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
mc.cat_expr(expr)
};
match cmt_result {
r, m);
{
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let self_cmt = ignore_err!(mc.cat_expr_autoderefd(deref_expr, i));
debug!("constrain_autoderefs: self_cmt={:?}",
self_cmt);
debug!("link_addr_of(expr={:?}, base={:?})", expr, base);
let cmt = {
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
ignore_err!(mc.cat_expr(base))
};
None => { return; }
Some(ref expr) => &**expr,
};
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let discr_cmt = ignore_err!(mc.cat_expr(init_expr));
link_pattern(rcx, mc, discr_cmt, &*local.pat);
}
/// linked to the lifetime of its guarantor (if any).
fn link_match(rcx: &Rcx, discr: &ast::Expr, arms: &[ast::Arm]) {
debug!("regionck::for_match()");
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let discr_cmt = ignore_err!(mc.cat_expr(discr));
debug!("discr_cmt={:?}", discr_cmt);
for arm in arms {
/// linked to the lifetime of its guarantor (if any).
fn link_fn_args(rcx: &Rcx, body_scope: CodeExtent, args: &[ast::Arg]) {
debug!("regionck::link_fn_args(body_scope={:?})", body_scope);
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
for arg in args {
let arg_ty = rcx.fcx.node_ty(arg.id);
let re_scope = ty::ReScope(body_scope);
/// Link lifetimes of any ref bindings in `root_pat` to the pointers found in the discriminant, if
/// needed.
fn link_pattern<'a, 'tcx>(rcx: &Rcx<'a, 'tcx>,
- mc: mc::MemCategorizationContext<FnCtxt<'a, 'tcx>>,
+ mc: mc::MemCategorizationContext<InferCtxt<'a, 'tcx>>,
discr_cmt: mc::cmt<'tcx>,
root_pat: &ast::Pat) {
debug!("link_pattern(discr_cmt={:?}, root_pat={:?})",
autoref: &ty::AutoRef)
{
debug!("link_autoref(autoref={:?})", autoref);
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let expr_cmt = ignore_err!(mc.cat_expr_autoderefd(expr, autoderefs));
debug!("expr_cmt={:?}", expr_cmt);
callee_scope: CodeExtent) {
debug!("link_by_ref(expr={:?}, callee_scope={:?})",
expr, callee_scope);
- let mc = mc::MemCategorizationContext::new(rcx.fcx);
+ let mc = mc::MemCategorizationContext::new(rcx.fcx.infcx());
let expr_cmt = ignore_err!(mc.cat_expr(expr));
let borrow_region = ty::ReScope(callee_scope);
link_region(rcx, expr.span, &borrow_region, ty::ImmBorrow, expr_cmt);
ty,
region);
- let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx, rcx.body_id,
+ let implications = implicator::implications(rcx.fcx.infcx(), rcx.fcx.infcx(), rcx.body_id,
ty, region, origin.span());
for implication in implications {
debug!("implication: {:?}", implication);
debug!("closure_must_outlive(region={:?}, def_id={:?}, substs={:?})",
region, def_id, substs);
- let upvars = rcx.fcx.closure_upvars(def_id, substs).unwrap();
+ let upvars = rcx.fcx.infcx().closure_upvars(def_id, substs).unwrap();
for upvar in upvars {
let var_id = upvar.def.def_id().local_id();
type_must_outlive(
debug!("analyzing closure `{}` with fn body id `{}`", id, body.id);
- let mut euv = euv::ExprUseVisitor::new(self, self.fcx);
+ let mut euv = euv::ExprUseVisitor::new(self, self.fcx.infcx());
euv.walk_fn(decl, body);
// If we had not yet settled on a closure kind for this closure,
let predicates = fcx.tcx().lookup_super_predicates(poly_trait_ref.def_id());
let predicates = predicates.instantiate_supertrait(fcx.tcx(), &poly_trait_ref);
let predicates = {
- let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx);
+ let selcx = &mut traits::SelectionContext::new(fcx.infcx(), fcx.infcx());
traits::normalize(selcx, cause.clone(), &predicates)
};
for predicate in predicates.value.predicates {