@@ -76,11 +76,9 @@ use std::cell::{Cell, RefCell, Ref};
7676use std:: cmp;
7777use std:: fmt;
7878use std:: hash:: { Hash , SipHasher , Hasher } ;
79- use std:: mem;
8079use std:: ops;
8180use std:: rc:: Rc ;
8281use std:: vec:: IntoIter ;
83- use collections:: enum_set:: { self , EnumSet , CLike } ;
8482use std:: collections:: { HashMap , HashSet } ;
8583use syntax:: abi;
8684use syntax:: ast:: { CrateNum , DefId , ItemImpl , ItemTrait , LOCAL_CRATE } ;
@@ -2059,18 +2057,44 @@ pub struct ExistentialBounds<'tcx> {
20592057 pub projection_bounds : Vec < PolyProjectionPredicate < ' tcx > > ,
20602058}
20612059
2062- #[ derive( Clone , Copy , PartialEq , Eq , Hash , Debug ) ]
2063- pub struct BuiltinBounds ( EnumSet < BuiltinBound > ) ;
2060+ #[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
2061+ pub struct BuiltinBounds {
2062+ bits : u8
2063+ }
20642064
20652065impl BuiltinBounds {
2066- pub fn empty ( ) -> BuiltinBounds {
2067- BuiltinBounds ( EnumSet :: new ( ) )
2066+ pub fn empty ( ) -> BuiltinBounds {
2067+ BuiltinBounds { bits : 0 }
2068+ }
2069+
2070+ pub fn insert ( & mut self , bound : BuiltinBound ) {
2071+ self . bits = match bound {
2072+ BuiltinBound :: Send => self . bits | 0b0000_0001 ,
2073+ BuiltinBound :: Sized => self . bits | 0b0000_0010 ,
2074+ BuiltinBound :: Copy => self . bits | 0b0000_0100 ,
2075+ BuiltinBound :: Sync => self . bits | 0b0000_1000 ,
2076+ }
2077+ }
2078+
2079+ pub fn contains ( & self , bound : BuiltinBound ) -> bool {
2080+ let bit = match bound {
2081+ BuiltinBound :: Send => self . bits ,
2082+ BuiltinBound :: Sized => self . bits >> 1 ,
2083+ BuiltinBound :: Copy => self . bits >> 2 ,
2084+ BuiltinBound :: Sync => self . bits >> 3
2085+ } ;
2086+
2087+ ( bit & 0b0000_0001 ) == 1
20682088 }
20692089
2070- pub fn iter ( & self ) -> enum_set :: Iter < BuiltinBound > {
2090+ pub fn iter ( & self ) -> BuiltinBoundsIter {
20712091 self . into_iter ( )
20722092 }
20732093
2094+ fn is_empty ( & self ) -> bool {
2095+ self . bits == 0
2096+ }
2097+
20742098 pub fn to_predicates < ' tcx > ( & self ,
20752099 tcx : & ty:: ctxt < ' tcx > ,
20762100 self_ty : Ty < ' tcx > ) -> Vec < Predicate < ' tcx > > {
@@ -2081,44 +2105,58 @@ impl BuiltinBounds {
20812105 }
20822106 ) . collect ( )
20832107 }
2108+
2109+ pub fn is_superset ( & self , other : & BuiltinBounds ) -> bool {
2110+ ( self . bits & other. bits ) == other. bits
2111+ }
20842112}
20852113
2086- impl ops :: Deref for BuiltinBounds {
2087- type Target = EnumSet < BuiltinBound > ;
2088- fn deref ( & self ) -> & Self :: Target { & self . 0 }
2114+ pub struct BuiltinBoundsIter {
2115+ bounds : BuiltinBounds ,
2116+ index : u8
20892117}
20902118
2091- impl ops:: DerefMut for BuiltinBounds {
2092- fn deref_mut ( & mut self ) -> & mut Self :: Target { & mut self . 0 }
2119+ impl Iterator for BuiltinBoundsIter {
2120+ type Item = BuiltinBound ;
2121+
2122+ fn next ( & mut self ) -> Option < BuiltinBound > {
2123+ while self . index < 4 {
2124+ let result = match self . index {
2125+ 0 if self . bounds . contains ( BuiltinBound :: Send ) => Some ( BuiltinBound :: Send ) ,
2126+ 1 if self . bounds . contains ( BuiltinBound :: Sized ) => Some ( BuiltinBound :: Sized ) ,
2127+ 2 if self . bounds . contains ( BuiltinBound :: Copy ) => Some ( BuiltinBound :: Copy ) ,
2128+ 3 if self . bounds . contains ( BuiltinBound :: Sync ) => Some ( BuiltinBound :: Sync ) ,
2129+ _ => None
2130+ } ;
2131+
2132+ self . index += 1 ;
2133+
2134+ if result. is_some ( ) {
2135+ return result;
2136+ }
2137+ }
2138+
2139+ return None ;
2140+ }
20932141}
20942142
20952143impl < ' a > IntoIterator for & ' a BuiltinBounds {
20962144 type Item = BuiltinBound ;
2097- type IntoIter = enum_set:: Iter < BuiltinBound > ;
2098- fn into_iter ( self ) -> Self :: IntoIter {
2099- ( * * self ) . into_iter ( )
2145+ type IntoIter = BuiltinBoundsIter ;
2146+
2147+ fn into_iter ( self ) -> BuiltinBoundsIter {
2148+ BuiltinBoundsIter { bounds : self . clone ( ) , index : 0 }
21002149 }
21012150}
21022151
2103- #[ derive( Clone , RustcEncodable , PartialEq , Eq , RustcDecodable , Hash ,
2104- Debug , Copy ) ]
2105- #[ repr( usize ) ]
2152+ #[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , RustcDecodable , RustcEncodable , Hash , Debug ) ]
21062153pub enum BuiltinBound {
21072154 Send ,
21082155 Sized ,
21092156 Copy ,
21102157 Sync ,
21112158}
21122159
2113- impl CLike for BuiltinBound {
2114- fn to_usize ( & self ) -> usize {
2115- * self as usize
2116- }
2117- fn from_usize ( v : usize ) -> BuiltinBound {
2118- unsafe { mem:: transmute ( v) }
2119- }
2120- }
2121-
21222160#[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
21232161pub struct TyVid {
21242162 pub index : u32
@@ -5707,7 +5745,7 @@ impl<'tcx> ctxt<'tcx> {
57075745
57085746 pub fn try_add_builtin_trait ( & self ,
57095747 trait_def_id : ast:: DefId ,
5710- builtin_bounds : & mut EnumSet < BuiltinBound > )
5748+ builtin_bounds : & mut BuiltinBounds )
57115749 -> bool
57125750 {
57135751 //! Checks whether `trait_ref` refers to one of the builtin
0 commit comments