@@ -6,6 +6,7 @@ pub use self::IntVarValue::*;
66pub use self :: Variance :: * ;
77
88use crate :: hir:: exports:: ExportMap ;
9+ use crate :: hir:: place:: Place as HirPlace ;
910use crate :: ich:: StableHashingContext ;
1011use crate :: middle:: cstore:: CrateStoreDyn ;
1112use crate :: middle:: resolve_lifetime:: ObjectLifetimeDefault ;
@@ -674,6 +675,12 @@ pub struct UpvarId {
674675 pub closure_expr_id : LocalDefId ,
675676}
676677
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+
677684#[ derive( Clone , PartialEq , Debug , TyEncodable , TyDecodable , Copy , HashStable ) ]
678685pub enum BorrowKind {
679686 /// Data must be immutable and is aliasable.
@@ -756,9 +763,40 @@ pub struct UpvarBorrow<'tcx> {
756763 pub region : ty:: Region < ' tcx > ,
757764}
758765
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+
759775pub type UpvarListMap = FxHashMap < DefId , FxIndexMap < hir:: HirId , UpvarId > > ;
760776pub type UpvarCaptureMap < ' tcx > = FxHashMap < UpvarId , UpvarCapture < ' tcx > > ;
761777
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+
762800#[ derive( Clone , Copy , PartialEq , Eq ) ]
763801pub enum IntVarValue {
764802 IntType ( ast:: IntTy ) ,
0 commit comments