Skip to content

Commit

Permalink
move drain_fulfillment_cx_or_panic to be private to traits::trans
Browse files Browse the repository at this point in the history
  • Loading branch information
nikomatsakis committed Mar 13, 2018
1 parent e4728e4 commit 0a2ac85
Show file tree
Hide file tree
Showing 2 changed files with 44 additions and 40 deletions.
40 changes: 0 additions & 40 deletions src/librustc/infer/mod.rs
Expand Up @@ -493,46 +493,6 @@ pub struct CombinedSnapshot<'a, 'tcx:'a> {
}

impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// Finishes processes any obligations that remain in the
/// fulfillment context, and then returns the result with all type
/// variables removed and regions erased. Because this is intended
/// for use after type-check has completed, if any errors occur,
/// it will panic. It is used during normalization and other cases
/// where processing the obligations in `fulfill_cx` may cause
/// type inference variables that appear in `result` to be
/// unified, and hence we need to process those obligations to get
/// the complete picture of the type.
pub fn drain_fulfillment_cx_or_panic<T>(&self,
span: Span,
fulfill_cx: &mut traits::FulfillmentContext<'tcx>,
result: &T)
-> T::Lifted
where T: TypeFoldable<'tcx> + ty::Lift<'gcx>
{
debug!("drain_fulfillment_cx_or_panic()");

// In principle, we only need to do this so long as `result`
// contains unbound type parameters. It could be a slight
// optimization to stop iterating early.
match fulfill_cx.select_all_or_error(self) {
Ok(()) => { }
Err(errors) => {
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
errors);
}
}

let result = self.resolve_type_vars_if_possible(result);
let result = self.tcx.erase_regions(&result);

match self.tcx.lift_to_global(&result) {
Some(result) => result,
None => {
span_bug!(span, "Uninferred types/regions in `{:?}`", result);
}
}
}

pub fn is_in_snapshot(&self) -> bool {
self.in_snapshot.get()
}
Expand Down
44 changes: 44 additions & 0 deletions src/librustc/traits/trans/mod.rs
Expand Up @@ -17,6 +17,8 @@ use dep_graph::{DepKind, DepTrackingMapConfig};
use std::marker::PhantomData;
use syntax_pos::DUMMY_SP;
use hir::def_id::DefId;
use infer::InferCtxt;
use syntax_pos::Span;
use traits::{FulfillmentContext, Obligation, ObligationCause, SelectionContext, Vtable};
use ty::{self, Ty, TyCtxt};
use ty::subst::{Subst, Substs};
Expand Down Expand Up @@ -151,3 +153,45 @@ impl<'gcx> DepTrackingMapConfig for ProjectionCache<'gcx> {
DepKind::TraitSelect
}
}

impl<'a, 'gcx, 'tcx> InferCtxt<'a, 'gcx, 'tcx> {
/// Finishes processes any obligations that remain in the
/// fulfillment context, and then returns the result with all type
/// variables removed and regions erased. Because this is intended
/// for use after type-check has completed, if any errors occur,
/// it will panic. It is used during normalization and other cases
/// where processing the obligations in `fulfill_cx` may cause
/// type inference variables that appear in `result` to be
/// unified, and hence we need to process those obligations to get
/// the complete picture of the type.
fn drain_fulfillment_cx_or_panic<T>(&self,
span: Span,
fulfill_cx: &mut FulfillmentContext<'tcx>,
result: &T)
-> T::Lifted
where T: TypeFoldable<'tcx> + ty::Lift<'gcx>
{
debug!("drain_fulfillment_cx_or_panic()");

// In principle, we only need to do this so long as `result`
// contains unbound type parameters. It could be a slight
// optimization to stop iterating early.
match fulfill_cx.select_all_or_error(self) {
Ok(()) => { }
Err(errors) => {
span_bug!(span, "Encountered errors `{:?}` resolving bounds after type-checking",
errors);
}
}

let result = self.resolve_type_vars_if_possible(result);
let result = self.tcx.erase_regions(&result);

match self.tcx.lift_to_global(&result) {
Some(result) => result,
None => {
span_bug!(span, "Uninferred types/regions in `{:?}`", result);
}
}
}
}

0 comments on commit 0a2ac85

Please sign in to comment.