Skip to content

Commit

Permalink
Add require_type_is_sized_deferred.
Browse files Browse the repository at this point in the history
  • Loading branch information
qnighy committed Nov 21, 2018
1 parent 289ad6e commit 682b33a
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions src/librustc_typeck/check/mod.rs
Expand Up @@ -208,6 +208,10 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {

fulfillment_cx: RefCell<Box<dyn TraitEngine<'tcx>>>,

// Some additional `Sized` obligations badly affect type inference.
// These obligations are added in a later stage of typeck.
deferred_sized_obligations: RefCell<Vec<(Ty<'tcx>, Span, traits::ObligationCauseCode<'tcx>)>>,

// When we process a call like `c()` where `c` is a closure type,
// we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
// `FnOnce` closure. In that case, we defer full resolution of the
Expand Down Expand Up @@ -644,6 +648,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
infcx,
fulfillment_cx: RefCell::new(TraitEngine::new(tcx)),
locals: RefCell::new(Default::default()),
deferred_sized_obligations: RefCell::new(Vec::new()),
deferred_call_resolutions: RefCell::new(Default::default()),
deferred_cast_checks: RefCell::new(Vec::new()),
deferred_generator_interiors: RefCell::new(Vec::new()),
Expand Down Expand Up @@ -907,6 +912,10 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
fcx.closure_analyze(body);
assert!(fcx.deferred_call_resolutions.borrow().is_empty());
fcx.resolve_generator_interiors(def_id);

for (ty, span, code) in fcx.deferred_sized_obligations.borrow_mut().drain(..) {
fcx.require_type_is_sized(ty, span, code);
}
fcx.select_all_obligations_or_error();

if fn_decl.is_some() {
Expand Down Expand Up @@ -2345,6 +2354,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
self.require_type_meets(ty, span, code, lang_item);
}

pub fn require_type_is_sized_deferred(&self,
ty: Ty<'tcx>,
span: Span,
code: traits::ObligationCauseCode<'tcx>)
{
self.deferred_sized_obligations.borrow_mut().push((ty, span, code));
}

pub fn register_bound(&self,
ty: Ty<'tcx>,
def_id: DefId,
Expand Down

0 comments on commit 682b33a

Please sign in to comment.