@@ -208,6 +208,10 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
208208
209209 fulfillment_cx : RefCell < Box < dyn TraitEngine < ' tcx > > > ,
210210
211+ // Some additional `Sized` obligations badly affect type inference.
212+ // These obligations are added in a later stage of typeck.
213+ deferred_sized_obligations : RefCell < Vec < ( Ty < ' tcx > , Span , traits:: ObligationCauseCode < ' tcx > ) > > ,
214+
211215 // When we process a call like `c()` where `c` is a closure type,
212216 // we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
213217 // `FnOnce` closure. In that case, we defer full resolution of the
@@ -644,6 +648,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
644648 infcx,
645649 fulfillment_cx : RefCell :: new ( TraitEngine :: new ( tcx) ) ,
646650 locals : RefCell :: new ( Default :: default ( ) ) ,
651+ deferred_sized_obligations : RefCell :: new ( Vec :: new ( ) ) ,
647652 deferred_call_resolutions : RefCell :: new ( Default :: default ( ) ) ,
648653 deferred_cast_checks : RefCell :: new ( Vec :: new ( ) ) ,
649654 deferred_generator_interiors : RefCell :: new ( Vec :: new ( ) ) ,
@@ -907,6 +912,10 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
907912 fcx. closure_analyze ( body) ;
908913 assert ! ( fcx. deferred_call_resolutions. borrow( ) . is_empty( ) ) ;
909914 fcx. resolve_generator_interiors ( def_id) ;
915+
916+ for ( ty, span, code) in fcx. deferred_sized_obligations . borrow_mut ( ) . drain ( ..) {
917+ fcx. require_type_is_sized ( ty, span, code) ;
918+ }
910919 fcx. select_all_obligations_or_error ( ) ;
911920
912921 if fn_decl. is_some ( ) {
@@ -2345,6 +2354,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
23452354 self . require_type_meets ( ty, span, code, lang_item) ;
23462355 }
23472356
2357+ pub fn require_type_is_sized_deferred ( & self ,
2358+ ty : Ty < ' tcx > ,
2359+ span : Span ,
2360+ code : traits:: ObligationCauseCode < ' tcx > )
2361+ {
2362+ self . deferred_sized_obligations . borrow_mut ( ) . push ( ( ty, span, code) ) ;
2363+ }
2364+
23482365 pub fn register_bound ( & self ,
23492366 ty : Ty < ' tcx > ,
23502367 def_id : DefId ,
0 commit comments