@@ -377,10 +377,18 @@ impl ToInteriorKind for mc::InteriorKind {
377377 }
378378}
379379
380+ // This can be:
381+ // - a pointer dereference (`*LV` in README.md)
382+ // - a field reference, with an optional definition of the containing
383+ // enum variant (`LV.f` in README.md)
384+ // `DefId` is present when the field is part of struct that is in
385+ // a variant of an enum. For instance in:
386+ // `enum E { X { foo: u32 }, Y { foo: u32 }}`
387+ // each `foo` is qualified by the definitition id of the variant (`X` or `Y`).
380388#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
381389pub enum LoanPathElem {
382- LpDeref ( mc:: PointerKind ) , // `*LV` in README.md
383- LpInterior ( InteriorKind ) , // `LV.f` in README.md
390+ LpDeref ( mc:: PointerKind ) ,
391+ LpInterior ( Option < DefId > , InteriorKind ) ,
384392}
385393
386394pub fn closure_to_block ( closure_id : ast:: NodeId ,
@@ -413,8 +421,9 @@ impl<'tcx> LoanPath<'tcx> {
413421
414422 fn has_fork ( & self , other : & LoanPath < ' tcx > ) -> bool {
415423 match ( & self . kind , & other. kind ) {
416- ( & LpExtend ( ref base, _, LpInterior ( id) ) , & LpExtend ( ref base2, _, LpInterior ( id2) ) ) =>
417- if id == id2 {
424+ ( & LpExtend ( ref base, _, LpInterior ( opt_variant_id, id) ) ,
425+ & LpExtend ( ref base2, _, LpInterior ( opt_variant_id2, id2) ) ) =>
426+ if id == id2 && opt_variant_id == opt_variant_id2 {
418427 base. has_fork ( & * * base2)
419428 } else {
420429 true
@@ -428,23 +437,23 @@ impl<'tcx> LoanPath<'tcx> {
428437 fn depth ( & self ) -> usize {
429438 match self . kind {
430439 LpExtend ( ref base, _, LpDeref ( _) ) => base. depth ( ) ,
431- LpExtend ( ref base, _, LpInterior ( _) ) => base. depth ( ) + 1 ,
440+ LpExtend ( ref base, _, LpInterior ( _, _ ) ) => base. depth ( ) + 1 ,
432441 _ => 0 ,
433442 }
434443 }
435444
436445 fn common ( & self , other : & LoanPath < ' tcx > ) -> Option < LoanPath < ' tcx > > {
437446 match ( & self . kind , & other. kind ) {
438- ( & LpExtend ( ref base, a, LpInterior ( id) ) ,
439- & LpExtend ( ref base2, _, LpInterior ( id2) ) ) => {
440- if id == id2 {
447+ ( & LpExtend ( ref base, a, LpInterior ( opt_variant_id , id) ) ,
448+ & LpExtend ( ref base2, _, LpInterior ( opt_variant_id2 , id2) ) ) => {
449+ if id == id2 && opt_variant_id == opt_variant_id2 {
441450 base. common ( & * * base2) . map ( |x| {
442451 let xd = x. depth ( ) ;
443452 if base. depth ( ) == xd && base2. depth ( ) == xd {
444453 assert_eq ! ( base. ty, base2. ty) ;
445454 assert_eq ! ( self . ty, other. ty) ;
446455 LoanPath {
447- kind : LpExtend ( Rc :: new ( x) , a, LpInterior ( id) ) ,
456+ kind : LpExtend ( Rc :: new ( x) , a, LpInterior ( opt_variant_id , id) ) ,
448457 ty : self . ty ,
449458 }
450459 } else {
@@ -509,7 +518,11 @@ pub fn opt_loan_path<'tcx>(cmt: &mc::cmt<'tcx>) -> Option<Rc<LoanPath<'tcx>>> {
509518
510519 Categorization :: Interior ( ref cmt_base, ik) => {
511520 opt_loan_path ( cmt_base) . map ( |lp| {
512- new_lp ( LpExtend ( lp, cmt. mutbl , LpInterior ( ik. cleaned ( ) ) ) )
521+ let opt_variant_id = match cmt_base. cat {
522+ Categorization :: Downcast ( _, did) => Some ( did) ,
523+ _ => None
524+ } ;
525+ new_lp ( LpExtend ( lp, cmt. mutbl , LpInterior ( opt_variant_id, ik. cleaned ( ) ) ) )
513526 } )
514527 }
515528
@@ -1068,7 +1081,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10681081 }
10691082
10701083
1071- LpExtend ( ref lp_base, _, LpInterior ( InteriorField ( fname) ) ) => {
1084+ LpExtend ( ref lp_base, _, LpInterior ( _ , InteriorField ( fname) ) ) => {
10721085 self . append_autoderefd_loan_path_to_string ( & * * lp_base, out) ;
10731086 match fname {
10741087 mc:: NamedField ( fname) => {
@@ -1082,7 +1095,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
10821095 }
10831096 }
10841097
1085- LpExtend ( ref lp_base, _, LpInterior ( InteriorElement ( ..) ) ) => {
1098+ LpExtend ( ref lp_base, _, LpInterior ( _ , InteriorElement ( ..) ) ) => {
10861099 self . append_autoderefd_loan_path_to_string ( & * * lp_base, out) ;
10871100 out. push_str ( "[..]" ) ;
10881101 }
@@ -1210,7 +1223,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
12101223 write ! ( f, "{:?}.*" , lp)
12111224 }
12121225
1213- LpExtend ( ref lp, _, LpInterior ( ref interior) ) => {
1226+ LpExtend ( ref lp, _, LpInterior ( _ , ref interior) ) => {
12141227 write ! ( f, "{:?}.{:?}" , lp, interior)
12151228 }
12161229 }
@@ -1242,7 +1255,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> {
12421255 write ! ( f, "{}.*" , lp)
12431256 }
12441257
1245- LpExtend ( ref lp, _, LpInterior ( ref interior) ) => {
1258+ LpExtend ( ref lp, _, LpInterior ( _ , ref interior) ) => {
12461259 write ! ( f, "{}.{:?}" , lp, interior)
12471260 }
12481261 }
0 commit comments