@@ -6,6 +6,7 @@ pub use self::IntVarValue::*;
6
6
pub use self :: Variance :: * ;
7
7
8
8
use crate :: hir:: exports:: ExportMap ;
9
+ use crate :: hir:: place:: Place as HirPlace ;
9
10
use crate :: ich:: StableHashingContext ;
10
11
use crate :: middle:: cstore:: CrateStoreDyn ;
11
12
use crate :: middle:: resolve_lifetime:: ObjectLifetimeDefault ;
@@ -674,6 +675,12 @@ pub struct UpvarId {
674
675
pub closure_expr_id : LocalDefId ,
675
676
}
676
677
678
+ impl UpvarId {
679
+ pub fn new ( var_hir_id : hir:: HirId , closure_def_id : LocalDefId ) -> UpvarId {
680
+ UpvarId { var_path : UpvarPath { hir_id : var_hir_id } , closure_expr_id : closure_def_id }
681
+ }
682
+ }
683
+
677
684
#[ derive( Clone , PartialEq , Debug , TyEncodable , TyDecodable , Copy , HashStable ) ]
678
685
pub enum BorrowKind {
679
686
/// Data must be immutable and is aliasable.
@@ -756,9 +763,40 @@ pub struct UpvarBorrow<'tcx> {
756
763
pub region : ty:: Region < ' tcx > ,
757
764
}
758
765
766
+ #[ derive( PartialEq , Clone , Debug , Copy , TyEncodable , TyDecodable , HashStable ) ]
767
+ pub struct CaptureInfo < ' tcx > {
768
+ /// Expr Id pointing to use that resulting in selecting the current capture kind
769
+ pub expr_id : Option < hir:: HirId > ,
770
+
771
+ /// Capture mode that was selected
772
+ pub capture_kind : UpvarCapture < ' tcx > ,
773
+ }
774
+
759
775
pub type UpvarListMap = FxHashMap < DefId , FxIndexMap < hir:: HirId , UpvarId > > ;
760
776
pub type UpvarCaptureMap < ' tcx > = FxHashMap < UpvarId , UpvarCapture < ' tcx > > ;
761
777
778
+ /// Consider closure where s.str1 is captured via an ImmutableBorrow and s.str2 via a MutableBorrow
779
+ ///
780
+ /// ```rust
781
+ /// // Assume that thte HirId for the variable definition is `V1`
782
+ /// let mut s = SomeStruct { str1: format!("s1"), str2: format!("s2") }
783
+ ///
784
+ /// let fix_s = |new_s2| {
785
+ /// // Assume that the HirId for the expression `s.str1` is `E1`
786
+ /// println!("Updating SomeStruct with str1=", s.str1);
787
+ /// // Assume that the HirId for the expression `*s.str2` is `E2`
788
+ /// s.str2 = new_s2;
789
+ /// }
790
+ /// ```
791
+ ///
792
+ /// For closure `fix_s`, (at a high level) the IndexMap will contain:
793
+ ///
794
+ /// Place { V1, [ProjectionKind::Field(Index=0, Variant=0)] } : CaptureKind { E1, ImmutableBorrow }
795
+ /// Place { V1, [ProjectionKind::Field(Index=1, Variant=0)] } : CaptureKind { E2, MutableBorrow }
796
+ ///
797
+ pub type CaptureInformationMap < ' tcx > =
798
+ FxHashMap < DefId , FxIndexMap < HirPlace < ' tcx > , CaptureInfo < ' tcx > > > ;
799
+
762
800
#[ derive( Clone , Copy , PartialEq , Eq ) ]
763
801
pub enum IntVarValue {
764
802
IntType ( ast:: IntTy ) ,
0 commit comments