@@ -26,6 +26,7 @@ use util::ppaux::{note_and_explain_region, bound_region_to_str};
26
26
use util:: ppaux:: { trait_store_to_str, ty_to_str, vstore_to_str} ;
27
27
use util:: ppaux:: Repr ;
28
28
use util:: common:: { indenter} ;
29
+ use util:: enum_set:: { EnumSet , CLike } ;
29
30
30
31
use core;
31
32
use core:: ptr:: to_unsafe_ptr;
@@ -58,8 +59,6 @@ pub struct field {
58
59
mt : mt
59
60
}
60
61
61
- pub type param_bounds = @~[ param_bound ] ;
62
-
63
62
pub struct method {
64
63
ident : ast:: ident ,
65
64
generics : ty:: Generics ,
@@ -655,12 +654,32 @@ pub enum type_err {
655
654
}
656
655
657
656
#[ deriving( Eq , IterBytes ) ]
658
- pub enum param_bound {
659
- bound_copy,
660
- bound_durable,
661
- bound_owned,
662
- bound_const,
663
- bound_trait( @TraitRef ) ,
657
+ pub struct ParamBounds {
658
+ builtin_bounds : BuiltinBounds ,
659
+ trait_bounds : ~[ @TraitRef ]
660
+ }
661
+
662
+ pub type BuiltinBounds = EnumSet < BuiltinBound > ;
663
+
664
+ #[ deriving( Eq , IterBytes ) ]
665
+ pub enum BuiltinBound {
666
+ BoundCopy ,
667
+ BoundStatic ,
668
+ BoundOwned ,
669
+ BoundConst ,
670
+ }
671
+
672
+ pub fn EmptyBuiltinBounds ( ) -> BuiltinBounds {
673
+ EnumSet :: empty ( )
674
+ }
675
+
676
+ impl CLike for BuiltinBound {
677
+ pub fn to_uint ( & self ) -> uint {
678
+ * self as uint
679
+ }
680
+ pub fn from_uint ( v : uint ) -> BuiltinBound {
681
+ unsafe { cast:: transmute ( v) }
682
+ }
664
683
}
665
684
666
685
#[ deriving( Eq ) ]
@@ -817,7 +836,7 @@ impl to_bytes::IterBytes for RegionVid {
817
836
818
837
pub struct TypeParameterDef {
819
838
def_id : ast:: def_id ,
820
- bounds : param_bounds
839
+ bounds : @ ParamBounds
821
840
}
822
841
823
842
/// Information about the type/lifetime parametesr associated with an item.
@@ -1497,14 +1516,6 @@ pub fn substs_to_str(cx: ctxt, substs: &substs) -> ~str {
1497
1516
substs. repr ( cx)
1498
1517
}
1499
1518
1500
- pub fn param_bound_to_str ( cx : ctxt , pb : & param_bound ) -> ~str {
1501
- pb. repr ( cx)
1502
- }
1503
-
1504
- pub fn param_bounds_to_str ( cx : ctxt , pbs : param_bounds ) -> ~str {
1505
- pbs. repr ( cx)
1506
- }
1507
-
1508
1519
pub fn subst ( cx : ctxt ,
1509
1520
substs : & substs ,
1510
1521
typ : t )
@@ -1795,6 +1806,19 @@ pub struct TypeContents {
1795
1806
}
1796
1807
1797
1808
pub impl TypeContents {
1809
+ fn meets_bounds(&self, cx: ctxt, bbs: BuiltinBounds) -> bool {
1810
+ iter::all(|bb| self.meets_bound(cx, bb), |f| bbs.each(f))
1811
+ }
1812
+
1813
+ fn meets_bound(&self, cx: ctxt, bb: BuiltinBound) -> bool {
1814
+ match bb {
1815
+ BoundCopy => self.is_copy(cx),
1816
+ BoundStatic => self.is_static(cx),
1817
+ BoundConst => self.is_const(cx),
1818
+ BoundOwned => self.is_owned(cx)
1819
+ }
1820
+ }
1821
+
1798
1822
fn intersects(&self, tc: TypeContents) -> bool {
1799
1823
(self.bits & tc.bits) != 0
1800
1824
}
@@ -1808,11 +1832,11 @@ pub impl TypeContents {
1808
1832
TC_EMPTY_ENUM
1809
1833
}
1810
1834
1811
- fn is_durable (&self, cx: ctxt) -> bool {
1812
- !self.intersects(TypeContents::nondurable (cx))
1835
+ fn is_static (&self, cx: ctxt) -> bool {
1836
+ !self.intersects(TypeContents::nonstatic (cx))
1813
1837
}
1814
1838
1815
- fn nondurable (_cx: ctxt) -> TypeContents {
1839
+ fn nonstatic (_cx: ctxt) -> TypeContents {
1816
1840
TC_BORROWED_POINTER
1817
1841
}
1818
1842
@@ -1917,8 +1941,8 @@ pub fn type_is_copyable(cx: ctxt, t: ty::t) -> bool {
1917
1941
type_contents(cx, t).is_copy(cx)
1918
1942
}
1919
1943
1920
- pub fn type_is_durable (cx: ctxt, t: ty::t) -> bool {
1921
- type_contents(cx, t).is_durable (cx)
1944
+ pub fn type_is_static (cx: ctxt, t: ty::t) -> bool {
1945
+ type_contents(cx, t).is_static (cx)
1922
1946
}
1923
1947
1924
1948
pub fn type_is_owned(cx: ctxt, t: ty::t) -> bool {
@@ -2198,19 +2222,19 @@ pub fn type_contents(cx: ctxt, ty: t) -> TypeContents {
2198
2222
debug!(" type_param_def_to_contents( %s) ", type_param_def.repr(cx));
2199
2223
let _i = indenter();
2200
2224
2201
- let r = type_param_def.bounds.foldl(TC_ALL, |tc, bound| {
2225
+ let mut tc = TC_ALL;
2226
+ for type_param_def.bounds.builtin_bounds.each |bound| {
2202
2227
debug!(" tc = %s, bound = %?", tc.to_str(), bound);
2203
- match *bound {
2204
- bound_copy => tc - TypeContents::nonimplicitly_copyable(cx),
2205
- bound_durable => tc - TypeContents::nondurable(cx),
2206
- bound_owned => tc - TypeContents::nonowned(cx),
2207
- bound_const => tc - TypeContents::nonconst(cx),
2208
- bound_trait(_) => *tc
2209
- }
2210
- });
2228
+ tc = tc - match bound {
2229
+ BoundCopy => TypeContents::nonimplicitly_copyable(cx),
2230
+ BoundStatic => TypeContents::nonstatic(cx),
2231
+ BoundOwned => TypeContents::nonowned(cx),
2232
+ BoundConst => TypeContents::nonconst(cx),
2233
+ };
2234
+ }
2211
2235
2212
- debug!(" result = %s", r .to_str());
2213
- return r ;
2236
+ debug!(" result = %s", tc .to_str());
2237
+ return tc ;
2214
2238
}
2215
2239
}
2216
2240
@@ -3577,7 +3601,7 @@ pub fn trait_supertraits(cx: ctxt,
3577
3601
pub fn trait_ref_supertraits ( cx : ctxt , trait_ref : & ty:: TraitRef ) -> ~[ @TraitRef ] {
3578
3602
let supertrait_refs = trait_supertraits ( cx, trait_ref. def_id ) ;
3579
3603
supertrait_refs. map (
3580
- |supertrait_ref| @ supertrait_ref. subst ( cx, & trait_ref. substs ) )
3604
+ |supertrait_ref| supertrait_ref. subst ( cx, & trait_ref. substs ) )
3581
3605
}
3582
3606
3583
3607
fn lookup_locally_or_in_crate_store < V : Copy > (
@@ -4261,18 +4285,9 @@ pub fn determine_inherited_purity(parent: (ast::purity, ast::node_id),
4261
4285
// relation on the supertraits from each bounded trait's constraint
4262
4286
// list.
4263
4287
pub fn each_bound_trait_and_supertraits(tcx: ctxt,
4264
- bounds: param_bounds,
4265
- f: &fn(&TraitRef) -> bool) {
4266
- for bounds.each |bound| {
4267
- let bound_trait_ref = match *bound {
4268
- ty::bound_trait(bound_t) => bound_t,
4269
-
4270
- ty::bound_copy | ty::bound_owned |
4271
- ty::bound_const | ty::bound_durable => {
4272
- loop; // skip non-trait bounds
4273
- }
4274
- };
4275
-
4288
+ bounds: &ParamBounds,
4289
+ f: &fn(@TraitRef) -> bool) {
4290
+ for bounds.trait_bounds.each |&bound_trait_ref| {
4276
4291
let mut supertrait_set = HashMap::new();
4277
4292
let mut trait_refs = ~[];
4278
4293
let mut i = 0;
0 commit comments