@@ -836,7 +836,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
836836 // has static lifetime.
837837 } else {
838838 // Variables being referenced must outlive closure.
839- constrain_free_variables_in_stack_closure (
839+ constrain_free_variables_in_by_ref_closure (
840840 rcx, bounds. region_bound , expr, freevars) ;
841841
842842 // Closure is stack allocated and hence cannot
@@ -848,20 +848,17 @@ fn check_expr_fn_block(rcx: &mut Rcx,
848848 } ) ;
849849 }
850850 ty:: ty_unboxed_closure( _, region) => {
851- ty:: with_freevars ( tcx, expr. id , |freevars| {
852- // No free variables means that there is no environment and
853- // hence the closure has static lifetime. Otherwise, the
854- // closure must not outlive the variables it closes over
855- // by-reference.
856- //
857- // NDM -- this seems wrong, discuss with pcwalton, should
858- // be straightforward enough.
859- if !freevars. is_empty ( ) {
860- let bounds = ty:: region_existential_bound ( region) ;
861- ensure_free_variable_types_outlive_closure_bound (
862- rcx, bounds, expr, freevars) ;
863- }
864- } )
851+ let bounds = ty:: region_existential_bound ( region) ;
852+ if tcx. capture_modes . borrow ( ) . get_copy ( & expr. id ) == ast:: CaptureByRef {
853+ ty:: with_freevars ( tcx, expr. id , |freevars| {
854+ if !freevars. is_empty ( ) {
855+ // Variables being referenced must be constrained and registered
856+ // in the upvar borrow map
857+ constrain_free_variables_in_by_ref_closure (
858+ rcx, bounds. region_bound , expr, freevars) ;
859+ }
860+ } )
861+ }
865862 }
866863 _ => { }
867864 }
@@ -876,6 +873,13 @@ fn check_expr_fn_block(rcx: &mut Rcx,
876873 propagate_upupvar_borrow_kind ( rcx, expr, freevars) ;
877874 } )
878875 }
876+ ty:: ty_unboxed_closure( ..) => {
877+ if tcx. capture_modes . borrow ( ) . get_copy ( & expr. id ) == ast:: CaptureByRef {
878+ ty:: with_freevars ( tcx, expr. id , |freevars| {
879+ propagate_upupvar_borrow_kind ( rcx, expr, freevars) ;
880+ } ) ;
881+ }
882+ }
879883 _ => { }
880884 }
881885
@@ -885,6 +889,12 @@ fn check_expr_fn_block(rcx: &mut Rcx,
885889 ensure_free_variable_types_outlive_closure_bound ( rcx, bounds, expr, freevars) ;
886890 } )
887891 }
892+ ty:: ty_unboxed_closure( _, region) => {
893+ ty:: with_freevars ( tcx, expr. id , |freevars| {
894+ let bounds = ty:: region_existential_bound ( region) ;
895+ ensure_free_variable_types_outlive_closure_bound ( rcx, bounds, expr, freevars) ;
896+ } )
897+ }
888898 _ => { }
889899 }
890900
@@ -951,7 +961,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
951961 }
952962 }
953963
954- fn constrain_free_variables_in_stack_closure (
964+ fn constrain_free_variables_in_by_ref_closure (
955965 rcx : & mut Rcx ,
956966 region_bound : ty:: Region ,
957967 expr : & ast:: Expr ,
0 commit comments