@@ -355,7 +355,7 @@ fn visit_fn<'tcx>(
355
355
356
356
// compute liveness
357
357
let mut lsets = Liveness :: new ( & mut fn_maps, def_id) ;
358
- let entry_ln = lsets. compute ( fk , & body, sp, id) ;
358
+ let entry_ln = lsets. compute ( & body, sp, id) ;
359
359
lsets. log_liveness ( entry_ln, id) ;
360
360
361
361
// check for various error conditions
@@ -862,13 +862,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
862
862
self . rwu_table . assign_unpacked ( idx, rwu) ;
863
863
}
864
864
865
- fn compute (
866
- & mut self ,
867
- fk : FnKind < ' _ > ,
868
- body : & hir:: Body < ' _ > ,
869
- span : Span ,
870
- id : hir:: HirId ,
871
- ) -> LiveNode {
865
+ fn compute ( & mut self , body : & hir:: Body < ' _ > , span : Span , id : hir:: HirId ) -> LiveNode {
872
866
debug ! ( "compute: using id for body, {:?}" , body. value) ;
873
867
874
868
// # Liveness of captured variables
@@ -887,7 +881,8 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
887
881
// if they are live on the entry to the closure, since only the closure
888
882
// itself can access them on subsequent calls.
889
883
890
- if let Some ( upvars) = self . ir . tcx . upvars_mentioned ( self . body_owner ) {
884
+ let upvars = self . ir . tcx . upvars_mentioned ( self . body_owner ) ;
885
+ if let Some ( upvars) = upvars {
891
886
// Mark upvars captured by reference as used after closure exits.
892
887
for ( & var_hir_id, upvar) in upvars. iter ( ) . rev ( ) {
893
888
let upvar_id = ty:: UpvarId {
@@ -906,9 +901,11 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
906
901
907
902
let succ = self . propagate_through_expr ( & body. value , self . exit_ln ) ;
908
903
909
- match fk {
910
- FnKind :: Method ( ..) | FnKind :: ItemFn ( ..) => return succ,
911
- FnKind :: Closure ( ..) => { }
904
+ if upvars. is_none ( ) {
905
+ // Either not a closure, or closure without any captured variables.
906
+ // No need to determine liveness of captured variables, since there
907
+ // are none.
908
+ return succ;
912
909
}
913
910
914
911
let ty = self . typeck_results . node_type ( id) ;
@@ -920,7 +917,7 @@ impl<'a, 'tcx> Liveness<'a, 'tcx> {
920
917
} ,
921
918
ty:: Generator ( ..) => return succ,
922
919
_ => {
923
- span_bug ! ( span, "type of closure expr {:?} is not a closure {:?}" , id, ty, ) ;
920
+ span_bug ! ( span, "{} has upvars so it should have a closure type: {:?}" , id, ty) ;
924
921
}
925
922
} ;
926
923
0 commit comments