diff --git a/src/librustc/middle/check_const.rs b/src/librustc/middle/check_const.rs index a9b3043e090..f9e78274b4f 100644 --- a/src/librustc/middle/check_const.rs +++ b/src/librustc/middle/check_const.rs @@ -125,7 +125,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { None => self.tcx.empty_parameter_environment() }; - let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), false); + let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env)); f(&mut euv::ExprUseVisitor::new(self, &infcx)) } @@ -295,7 +295,7 @@ impl<'a, 'tcx> CheckCrateVisitor<'a, 'tcx> { fn check_static_type(&self, e: &hir::Expr) { let ty = self.tcx.node_id_to_type(e.id); - let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None, false); + let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None); let cause = traits::ObligationCause::new(e.span, e.id, traits::SharedStatic); let mut fulfill_cx = infcx.fulfillment_cx.borrow_mut(); fulfill_cx.register_builtin_bound(&infcx, ty, ty::BoundSync, cause); diff --git a/src/librustc/middle/check_match.rs b/src/librustc/middle/check_match.rs index a3314243346..7e9a8a28f1f 100644 --- a/src/librustc/middle/check_match.rs +++ b/src/librustc/middle/check_match.rs @@ -1094,8 +1094,7 @@ fn check_legality_of_move_bindings(cx: &MatchCheckCtxt, //FIXME: (@jroesch) this code should be floated up as well let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, - Some(cx.param_env.clone()), - false); + Some(cx.param_env.clone())); if infcx.type_moves_by_default(pat_ty, pat.span) { check_move(p, sub.as_ref().map(|p| &**p)); } @@ -1127,8 +1126,7 @@ fn check_for_mutation_in_guard<'a, 'tcx>(cx: &'a MatchCheckCtxt<'a, 'tcx>, let infcx = infer::new_infer_ctxt(cx.tcx, &cx.tcx.tables, - Some(checker.cx.param_env.clone()), - false); + Some(checker.cx.param_env.clone())); let mut visitor = ExprUseVisitor::new(&mut checker, &infcx); visitor.walk_expr(guard); diff --git a/src/librustc/middle/check_rvalues.rs b/src/librustc/middle/check_rvalues.rs index 8a3e039ac6e..5ead8fb95f8 100644 --- a/src/librustc/middle/check_rvalues.rs +++ b/src/librustc/middle/check_rvalues.rs @@ -44,8 +44,7 @@ impl<'a, 'tcx, 'v> intravisit::Visitor<'v> for RvalueContext<'a, 'tcx> { let param_env = ParameterEnvironment::for_item(self.tcx, fn_id); let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, - Some(param_env.clone()), - false); + Some(param_env.clone())); let mut delegate = RvalueContextDelegate { tcx: self.tcx, param_env: ¶m_env }; let mut euv = euv::ExprUseVisitor::new(&mut delegate, &infcx); euv.walk_fn(fd, b); diff --git a/src/librustc/middle/const_eval.rs b/src/librustc/middle/const_eval.rs index d5cfff4aff8..4830fbc74c7 100644 --- a/src/librustc/middle/const_eval.rs +++ b/src/librustc/middle/const_eval.rs @@ -1247,7 +1247,7 @@ fn resolve_trait_associated_const<'a, 'tcx: 'a>(tcx: &'a ty::ctxt<'tcx>, substs: trait_substs }); tcx.populate_implementations_for_trait_if_necessary(trait_ref.def_id()); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); let mut selcx = traits::SelectionContext::new(&infcx); let obligation = traits::Obligation::new(traits::ObligationCause::dummy(), diff --git a/src/librustc/middle/infer/mod.rs b/src/librustc/middle/infer/mod.rs index 922d4c251bb..15e368812f2 100644 --- a/src/librustc/middle/infer/mod.rs +++ b/src/librustc/middle/infer/mod.rs @@ -354,16 +354,9 @@ pub fn fixup_err_to_string(f: FixupError) -> String { } } -/// errors_will_be_reported is required to proxy to the fulfillment context -/// FIXME -- a better option would be to hold back on modifying -/// the global cache until we know that all dependent obligations -/// are also satisfied. In that case, we could actually remove -/// this boolean flag, and we'd also avoid the problem of squelching -/// duplicate errors that occur across fns. pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, tables: &'a RefCell>, - param_env: Option>, - errors_will_be_reported: bool) + param_env: Option>) -> InferCtxt<'a, 'tcx> { InferCtxt { tcx: tcx, @@ -373,7 +366,7 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, float_unification_table: RefCell::new(UnificationTable::new()), region_vars: RegionVarBindings::new(tcx), parameter_environment: param_env.unwrap_or(tcx.empty_parameter_environment()), - fulfillment_cx: RefCell::new(traits::FulfillmentContext::new(errors_will_be_reported)), + fulfillment_cx: RefCell::new(traits::FulfillmentContext::new()), reported_trait_errors: RefCell::new(FnvHashSet()), normalize: false, err_count_on_creation: tcx.sess.err_count() @@ -383,7 +376,7 @@ pub fn new_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, pub fn normalizing_infer_ctxt<'a, 'tcx>(tcx: &'a ty::ctxt<'tcx>, tables: &'a RefCell>) -> InferCtxt<'a, 'tcx> { - let mut infcx = new_infer_ctxt(tcx, tables, None, false); + let mut infcx = new_infer_ctxt(tcx, tables, None); infcx.normalize = true; infcx } @@ -522,7 +515,7 @@ pub fn normalize_associated_type<'tcx,T>(tcx: &ty::ctxt<'tcx>, value: &T) -> T return value; } - let infcx = new_infer_ctxt(tcx, &tcx.tables, None, true); + let infcx = new_infer_ctxt(tcx, &tcx.tables, None); let mut selcx = traits::SelectionContext::new(&infcx); let cause = traits::ObligationCause::dummy(); let traits::Normalized { value: result, obligations } = diff --git a/src/librustc/middle/traits/mod.rs b/src/librustc/middle/traits/mod.rs index 6cf841cc477..4a92a8a9d58 100644 --- a/src/librustc/middle/traits/mod.rs +++ b/src/librustc/middle/traits/mod.rs @@ -356,7 +356,7 @@ pub fn type_known_to_meet_builtin_bound<'a,'tcx>(infcx: &InferCtxt<'a,'tcx>, // this function's result remains infallible, we must confirm // that guess. While imperfect, I believe this is sound. - let mut fulfill_cx = FulfillmentContext::new(false); + let mut fulfill_cx = FulfillmentContext::new(); // We can use a dummy node-id here because we won't pay any mind // to region obligations that arise (there shouldn't really be any @@ -434,8 +434,9 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi let elaborated_env = unnormalized_env.with_caller_bounds(predicates); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env), false); - let predicates = match fully_normalize(&infcx, cause, + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(elaborated_env)); + let predicates = match fully_normalize(&infcx, + cause, &infcx.parameter_environment.caller_bounds) { Ok(predicates) => predicates, Err(errors) => { @@ -444,6 +445,9 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi } }; + debug!("normalize_param_env_or_error: normalized predicates={:?}", + predicates); + let free_regions = FreeRegionMap::new(); infcx.resolve_regions_and_report_errors(&free_regions, body_id); let predicates = match infcx.fully_resolve(&predicates) { @@ -462,6 +466,9 @@ pub fn normalize_param_env_or_error<'a,'tcx>(unnormalized_env: ty::ParameterEnvi } }; + debug!("normalize_param_env_or_error: resolved predicates={:?}", + predicates); + infcx.parameter_environment.with_caller_bounds(predicates) } @@ -471,7 +478,7 @@ pub fn fully_normalize<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>, -> Result>> where T : TypeFoldable<'tcx> { - debug!("normalize_param_env(value={:?})", value); + debug!("fully_normalize(value={:?})", value); let mut selcx = &mut SelectionContext::new(infcx); // FIXME (@jroesch) ISSUE 26721 @@ -487,20 +494,28 @@ pub fn fully_normalize<'a,'tcx,T>(infcx: &InferCtxt<'a,'tcx>, // // I think we should probably land this refactor and then come // back to this is a follow-up patch. - let mut fulfill_cx = FulfillmentContext::new(false); + let mut fulfill_cx = FulfillmentContext::new(); let Normalized { value: normalized_value, obligations } = project::normalize(selcx, cause, value); - debug!("normalize_param_env: normalized_value={:?} obligations={:?}", + debug!("fully_normalize: normalized_value={:?} obligations={:?}", normalized_value, obligations); for obligation in obligations { fulfill_cx.register_predicate_obligation(selcx.infcx(), obligation); } - try!(fulfill_cx.select_all_or_error(infcx)); + debug!("fully_normalize: select_all_or_error start"); + match fulfill_cx.select_all_or_error(infcx) { + Ok(()) => { } + Err(e) => { + debug!("fully_normalize: error={:?}", e); + return Err(e); + } + } + debug!("fully_normalize: select_all_or_error complete"); let resolved_value = infcx.resolve_type_vars_if_possible(&normalized_value); - debug!("normalize_param_env: resolved_value={:?}", resolved_value); + debug!("fully_normalize: resolved_value={:?}", resolved_value); Ok(resolved_value) } diff --git a/src/librustc/middle/ty/util.rs b/src/librustc/middle/ty/util.rs index af23efe2bf4..03145951367 100644 --- a/src/librustc/middle/ty/util.rs +++ b/src/librustc/middle/ty/util.rs @@ -182,7 +182,7 @@ impl<'a, 'tcx> ParameterEnvironment<'a, 'tcx> { let tcx = self.tcx; // FIXME: (@jroesch) float this code up - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(self.clone()), false); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(self.clone())); let adt = match self_type.sty { ty::TyStruct(struct_def, substs) => { @@ -655,7 +655,7 @@ impl<'tcx> ty::TyS<'tcx> { -> bool { let tcx = param_env.tcx; - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env.clone()), false); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(param_env.clone())); let is_impld = traits::type_known_to_meet_builtin_bound(&infcx, self, bound, span); diff --git a/src/librustc_borrowck/borrowck/check_loans.rs b/src/librustc_borrowck/borrowck/check_loans.rs index 2d30b827750..5e8495ceddd 100644 --- a/src/librustc_borrowck/borrowck/check_loans.rs +++ b/src/librustc_borrowck/borrowck/check_loans.rs @@ -202,7 +202,7 @@ pub fn check_loans<'a, 'b, 'c, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, debug!("check_loans(body id={})", body.id); let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id); - let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env), false); + let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env)); let mut clcx = CheckLoanCtxt { bccx: bccx, diff --git a/src/librustc_borrowck/borrowck/gather_loans/mod.rs b/src/librustc_borrowck/borrowck/gather_loans/mod.rs index 6f6ce67380b..8cf10cb9b05 100644 --- a/src/librustc_borrowck/borrowck/gather_loans/mod.rs +++ b/src/librustc_borrowck/borrowck/gather_loans/mod.rs @@ -55,7 +55,7 @@ pub fn gather_loans_in_fn<'a, 'tcx>(bccx: &BorrowckCtxt<'a, 'tcx>, }; let param_env = ty::ParameterEnvironment::for_item(bccx.tcx, fn_id); - let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env), false); + let infcx = infer::new_infer_ctxt(bccx.tcx, &bccx.tcx.tables, Some(param_env)); { let mut euv = euv::ExprUseVisitor::new(&mut glcx, &infcx); euv.walk_fn(decl, body); @@ -525,7 +525,7 @@ struct StaticInitializerCtxt<'a, 'tcx: 'a> { impl<'a, 'tcx, 'v> Visitor<'v> for StaticInitializerCtxt<'a, 'tcx> { fn visit_expr(&mut self, ex: &Expr) { if let hir::ExprAddrOf(mutbl, ref base) = ex.node { - let infcx = infer::new_infer_ctxt(self.bccx.tcx, &self.bccx.tcx.tables, None, false); + let infcx = infer::new_infer_ctxt(self.bccx.tcx, &self.bccx.tcx.tables, None); let mc = mc::MemCategorizationContext::new(&infcx); let base_cmt = mc.cat_expr(&**base).unwrap(); let borrow_kind = ty::BorrowKind::from_mutbl(mutbl); diff --git a/src/librustc_mir/mir_map.rs b/src/librustc_mir/mir_map.rs index ac15878dc51..3886a6b83ac 100644 --- a/src/librustc_mir/mir_map.rs +++ b/src/librustc_mir/mir_map.rs @@ -143,7 +143,7 @@ impl<'a, 'm, 'tcx> Visitor<'tcx> for InnerDump<'a,'m,'tcx> { let param_env = ty::ParameterEnvironment::for_item(self.tcx, id); - let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env), true); + let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, Some(param_env)); match build_mir(Cx::new(&infcx), implicit_arg_tys, id, span, decl, body) { Ok(mut mir) => { diff --git a/src/librustc_typeck/check/compare_method.rs b/src/librustc_typeck/check/compare_method.rs index 554424a36b1..d5f24220189 100644 --- a/src/librustc_typeck/check/compare_method.rs +++ b/src/librustc_typeck/check/compare_method.rs @@ -42,7 +42,7 @@ pub fn compare_impl_method<'tcx>(tcx: &ty::ctxt<'tcx>, debug!("compare_impl_method: impl_trait_ref (liberated) = {:?}", impl_trait_ref); - let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true); + let mut infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut(); let trait_to_impl_substs = &impl_trait_ref.substs; @@ -416,7 +416,7 @@ pub fn compare_const_impl<'tcx>(tcx: &ty::ctxt<'tcx>, debug!("compare_const_impl(impl_trait_ref={:?})", impl_trait_ref); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, true); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); let mut fulfillment_cx = infcx.fulfillment_cx.borrow_mut(); // The below is for the most part highly similar to the procedure diff --git a/src/librustc_typeck/check/dropck.rs b/src/librustc_typeck/check/dropck.rs index 0cf552b6efe..deda0b818ee 100644 --- a/src/librustc_typeck/check/dropck.rs +++ b/src/librustc_typeck/check/dropck.rs @@ -83,7 +83,7 @@ fn ensure_drop_params_and_item_params_correspond<'tcx>( // check that the impl type can be made to match the trait type. let impl_param_env = ty::ParameterEnvironment::for_item(tcx, self_type_node_id); - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(impl_param_env), true); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, Some(impl_param_env)); let named_type = tcx.lookup_item_type(self_type_did).ty; let named_type = named_type.subst(tcx, &infcx.parameter_environment.free_substs); diff --git a/src/librustc_typeck/check/mod.rs b/src/librustc_typeck/check/mod.rs index 4de04d99bd9..e9184a12d72 100644 --- a/src/librustc_typeck/check/mod.rs +++ b/src/librustc_typeck/check/mod.rs @@ -305,7 +305,7 @@ impl<'a, 'tcx> Inherited<'a, 'tcx> { -> Inherited<'a, 'tcx> { Inherited { - infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env), true), + infcx: infer::new_infer_ctxt(tcx, tables, Some(param_env)), locals: RefCell::new(NodeMap()), tables: tables, deferred_call_resolutions: RefCell::new(DefIdMap()), diff --git a/src/librustc_typeck/coherence/mod.rs b/src/librustc_typeck/coherence/mod.rs index 7465ff526b6..7e63fd47d61 100644 --- a/src/librustc_typeck/coherence/mod.rs +++ b/src/librustc_typeck/coherence/mod.rs @@ -384,7 +384,7 @@ impl<'a, 'tcx> CoherenceChecker<'a, 'tcx> { debug!("check_implementations_of_coerce_unsized: {:?} -> {:?} (free)", source, target); - let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env), true); + let infcx = new_infer_ctxt(tcx, &tcx.tables, Some(param_env)); let check_mutbl = |mt_a: ty::TypeAndMut<'tcx>, mt_b: ty::TypeAndMut<'tcx>, mk_ptr: &Fn(Ty<'tcx>) -> Ty<'tcx>| { @@ -528,7 +528,7 @@ fn enforce_trait_manually_implementable(tcx: &ty::ctxt, sp: Span, trait_def_id: pub fn check_coherence(crate_context: &CrateCtxt) { let _task = crate_context.tcx.dep_graph.in_task(DepNode::Coherence); - let infcx = new_infer_ctxt(crate_context.tcx, &crate_context.tcx.tables, None, true); + let infcx = new_infer_ctxt(crate_context.tcx, &crate_context.tcx.tables, None); CoherenceChecker { crate_context: crate_context, inference_context: infcx, diff --git a/src/librustc_typeck/coherence/overlap.rs b/src/librustc_typeck/coherence/overlap.rs index 71c6fc1fd08..470e954781f 100644 --- a/src/librustc_typeck/coherence/overlap.rs +++ b/src/librustc_typeck/coherence/overlap.rs @@ -127,7 +127,7 @@ impl<'cx, 'tcx> OverlapChecker<'cx, 'tcx> { impl1_def_id, impl2_def_id); - let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None, false); + let infcx = infer::new_infer_ctxt(self.tcx, &self.tcx.tables, None); if let Some(trait_ref) = traits::overlapping_impls(&infcx, impl1_def_id, impl2_def_id) { self.report_overlap_error(impl1_def_id, impl2_def_id, trait_ref); } diff --git a/src/librustc_typeck/lib.rs b/src/librustc_typeck/lib.rs index 867d12a1def..acffbeabb24 100644 --- a/src/librustc_typeck/lib.rs +++ b/src/librustc_typeck/lib.rs @@ -193,7 +193,7 @@ fn require_same_types<'a, 'tcx, M>(tcx: &ty::ctxt<'tcx>, { let result = match maybe_infcx { None => { - let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None, false); + let infcx = infer::new_infer_ctxt(tcx, &tcx.tables, None); infer::mk_eqty(&infcx, t1_is_expected, TypeOrigin::Misc(span), t1, t2) } Some(infcx) => {