]> git.lizzy.rs Git - rust.git/commitdiff
Adjust the handling of trait obligations and defaults to account for
authorNiko Matsakis <niko@alum.mit.edu>
Sat, 31 Jan 2015 11:33:41 +0000 (06:33 -0500)
committerNiko Matsakis <niko@alum.mit.edu>
Sun, 1 Feb 2015 11:13:06 +0000 (06:13 -0500)
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.

src/librustc_typeck/check/mod.rs
src/librustc_typeck/check/vtable.rs

index 285b4fdf2e8744e6ab5bb0fc24dab28f653b8a2f..c58377fc87bd7ac1c30fd9b0e3c3e19683df44f8 100644 (file)
@@ -493,8 +493,9 @@ fn check_bare_fn<'a, 'tcx>(ccx: &CrateCtxt<'a, 'tcx>,
             let fcx = check_fn(ccx, fn_ty.unsafety, id, &fn_sig,
                                decl, id, body, &inh);
 
-            vtable::select_all_fcx_obligations_or_error(&fcx);
+            vtable::select_all_fcx_obligations_and_apply_defaults(&fcx);
             upvar::closure_analyze_fn(&fcx, id, decl, body);
+            vtable::select_all_fcx_obligations_or_error(&fcx);
             regionck::regionck_fn(&fcx, id, decl, body);
             writeback::resolve_type_vars_in_fn(&fcx, decl, body);
         }
index 9d8eaf98569fa10882f0a9e46e30adc58e3c25b6..9921a331fa40db965277a17e73110b7a4383bb90 100644 (file)
@@ -277,15 +277,20 @@ fn check_object_type_binds_all_associated_types<'tcx>(tcx: &ty::ctxt<'tcx>,
     }
 }
 
-pub fn select_all_fcx_obligations_or_error(fcx: &FnCtxt) {
+pub fn select_all_fcx_obligations_and_apply_defaults(fcx: &FnCtxt) {
     debug!("select_all_fcx_obligations_or_error");
 
     fcx.inh.deferred_resolutions.borrow_mut()
                                 .retain(|r| !r.attempt_resolution(fcx));
-
     select_fcx_obligations_where_possible(fcx);
     fcx.default_type_parameters();
+    select_fcx_obligations_where_possible(fcx);
+}
+
+pub fn select_all_fcx_obligations_or_error(fcx: &FnCtxt) {
+    debug!("select_all_fcx_obligations_or_error");
 
+    select_all_fcx_obligations_and_apply_defaults(fcx);
     let mut fulfillment_cx = fcx.inh.fulfillment_cx.borrow_mut();
     let r = fulfillment_cx.select_all_or_error(fcx.infcx(), fcx);
     match r {