@@ -377,10 +377,18 @@ impl ToInteriorKind for mc::InteriorKind {
377
377
}
378
378
}
379
379
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`).
380
388
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
381
389
pub 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 ) ,
384
392
}
385
393
386
394
pub fn closure_to_block ( closure_id : ast:: NodeId ,
@@ -413,8 +421,9 @@ impl<'tcx> LoanPath<'tcx> {
413
421
414
422
fn has_fork ( & self , other : & LoanPath < ' tcx > ) -> bool {
415
423
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 {
418
427
base. has_fork ( & * * base2)
419
428
} else {
420
429
true
@@ -428,23 +437,23 @@ impl<'tcx> LoanPath<'tcx> {
428
437
fn depth ( & self ) -> usize {
429
438
match self . kind {
430
439
LpExtend ( ref base, _, LpDeref ( _) ) => base. depth ( ) ,
431
- LpExtend ( ref base, _, LpInterior ( _) ) => base. depth ( ) + 1 ,
440
+ LpExtend ( ref base, _, LpInterior ( _, _ ) ) => base. depth ( ) + 1 ,
432
441
_ => 0 ,
433
442
}
434
443
}
435
444
436
445
fn common ( & self , other : & LoanPath < ' tcx > ) -> Option < LoanPath < ' tcx > > {
437
446
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 {
441
450
base. common ( & * * base2) . map ( |x| {
442
451
let xd = x. depth ( ) ;
443
452
if base. depth ( ) == xd && base2. depth ( ) == xd {
444
453
assert_eq ! ( base. ty, base2. ty) ;
445
454
assert_eq ! ( self . ty, other. ty) ;
446
455
LoanPath {
447
- kind : LpExtend ( Rc :: new ( x) , a, LpInterior ( id) ) ,
456
+ kind : LpExtend ( Rc :: new ( x) , a, LpInterior ( opt_variant_id , id) ) ,
448
457
ty : self . ty ,
449
458
}
450
459
} else {
@@ -509,7 +518,11 @@ pub fn opt_loan_path<'tcx>(cmt: &mc::cmt<'tcx>) -> Option<Rc<LoanPath<'tcx>>> {
509
518
510
519
Categorization :: Interior ( ref cmt_base, ik) => {
511
520
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 ( ) ) ) )
513
526
} )
514
527
}
515
528
@@ -1068,7 +1081,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1068
1081
}
1069
1082
1070
1083
1071
- LpExtend ( ref lp_base, _, LpInterior ( InteriorField ( fname) ) ) => {
1084
+ LpExtend ( ref lp_base, _, LpInterior ( _ , InteriorField ( fname) ) ) => {
1072
1085
self . append_autoderefd_loan_path_to_string ( & * * lp_base, out) ;
1073
1086
match fname {
1074
1087
mc:: NamedField ( fname) => {
@@ -1082,7 +1095,7 @@ impl<'a, 'tcx> BorrowckCtxt<'a, 'tcx> {
1082
1095
}
1083
1096
}
1084
1097
1085
- LpExtend ( ref lp_base, _, LpInterior ( InteriorElement ( ..) ) ) => {
1098
+ LpExtend ( ref lp_base, _, LpInterior ( _ , InteriorElement ( ..) ) ) => {
1086
1099
self . append_autoderefd_loan_path_to_string ( & * * lp_base, out) ;
1087
1100
out. push_str ( "[..]" ) ;
1088
1101
}
@@ -1210,7 +1223,7 @@ impl<'tcx> fmt::Debug for LoanPath<'tcx> {
1210
1223
write ! ( f, "{:?}.*" , lp)
1211
1224
}
1212
1225
1213
- LpExtend ( ref lp, _, LpInterior ( ref interior) ) => {
1226
+ LpExtend ( ref lp, _, LpInterior ( _ , ref interior) ) => {
1214
1227
write ! ( f, "{:?}.{:?}" , lp, interior)
1215
1228
}
1216
1229
}
@@ -1242,7 +1255,7 @@ impl<'tcx> fmt::Display for LoanPath<'tcx> {
1242
1255
write ! ( f, "{}.*" , lp)
1243
1256
}
1244
1257
1245
- LpExtend ( ref lp, _, LpInterior ( ref interior) ) => {
1258
+ LpExtend ( ref lp, _, LpInterior ( _ , ref interior) ) => {
1246
1259
write ! ( f, "{}.{:?}" , lp, interior)
1247
1260
}
1248
1261
}
0 commit comments