@@ -376,6 +376,7 @@ struct Builder<'a, 'gcx: 'a+'tcx, 'tcx: 'a> {
376
376
local_decls : IndexVec < Local , LocalDecl < ' tcx > > ,
377
377
canonical_user_type_annotations : ty:: CanonicalUserTypeAnnotations < ' tcx > ,
378
378
upvar_decls : Vec < UpvarDecl > ,
379
+ upvar_mutbls : Vec < Mutability > ,
379
380
unit_temp : Option < Place < ' tcx > > ,
380
381
381
382
/// Cached block with the `RESUME` terminator; this is created
@@ -625,6 +626,7 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
625
626
let fn_def_id = tcx_hir. local_def_id_from_hir_id ( fn_id) ;
626
627
627
628
// Gather the upvars of a closure, if any.
629
+ let mut upvar_mutbls = vec ! [ ] ;
628
630
// In analyze_closure() in upvar.rs we gathered a list of upvars used by a
629
631
// closure and we stored in a map called upvar_list in TypeckTables indexed
630
632
// with the closure's DefId. Here, we run through that vec of UpvarIds for
@@ -644,24 +646,24 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
644
646
} ;
645
647
let mut decl = UpvarDecl {
646
648
debug_name : keywords:: Invalid . name ( ) ,
647
- var_hir_id : ClearCrossCrate :: Set ( var_hir_id) ,
648
649
by_ref,
649
- mutability : Mutability :: Not ,
650
650
} ;
651
+ let mut mutability = Mutability :: Not ;
651
652
if let Some ( Node :: Binding ( pat) ) = tcx_hir. find ( var_node_id) {
652
653
if let hir:: PatKind :: Binding ( _, _, ident, _) = pat. node {
653
654
decl. debug_name = ident. name ;
654
655
if let Some ( & bm) = hir. tables . pat_binding_modes ( ) . get ( pat. hir_id ) {
655
656
if bm == ty:: BindByValue ( hir:: MutMutable ) {
656
- decl . mutability = Mutability :: Mut ;
657
+ mutability = Mutability :: Mut ;
657
658
} else {
658
- decl . mutability = Mutability :: Not ;
659
+ mutability = Mutability :: Not ;
659
660
}
660
661
} else {
661
662
tcx. sess . delay_span_bug ( pat. span , "missing binding mode" ) ;
662
663
}
663
664
}
664
665
}
666
+ upvar_mutbls. push ( mutability) ;
665
667
decl
666
668
} )
667
669
. collect ( ) ;
@@ -672,7 +674,8 @@ fn construct_fn<'a, 'gcx, 'tcx, A>(hir: Cx<'a, 'gcx, 'tcx>,
672
674
safety,
673
675
return_ty,
674
676
return_ty_span,
675
- upvar_decls) ;
677
+ upvar_decls,
678
+ upvar_mutbls) ;
676
679
677
680
let call_site_scope = region:: Scope {
678
681
id : body. value . hir_id . local_id ,
@@ -734,7 +737,7 @@ fn construct_const<'a, 'gcx, 'tcx>(
734
737
let ty = hir. tables ( ) . expr_ty_adjusted ( ast_expr) ;
735
738
let owner_id = tcx. hir ( ) . body_owner ( body_id) ;
736
739
let span = tcx. hir ( ) . span ( owner_id) ;
737
- let mut builder = Builder :: new ( hir, span, 0 , Safety :: Safe , ty, ty_span, vec ! [ ] ) ;
740
+ let mut builder = Builder :: new ( hir, span, 0 , Safety :: Safe , ty, ty_span, vec ! [ ] , vec ! [ ] ) ;
738
741
739
742
let mut block = START_BLOCK ;
740
743
let expr = builder. hir . mirror ( ast_expr) ;
@@ -762,7 +765,7 @@ fn construct_error<'a, 'gcx, 'tcx>(hir: Cx<'a, 'gcx, 'tcx>,
762
765
let owner_id = hir. tcx ( ) . hir ( ) . body_owner ( body_id) ;
763
766
let span = hir. tcx ( ) . hir ( ) . span ( owner_id) ;
764
767
let ty = hir. tcx ( ) . types . err ;
765
- let mut builder = Builder :: new ( hir, span, 0 , Safety :: Safe , ty, span, vec ! [ ] ) ;
768
+ let mut builder = Builder :: new ( hir, span, 0 , Safety :: Safe , ty, span, vec ! [ ] , vec ! [ ] ) ;
766
769
let source_info = builder. source_info ( span) ;
767
770
builder. cfg . terminate ( START_BLOCK , source_info, TerminatorKind :: Unreachable ) ;
768
771
builder. finish ( None )
@@ -775,7 +778,8 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
775
778
safety : Safety ,
776
779
return_ty : Ty < ' tcx > ,
777
780
return_span : Span ,
778
- upvar_decls : Vec < UpvarDecl > )
781
+ upvar_decls : Vec < UpvarDecl > ,
782
+ upvar_mutbls : Vec < Mutability > )
779
783
-> Builder < ' a , ' gcx , ' tcx > {
780
784
let lint_level = LintLevel :: Explicit ( hir. root_lint_level ) ;
781
785
let mut builder = Builder {
@@ -798,6 +802,7 @@ impl<'a, 'gcx, 'tcx> Builder<'a, 'gcx, 'tcx> {
798
802
) ,
799
803
canonical_user_type_annotations : IndexVec :: new ( ) ,
800
804
upvar_decls,
805
+ upvar_mutbls,
801
806
var_indices : Default :: default ( ) ,
802
807
unit_temp : None ,
803
808
cached_resume_block : None ,
0 commit comments