Skip to content

Commit 4ca2f7a

Browse files
committed
Deprecate EnumSet and remove its final use in rustc
1 parent 7fc0675 commit 4ca2f7a

File tree

6 files changed

+76
-34
lines changed

6 files changed

+76
-34
lines changed

src/libcollections/enum_set.rs

+4-3
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,11 @@
1313
//! This module defines a container which uses an efficient bit mask
1414
//! representation to hold C-like enum variants.
1515
16+
#![deprecated(reason = "EnumSet has been deprecated",
17+
since = "1.2.0")]
1618
#![unstable(feature = "enumset",
17-
reason = "matches collection reform specification, \
18-
waiting for dust to settle")]
19-
19+
reason = "deprecated")]
20+
#![allow(deprecated)]
2021
use core::prelude::*;
2122
use core::marker;
2223
use core::fmt;

src/libcollections/lib.rs

+1
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,7 @@ pub use bit_set::BitSet;
8282
pub use btree_map::BTreeMap;
8383
pub use btree_set::BTreeSet;
8484
pub use linked_list::LinkedList;
85+
#[allow(deprecated)]
8586
pub use enum_set::EnumSet;
8687
pub use vec_deque::VecDeque;
8788
pub use string::String;

src/librustc/lib.rs

-1
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,6 @@
3535
#![feature(duration)]
3636
#![feature(duration_span)]
3737
#![feature(dynamic_lib)]
38-
#![feature(enumset)]
3938
#![feature(fs_canonicalize)]
4039
#![feature(hash_default)]
4140
#![feature(hashmap_hasher)]

src/librustc/middle/traits/select.rs

+2-2
Original file line numberDiff line numberDiff line change
@@ -1343,7 +1343,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
13431343
ty::TyTrait(ref data) => {
13441344
match self.tcx().lang_items.to_builtin_kind(obligation.predicate.def_id()) {
13451345
Some(bound @ ty::BoundSend) | Some(bound @ ty::BoundSync) => {
1346-
if data.bounds.builtin_bounds.contains(&bound) {
1346+
if data.bounds.builtin_bounds.contains(bound) {
13471347
debug!("assemble_candidates_from_object_ty: matched builtin bound, \
13481348
pushing candidate");
13491349
candidates.vec.push(BuiltinObjectCandidate);
@@ -1632,7 +1632,7 @@ impl<'cx, 'tcx> SelectionContext<'cx, 'tcx> {
16321632
match bound {
16331633
ty::BoundSized => Err(Unimplemented),
16341634
ty::BoundCopy => {
1635-
if data.bounds.builtin_bounds.contains(&bound) {
1635+
if data.bounds.builtin_bounds.contains(bound) {
16361636
ok_if(Vec::new())
16371637
} else {
16381638
// Recursively check all supertraits to find out if any further

src/librustc/middle/ty.rs

+66-28
Original file line numberDiff line numberDiff line change
@@ -76,11 +76,9 @@ use std::cell::{Cell, RefCell, Ref};
7676
use std::cmp;
7777
use std::fmt;
7878
use std::hash::{Hash, SipHasher, Hasher};
79-
use std::mem;
8079
use std::ops;
8180
use std::rc::Rc;
8281
use std::vec::IntoIter;
83-
use collections::enum_set::{self, EnumSet, CLike};
8482
use std::collections::{HashMap, HashSet};
8583
use syntax::abi;
8684
use 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

20652065
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
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

20952143
impl<'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)]
21062153
pub 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)]
21232161
pub 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

src/libserialize/collection_impls.rs

+3
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ use std::collections::hash_state::HashState;
1717

1818
use {Decodable, Encodable, Decoder, Encoder};
1919
use std::collections::{LinkedList, VecDeque, BTreeMap, BTreeSet, HashMap, HashSet, VecMap};
20+
#[allow(deprecated)]
2021
use collections::enum_set::{EnumSet, CLike};
2122

2223
impl<
@@ -130,6 +131,7 @@ impl<
130131
}
131132
}
132133

134+
#[allow(deprecated)]
133135
impl<
134136
T: Encodable + CLike
135137
> Encodable for EnumSet<T> {
@@ -142,6 +144,7 @@ impl<
142144
}
143145
}
144146

147+
#[allow(deprecated)]
145148
impl<
146149
T: Decodable + CLike
147150
> Decodable for EnumSet<T> {

0 commit comments

Comments
 (0)