@@ -844,7 +844,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
844
844
// has static lifetime.
845
845
} else {
846
846
// Variables being referenced must outlive closure.
847
- constrain_free_variables_in_stack_closure (
847
+ constrain_free_variables_in_by_ref_closure (
848
848
rcx, bounds. region_bound , expr, freevars) ;
849
849
850
850
// Closure is stack allocated and hence cannot
@@ -856,20 +856,17 @@ fn check_expr_fn_block(rcx: &mut Rcx,
856
856
} ) ;
857
857
}
858
858
ty:: ty_unboxed_closure( _, region) => {
859
- ty:: with_freevars ( tcx, expr. id , |freevars| {
860
- // No free variables means that there is no environment and
861
- // hence the closure has static lifetime. Otherwise, the
862
- // closure must not outlive the variables it closes over
863
- // by-reference.
864
- //
865
- // NDM -- this seems wrong, discuss with pcwalton, should
866
- // be straightforward enough.
867
- if !freevars. is_empty ( ) {
868
- let bounds = ty:: region_existential_bound ( region) ;
869
- ensure_free_variable_types_outlive_closure_bound (
870
- rcx, bounds, expr, freevars) ;
871
- }
872
- } )
859
+ let bounds = ty:: region_existential_bound ( region) ;
860
+ if tcx. capture_modes . borrow ( ) . get_copy ( & expr. id ) == ast:: CaptureByRef {
861
+ ty:: with_freevars ( tcx, expr. id , |freevars| {
862
+ if !freevars. is_empty ( ) {
863
+ // Variables being referenced must be constrained and registered
864
+ // in the upvar borrow map
865
+ constrain_free_variables_in_by_ref_closure (
866
+ rcx, bounds. region_bound , expr, freevars) ;
867
+ }
868
+ } )
869
+ }
873
870
}
874
871
_ => { }
875
872
}
@@ -884,6 +881,13 @@ fn check_expr_fn_block(rcx: &mut Rcx,
884
881
propagate_upupvar_borrow_kind ( rcx, expr, freevars) ;
885
882
} )
886
883
}
884
+ ty:: ty_unboxed_closure( ..) => {
885
+ if tcx. capture_modes . borrow ( ) . get_copy ( & expr. id ) == ast:: CaptureByRef {
886
+ ty:: with_freevars ( tcx, expr. id , |freevars| {
887
+ propagate_upupvar_borrow_kind ( rcx, expr, freevars) ;
888
+ } ) ;
889
+ }
890
+ }
887
891
_ => { }
888
892
}
889
893
@@ -893,6 +897,12 @@ fn check_expr_fn_block(rcx: &mut Rcx,
893
897
ensure_free_variable_types_outlive_closure_bound ( rcx, bounds, expr, freevars) ;
894
898
} )
895
899
}
900
+ ty:: ty_unboxed_closure( _, region) => {
901
+ ty:: with_freevars ( tcx, expr. id , |freevars| {
902
+ let bounds = ty:: region_existential_bound ( region) ;
903
+ ensure_free_variable_types_outlive_closure_bound ( rcx, bounds, expr, freevars) ;
904
+ } )
905
+ }
896
906
_ => { }
897
907
}
898
908
@@ -959,7 +969,7 @@ fn check_expr_fn_block(rcx: &mut Rcx,
959
969
}
960
970
}
961
971
962
- fn constrain_free_variables_in_stack_closure (
972
+ fn constrain_free_variables_in_by_ref_closure (
963
973
rcx : & mut Rcx ,
964
974
region_bound : ty:: Region ,
965
975
expr : & ast:: Expr ,
0 commit comments