@@ -836,7 +836,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
836
836
// has static lifetime.
837
837
} else {
838
838
// Variables being referenced must outlive closure.
839
- constrain_free_variables_in_stack_closure (
839
+ constrain_free_variables_in_by_ref_closure (
840
840
rcx, bounds. region_bound , expr, freevars) ;
841
841
842
842
// Closure is stack allocated and hence cannot
@@ -848,20 +848,17 @@ fn check_expr_fn_block(rcx: &mut Rcx,
848
848
} ) ;
849
849
}
850
850
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
+ }
865
862
}
866
863
_ => { }
867
864
}
@@ -876,6 +873,13 @@ fn check_expr_fn_block(rcx: &mut Rcx,
876
873
propagate_upupvar_borrow_kind ( rcx, expr, freevars) ;
877
874
} )
878
875
}
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
+ }
879
883
_ => { }
880
884
}
881
885
@@ -885,6 +889,12 @@ fn check_expr_fn_block(rcx: &mut Rcx,
885
889
ensure_free_variable_types_outlive_closure_bound ( rcx, bounds, expr, freevars) ;
886
890
} )
887
891
}
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
+ }
888
898
_ => { }
889
899
}
890
900
@@ -951,7 +961,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
951
961
}
952
962
}
953
963
954
- fn constrain_free_variables_in_stack_closure (
964
+ fn constrain_free_variables_in_by_ref_closure (
955
965
rcx : & mut Rcx ,
956
966
region_bound : ty:: Region ,
957
967
expr : & ast:: Expr ,
0 commit comments