Skip to content

Commit 92f9476

Browse files
committed
Adjust the handling of trait obligations and defaults to account for
upvar inference. Upvar inference can cause some obligations to be deferred, notably things like `F : Sized` where `F` is a closure type, or `F : FnMut`. Adjust the ordering therefore so that we process all traits and apply fallback, do upvar inference, and only then start reporting errors for outstanding obligations.
1 parent f5281e2 commit 92f9476

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/librustc_typeck/check/mod.rs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -493,8 +493,9 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
493493
let fcx = check_fn(ccx, fn_ty.unsafety, id, &fn_sig,
494494
decl, id, body, &inh);
495495

496-
vtable::select_all_fcx_obligations_or_error(&fcx);
496+
vtable::select_all_fcx_obligations_and_apply_defaults(&fcx);
497497
upvar::closure_analyze_fn(&fcx, id, decl, body);
498+
vtable::select_all_fcx_obligations_or_error(&fcx);
498499
regionck::regionck_fn(&fcx, id, decl, body);
499500
writeback::resolve_type_vars_in_fn(&fcx, decl, body);
500501
}

src/librustc_typeck/check/vtable.rs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -277,15 +277,20 @@ fn check_object_type_binds_all_associated_types<'tcx>(tcx: &ty::ctxt<'tcx>,
277277
}
278278
}
279279

280-
pub fn select_all_fcx_obligations_or_error(fcx: &FnCtxt) {
280+
pub fn select_all_fcx_obligations_and_apply_defaults(fcx: &FnCtxt) {
281281
debug!("select_all_fcx_obligations_or_error");
282282

283283
fcx.inh.deferred_resolutions.borrow_mut()
284284
.retain(|r| !r.attempt_resolution(fcx));
285-
286285
select_fcx_obligations_where_possible(fcx);
287286
fcx.default_type_parameters();
287+
select_fcx_obligations_where_possible(fcx);
288+
}
289+
290+
pub fn select_all_fcx_obligations_or_error(fcx: &FnCtxt) {
291+
debug!("select_all_fcx_obligations_or_error");
288292

293+
select_all_fcx_obligations_and_apply_defaults(fcx);
289294
let mut fulfillment_cx = fcx.inh.fulfillment_cx.borrow_mut();
290295
let r = fulfillment_cx.select_all_or_error(fcx.infcx(), fcx);
291296
match r {

0 commit comments

Comments
 (0)