@@ -208,6 +208,10 @@ pub struct Inherited<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
208
208
209
209
fulfillment_cx : RefCell < Box < dyn TraitEngine < ' tcx > > > ,
210
210
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
+
211
215
// When we process a call like `c()` where `c` is a closure type,
212
216
// we may not have decided yet whether `c` is a `Fn`, `FnMut`, or
213
217
// `FnOnce` closure. In that case, we defer full resolution of the
@@ -644,6 +648,7 @@ impl<'a, 'gcx, 'tcx> Inherited<'a, 'gcx, 'tcx> {
644
648
infcx,
645
649
fulfillment_cx : RefCell :: new ( TraitEngine :: new ( tcx) ) ,
646
650
locals : RefCell :: new ( Default :: default ( ) ) ,
651
+ deferred_sized_obligations : RefCell :: new ( Vec :: new ( ) ) ,
647
652
deferred_call_resolutions : RefCell :: new ( Default :: default ( ) ) ,
648
653
deferred_cast_checks : RefCell :: new ( Vec :: new ( ) ) ,
649
654
deferred_generator_interiors : RefCell :: new ( Vec :: new ( ) ) ,
@@ -907,6 +912,10 @@ fn typeck_tables_of<'a, 'tcx>(tcx: TyCtxt<'a, 'tcx, 'tcx>,
907
912
fcx. closure_analyze ( body) ;
908
913
assert ! ( fcx. deferred_call_resolutions. borrow( ) . is_empty( ) ) ;
909
914
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
+ }
910
919
fcx. select_all_obligations_or_error ( ) ;
911
920
912
921
if fn_decl. is_some ( ) {
@@ -2345,6 +2354,14 @@ impl<'a, 'gcx, 'tcx> FnCtxt<'a, 'gcx, 'tcx> {
2345
2354
self . require_type_meets ( ty, span, code, lang_item) ;
2346
2355
}
2347
2356
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
+
2348
2365
pub fn register_bound ( & self ,
2349
2366
ty : Ty < ' tcx > ,
2350
2367
def_id : DefId ,
0 commit comments