@@ -637,14 +637,15 @@ pub fn trans_trait_callee_from_llval(bcx: block,
637
637
val_str(bcx.ccx().tn, llpair));
638
638
let llvtable = Load(bcx,
639
639
PointerCast(bcx,
640
- GEPi(bcx, llpair, [0u, 0u]),
640
+ GEPi(bcx, llpair,
641
+ [0u, abi::trt_field_vtable]),
641
642
T_ptr(T_ptr(T_vtable()))));
642
643
643
644
// Load the box from the @Trait pair and GEP over the box header if
644
645
// necessary:
645
646
let mut llself;
646
647
debug!(" ( translating trait callee) loading second index from pair");
647
- let llbox = Load(bcx, GEPi(bcx, llpair, [0u, 1u ]));
648
+ let llbox = Load(bcx, GEPi(bcx, llpair, [0u, abi::trt_field_box ]));
648
649
649
650
// Munge `llself` appropriately for the type of `self` in the method.
650
651
let self_mode;
@@ -845,27 +846,30 @@ pub fn trans_trait_cast(bcx: block,
845
846
846
847
match store {
847
848
ty:: RegionTraitStore ( _) | ty:: BoxTraitStore => {
848
- let mut llboxdest = GEPi ( bcx, lldest, [ 0 u, 1 u] ) ;
849
- // Just store the pointer into the pair.
849
+ let mut llboxdest = GEPi ( bcx, lldest, [ 0 u, abi:: trt_field_box] ) ;
850
+ // Just store the pointer into the pair. (Region/borrowed
851
+ // and boxed trait objects are represented as pairs, and
852
+ // have no type descriptor field.)
850
853
llboxdest = PointerCast ( bcx,
851
854
llboxdest,
852
855
T_ptr ( type_of( bcx. ccx( ) , v_ty) ) ) ;
853
856
bcx = expr:: trans_into( bcx, val, SaveIn ( llboxdest) ) ;
854
857
}
855
858
ty:: UniqTraitStore => {
856
- // Translate the uniquely-owned value into the second element of
857
- // the triple. (The first element is the vtable.)
858
- let mut llvaldest = GEPi ( bcx, lldest, [ 0 , 1 ] ) ;
859
+ // Translate the uniquely-owned value in the
860
+ // triple. (Unique trait objects are represented as
861
+ // triples.)
862
+ let mut llvaldest = GEPi ( bcx, lldest, [ 0 , abi:: trt_field_box] ) ;
859
863
llvaldest = PointerCast ( bcx,
860
864
llvaldest,
861
865
T_ptr ( type_of( bcx. ccx( ) , v_ty) ) ) ;
862
866
bcx = expr:: trans_into( bcx, val, SaveIn ( llvaldest) ) ;
863
867
864
- // Get the type descriptor of the wrapped value and store it into
865
- // the third element of the triple as well.
868
+ // Get the type descriptor of the wrapped value and store
869
+ // it in the triple as well.
866
870
let tydesc = get_tydesc( bcx. ccx( ) , v_ty) ;
867
871
glue:: lazily_emit_all_tydesc_glue( bcx. ccx( ) , tydesc) ;
868
- let lltydescdest = GEPi ( bcx, lldest, [ 0 , 2 ] ) ;
872
+ let lltydescdest = GEPi ( bcx, lldest, [ 0 , abi :: trt_field_tydesc ] ) ;
869
873
Store ( bcx, tydesc. tydesc, lltydescdest) ;
870
874
}
871
875
}
@@ -875,7 +879,7 @@ pub fn trans_trait_cast(bcx: block,
875
879
let orig = resolve_vtable_in_fn_ctxt( bcx. fcx, orig) ;
876
880
let vtable = get_vtable( bcx. ccx( ) , orig) ;
877
881
Store ( bcx, vtable, PointerCast ( bcx,
878
- GEPi ( bcx, lldest, [ 0 u, 0 u ] ) ,
882
+ GEPi ( bcx, lldest, [ 0 u, abi :: trt_field_vtable ] ) ,
879
883
T_ptr ( val_ty( vtable) ) ) ) ;
880
884
881
885
bcx
0 commit comments