@@ -76,11 +76,9 @@ use std::cell::{Cell, RefCell, Ref};
76
76
use std:: cmp;
77
77
use std:: fmt;
78
78
use std:: hash:: { Hash , SipHasher , Hasher } ;
79
- use std:: mem;
80
79
use std:: ops;
81
80
use std:: rc:: Rc ;
82
81
use std:: vec:: IntoIter ;
83
- use collections:: enum_set:: { self , EnumSet , CLike } ;
84
82
use std:: collections:: { HashMap , HashSet } ;
85
83
use syntax:: abi;
86
84
use syntax:: ast:: { CrateNum , DefId , ItemImpl , ItemTrait , LOCAL_CRATE } ;
@@ -2059,18 +2057,44 @@ pub struct ExistentialBounds<'tcx> {
2059
2057
pub projection_bounds : Vec < PolyProjectionPredicate < ' tcx > > ,
2060
2058
}
2061
2059
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
+ }
2064
2064
2065
2065
impl 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
2068
2088
}
2069
2089
2070
- pub fn iter ( & self ) -> enum_set :: Iter < BuiltinBound > {
2090
+ pub fn iter ( & self ) -> BuiltinBoundsIter {
2071
2091
self . into_iter ( )
2072
2092
}
2073
2093
2094
+ fn is_empty ( & self ) -> bool {
2095
+ self . bits == 0
2096
+ }
2097
+
2074
2098
pub fn to_predicates < ' tcx > ( & self ,
2075
2099
tcx : & ty:: ctxt < ' tcx > ,
2076
2100
self_ty : Ty < ' tcx > ) -> Vec < Predicate < ' tcx > > {
@@ -2081,44 +2105,58 @@ impl BuiltinBounds {
2081
2105
}
2082
2106
) . collect ( )
2083
2107
}
2108
+
2109
+ pub fn is_superset ( & self , other : & BuiltinBounds ) -> bool {
2110
+ ( self . bits & other. bits ) == other. bits
2111
+ }
2084
2112
}
2085
2113
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
2089
2117
}
2090
2118
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
+ }
2093
2141
}
2094
2142
2095
2143
impl < ' a > IntoIterator for & ' a BuiltinBounds {
2096
2144
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 }
2100
2149
}
2101
2150
}
2102
2151
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 ) ]
2106
2153
pub enum BuiltinBound {
2107
2154
Send ,
2108
2155
Sized ,
2109
2156
Copy ,
2110
2157
Sync ,
2111
2158
}
2112
2159
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
-
2122
2160
#[ derive( Clone , Copy , PartialEq , Eq , Hash ) ]
2123
2161
pub struct TyVid {
2124
2162
pub index : u32
@@ -5707,7 +5745,7 @@ impl<'tcx> ctxt<'tcx> {
5707
5745
5708
5746
pub fn try_add_builtin_trait ( & self ,
5709
5747
trait_def_id : ast:: DefId ,
5710
- builtin_bounds : & mut EnumSet < BuiltinBound > )
5748
+ builtin_bounds : & mut BuiltinBounds )
5711
5749
-> bool
5712
5750
{
5713
5751
//! Checks whether `trait_ref` refers to one of the builtin
0 commit comments