@@ -70,12 +70,15 @@ use util::nodemap::{NodeMap, NodeSet, DefIdMap, DefIdSet};
70
70
use util:: nodemap:: FnvHashMap ;
71
71
use util:: num:: ToPrimitive ;
72
72
73
+ use rustc_data_structures:: bitset:: { U8BitSet , BitSet , BitSetIter } ;
74
+
73
75
use arena:: TypedArena ;
74
76
use std:: borrow:: { Borrow , Cow } ;
75
77
use std:: cell:: { Cell , RefCell , Ref } ;
76
78
use std:: cmp;
77
79
use std:: fmt;
78
80
use std:: hash:: { Hash , SipHasher , Hasher } ;
81
+ use std:: mem;
79
82
use std:: ops;
80
83
use std:: rc:: Rc ;
81
84
use std:: vec:: IntoIter ;
@@ -2059,28 +2062,28 @@ pub struct ExistentialBounds<'tcx> {
2059
2062
2060
2063
#[ derive( Copy , Clone , PartialEq , Eq , Hash , Debug ) ]
2061
2064
pub struct BuiltinBounds {
2062
- bits : u8
2065
+ bit_set : U8BitSet
2063
2066
}
2064
2067
2065
2068
impl BuiltinBounds {
2066
2069
pub fn empty ( ) -> BuiltinBounds {
2067
- BuiltinBounds { bits : 0 }
2070
+ BuiltinBounds { bit_set : BitSet :: empty ( ) }
2068
2071
}
2069
2072
2070
2073
pub fn insert ( & mut self , bound : BuiltinBound ) {
2071
- self . bits |= 1 << ( bound as u8 ) ;
2074
+ self . bit_set . insert ( bound as u8 )
2072
2075
}
2073
2076
2074
2077
pub fn contains ( & self , bound : BuiltinBound ) -> bool {
2075
- ( ( self . bits >> ( bound as u8 ) ) & 1 ) == 1
2078
+ self . bit_set . contains ( bound as u8 )
2076
2079
}
2077
2080
2078
2081
pub fn iter ( & self ) -> BuiltinBoundsIter {
2079
2082
self . into_iter ( )
2080
2083
}
2081
2084
2082
2085
fn is_empty ( & self ) -> bool {
2083
- self . bits == 0
2086
+ self . bit_set . is_empty ( )
2084
2087
}
2085
2088
2086
2089
pub fn to_predicates < ' tcx > ( & self ,
@@ -2095,36 +2098,19 @@ impl BuiltinBounds {
2095
2098
}
2096
2099
2097
2100
pub fn is_superset ( & self , other : & BuiltinBounds ) -> bool {
2098
- ( self . bits & other . bits ) == other. bits
2101
+ self . bit_set . is_superset ( other. bit_set )
2099
2102
}
2100
2103
}
2101
2104
2102
2105
pub struct BuiltinBoundsIter {
2103
- bounds : BuiltinBounds ,
2104
- index : u8
2106
+ bit_set : BitSetIter < u8 >
2105
2107
}
2106
2108
2107
2109
impl Iterator for BuiltinBoundsIter {
2108
2110
type Item = BuiltinBound ;
2109
2111
2110
2112
fn next ( & mut self ) -> Option < BuiltinBound > {
2111
- while self . index < 4 {
2112
- let result = match self . index {
2113
- 0 if self . bounds . contains ( BuiltinBound :: Send ) => Some ( BuiltinBound :: Send ) ,
2114
- 1 if self . bounds . contains ( BuiltinBound :: Sized ) => Some ( BuiltinBound :: Sized ) ,
2115
- 2 if self . bounds . contains ( BuiltinBound :: Copy ) => Some ( BuiltinBound :: Copy ) ,
2116
- 3 if self . bounds . contains ( BuiltinBound :: Sync ) => Some ( BuiltinBound :: Sync ) ,
2117
- _ => None
2118
- } ;
2119
-
2120
- self . index += 1 ;
2121
-
2122
- if result. is_some ( ) {
2123
- return result;
2124
- }
2125
- }
2126
-
2127
- return None ;
2113
+ self . bit_set . next ( ) . map ( |b| unsafe { mem:: transmute ( b) } )
2128
2114
}
2129
2115
}
2130
2116
@@ -2133,10 +2119,11 @@ impl<'a> IntoIterator for &'a BuiltinBounds {
2133
2119
type IntoIter = BuiltinBoundsIter ;
2134
2120
2135
2121
fn into_iter ( self ) -> BuiltinBoundsIter {
2136
- BuiltinBoundsIter { bounds : self . clone ( ) , index : 0 }
2122
+ BuiltinBoundsIter { bit_set : self . bit_set . into_iter ( ) }
2137
2123
}
2138
2124
}
2139
2125
2126
+ #[ repr( u8 ) ]
2140
2127
#[ derive( Copy , Clone , PartialEq , Eq , PartialOrd , Ord , RustcDecodable , RustcEncodable , Hash , Debug ) ]
2141
2128
pub enum BuiltinBound {
2142
2129
Send ,
0 commit comments