@@ -378,14 +378,14 @@ pub fn type_of_adjust(cx: &ctxt, adj: &AutoAdjustment) -> Option<t> {
378
378
fn type_of_autoref ( cx : & ctxt , autoref : & AutoRef ) -> Option < t > {
379
379
match autoref {
380
380
& AutoUnsize ( ref k) => match k {
381
- & UnsizeVtable ( TyTrait { def_id , ref substs , bounds } , _) => {
382
- Some ( mk_trait ( cx, def_id , substs . clone ( ) , bounds) )
381
+ & UnsizeVtable ( TyTrait { ref principal , bounds } , _) => {
382
+ Some ( mk_trait ( cx, ( * principal ) . clone ( ) , bounds) )
383
383
}
384
384
_ => None
385
385
} ,
386
386
& AutoUnsizeUniq ( ref k) => match k {
387
- & UnsizeVtable ( TyTrait { def_id , ref substs , bounds } , _) => {
388
- Some ( mk_uniq ( cx, mk_trait ( cx, def_id , substs . clone ( ) , bounds) ) )
387
+ & UnsizeVtable ( TyTrait { ref principal , bounds } , _) => {
388
+ Some ( mk_uniq ( cx, mk_trait ( cx, ( * principal ) . clone ( ) , bounds) ) )
389
389
}
390
390
_ => None
391
391
} ,
@@ -983,12 +983,12 @@ pub enum sty {
983
983
984
984
#[ deriving( Clone , PartialEq , Eq , Hash , Show ) ]
985
985
pub struct TyTrait {
986
- pub def_id : DefId ,
987
- pub substs : Substs ,
986
+ // Principal trait reference.
987
+ pub principal : TraitRef , // would use Rc<TraitRef>, but it runs afoul of some static rules
988
988
pub bounds : ExistentialBounds
989
989
}
990
990
991
- #[ deriving( PartialEq , Eq , Hash , Show ) ]
991
+ #[ deriving( Clone , PartialEq , Eq , Hash , Show ) ]
992
992
pub struct TraitRef {
993
993
pub def_id : DefId ,
994
994
pub substs : Substs ,
@@ -1643,8 +1643,8 @@ pub fn mk_t(cx: &ctxt, st: sty) -> t {
1643
1643
& ty_enum( _, ref substs) | & ty_struct( _, ref substs) => {
1644
1644
flags = flags | sflags ( substs) ;
1645
1645
}
1646
- & ty_trait( box TyTrait { ref substs , ref bounds, .. } ) => {
1647
- flags = flags | sflags ( substs) ;
1646
+ & ty_trait( box TyTrait { ref principal , ref bounds } ) => {
1647
+ flags = flags | sflags ( & principal . substs ) ;
1648
1648
flags = flags | flags_for_bounds ( bounds) ;
1649
1649
}
1650
1650
& ty_uniq( tt) | & ty_vec( tt, _) | & ty_open( tt) => {
@@ -1874,14 +1874,12 @@ pub fn mk_ctor_fn(cx: &ctxt,
1874
1874
1875
1875
1876
1876
pub fn mk_trait ( cx : & ctxt ,
1877
- did : ast:: DefId ,
1878
- substs : Substs ,
1877
+ principal : ty:: TraitRef ,
1879
1878
bounds : ExistentialBounds )
1880
1879
-> t {
1881
1880
// take a copy of substs so that we own the vectors inside
1882
1881
let inner = box TyTrait {
1883
- def_id : did,
1884
- substs : substs,
1882
+ principal : principal,
1885
1883
bounds : bounds
1886
1884
} ;
1887
1885
mk_t ( cx, ty_trait ( inner) )
@@ -1934,9 +1932,15 @@ pub fn maybe_walk_ty(ty: t, f: |t| -> bool) {
1934
1932
ty_ptr( ref tm) | ty_rptr( _, ref tm) => {
1935
1933
maybe_walk_ty ( tm. ty , f) ;
1936
1934
}
1937
- ty_enum( _, ref substs) | ty_struct( _, ref substs) | ty_unboxed_closure( _, _, ref substs) |
1938
- ty_trait( box TyTrait { ref substs, .. } ) => {
1939
- for subty in ( * substs) . types . iter ( ) {
1935
+ ty_trait( box TyTrait { ref principal, .. } ) => {
1936
+ for subty in principal. substs . types . iter ( ) {
1937
+ maybe_walk_ty ( * subty, |x| f ( x) ) ;
1938
+ }
1939
+ }
1940
+ ty_enum( _, ref substs) |
1941
+ ty_struct( _, ref substs) |
1942
+ ty_unboxed_closure( _, _, ref substs) => {
1943
+ for subty in substs. types . iter ( ) {
1940
1944
maybe_walk_ty ( * subty, |x| f ( x) ) ;
1941
1945
}
1942
1946
}
@@ -3554,8 +3558,8 @@ pub fn unsize_ty(cx: &ctxt,
3554
3558
format ! ( "UnsizeStruct with bad sty: {}" ,
3555
3559
ty_to_string( cx, ty) ) . as_slice ( ) )
3556
3560
} ,
3557
- & UnsizeVtable ( TyTrait { def_id , ref substs , bounds } , _) => {
3558
- mk_trait ( cx, def_id , substs . clone ( ) , bounds)
3561
+ & UnsizeVtable ( TyTrait { ref principal , bounds } , _) => {
3562
+ mk_trait ( cx, ( * principal ) . clone ( ) , bounds)
3559
3563
}
3560
3564
}
3561
3565
}
@@ -3808,7 +3812,7 @@ pub fn ty_sort_string(cx: &ctxt, t: t) -> String {
3808
3812
ty_bare_fn( _) => "extern fn" . to_string ( ) ,
3809
3813
ty_closure( _) => "fn" . to_string ( ) ,
3810
3814
ty_trait( ref inner) => {
3811
- format ! ( "trait {}" , item_path_str( cx, inner. def_id) )
3815
+ format ! ( "trait {}" , item_path_str( cx, inner. principal . def_id) )
3812
3816
}
3813
3817
ty_struct( id, _) => {
3814
3818
format ! ( "struct {}" , item_path_str( cx, id) )
@@ -4230,11 +4234,14 @@ pub fn try_add_builtin_trait(
4230
4234
4231
4235
pub fn ty_to_def_id ( ty : t ) -> Option < ast:: DefId > {
4232
4236
match get ( ty) . sty {
4233
- ty_trait( box TyTrait { def_id : id, .. } ) |
4237
+ ty_trait( ref tt) =>
4238
+ Some ( tt. principal . def_id ) ,
4234
4239
ty_struct( id, _) |
4235
4240
ty_enum( id, _) |
4236
- ty_unboxed_closure( id, _, _) => Some ( id) ,
4237
- _ => None
4241
+ ty_unboxed_closure( id, _, _) =>
4242
+ Some ( id) ,
4243
+ _ =>
4244
+ None
4238
4245
}
4239
4246
}
4240
4247
@@ -5213,9 +5220,9 @@ pub fn hash_crate_independent(tcx: &ctxt, t: t, svh: &Svh) -> u64 {
5213
5220
}
5214
5221
}
5215
5222
}
5216
- ty_trait( box TyTrait { def_id : d , bounds, .. } ) => {
5223
+ ty_trait( box TyTrait { ref principal , bounds } ) => {
5217
5224
byte ! ( 17 ) ;
5218
- did ( & mut state, d ) ;
5225
+ did ( & mut state, principal . def_id ) ;
5219
5226
hash ! ( bounds) ;
5220
5227
}
5221
5228
ty_struct( d, _) => {
@@ -5504,12 +5511,13 @@ pub fn accumulate_lifetimes_in_type(accumulator: &mut Vec<ty::Region>,
5504
5511
typ : t ) {
5505
5512
walk_ty ( typ, |typ| {
5506
5513
match get ( typ) . sty {
5507
- ty_rptr( region, _) => accumulator. push ( region) ,
5514
+ ty_rptr( region, _) => {
5515
+ accumulator. push ( region)
5516
+ }
5517
+ ty_trait( ref t) => {
5518
+ accumulator. push_all ( t. principal . substs . regions ( ) . as_slice ( ) ) ;
5519
+ }
5508
5520
ty_enum( _, ref substs) |
5509
- ty_trait( box TyTrait {
5510
- ref substs,
5511
- ..
5512
- } ) |
5513
5521
ty_struct( _, ref substs) => {
5514
5522
accum_substs ( accumulator, substs) ;
5515
5523
}
0 commit comments