Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
8adcba43
R
Rust
项目概览
int
/
Rust
大约 1 年 前同步成功
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
Rust
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
8adcba43
编写于
8月 06, 2013
作者:
B
bors
浏览文件
操作
浏览文件
下载
差异文件
auto merge of #8054 : sammykim/rust/move-EnumSet, r=alexcrichton
Fix #8004
上级
f8cf234b
a76943be
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
30 addition
and
66 deletion
+30
-66
src/libextra/enum_set.rs
src/libextra/enum_set.rs
+16
-46
src/libextra/extra.rs
src/libextra/extra.rs
+1
-0
src/librustc/metadata/tyencode.rs
src/librustc/metadata/tyencode.rs
+2
-3
src/librustc/middle/kind.rs
src/librustc/middle/kind.rs
+2
-3
src/librustc/middle/ty.rs
src/librustc/middle/ty.rs
+5
-7
src/librustc/rustc.rs
src/librustc/rustc.rs
+0
-1
src/librustc/util/ppaux.rs
src/librustc/util/ppaux.rs
+4
-6
未找到文件。
src/lib
rustc/util
/enum_set.rs
→
src/lib
extra
/enum_set.rs
浏览文件 @
8adcba43
...
...
@@ -11,14 +11,18 @@
use
std
::
iterator
::
Iterator
;
#[deriving(Clone,
Eq,
IterBytes,
ToStr)]
/// A specialized Set implementation to use enum types.
pub
struct
EnumSet
<
E
>
{
// We must maintain the invariant that no bits are set
// for which no variant exists
priv
bits
:
uint
}
/// An iterface for casting C-like enum to uint and back.
pub
trait
CLike
{
/// Converts C-like enum to uint.
pub
fn
to_uint
(
&
self
)
->
uint
;
/// Converts uint to C-like enum.
pub
fn
from_uint
(
uint
)
->
Self
;
}
...
...
@@ -27,54 +31,47 @@ fn bit<E:CLike>(e: E) -> uint {
}
impl
<
E
:
CLike
>
EnumSet
<
E
>
{
/// Returns an empty EnumSet.
pub
fn
empty
()
->
EnumSet
<
E
>
{
EnumSet
{
bits
:
0
}
}
/// Returns true if an EnumSet is empty.
pub
fn
is_empty
(
&
self
)
->
bool
{
self
.bits
==
0
}
/// Returns true if an EnumSet contains any enum of a given EnumSet
pub
fn
intersects
(
&
self
,
e
:
EnumSet
<
E
>
)
->
bool
{
(
self
.bits
&
e
.bits
)
!=
0
}
/// Returns an intersection of both EnumSets.
pub
fn
intersection
(
&
self
,
e
:
EnumSet
<
E
>
)
->
EnumSet
<
E
>
{
EnumSet
{
bits
:
self
.bits
&
e
.bits
}
}
/// Returns true if a given EnumSet is included in an EnumSet.
pub
fn
contains
(
&
self
,
e
:
EnumSet
<
E
>
)
->
bool
{
(
self
.bits
&
e
.bits
)
==
e
.bits
}
/// Returns a union of both EnumSets.
pub
fn
union
(
&
self
,
e
:
EnumSet
<
E
>
)
->
EnumSet
<
E
>
{
EnumSet
{
bits
:
self
.bits
|
e
.bits
}
}
/// Add an enum to an EnumSet
pub
fn
add
(
&
mut
self
,
e
:
E
)
{
self
.bits
|
=
bit
(
e
);
}
/// Returns true if an EnumSet contains a given enum
pub
fn
contains_elem
(
&
self
,
e
:
E
)
->
bool
{
(
self
.bits
&
bit
(
e
))
!=
0
}
pub
fn
each
(
&
self
,
f
:
&
fn
(
E
)
->
bool
)
->
bool
{
let
mut
bits
=
self
.bits
;
let
mut
index
=
0
;
while
bits
!=
0
{
if
(
bits
&
1
)
!=
0
{
let
e
=
CLike
::
from_uint
(
index
);
if
!
f
(
e
)
{
return
false
;
}
}
index
+=
1
;
bits
>>=
1
;
}
return
true
;
}
/// Returns an iterator over an EnumSet
pub
fn
iter
(
&
self
)
->
EnumSetIterator
<
E
>
{
EnumSetIterator
::
new
(
self
.bits
)
}
...
...
@@ -98,6 +95,7 @@ fn bitand(&self, e: &EnumSet<E>) -> EnumSet<E> {
}
}
/// An iterator over an EnumSet
pub
struct
EnumSetIterator
<
E
>
{
priv
index
:
uint
,
priv
bits
:
uint
,
...
...
@@ -136,7 +134,7 @@ mod test {
use
std
::
cast
;
use
util
::
enum_set
::
*
;
use
enum_set
::
*
;
#[deriving(Eq)]
enum
Foo
{
...
...
@@ -236,7 +234,7 @@ fn test_contains_elem() {
}
///////////////////////////////////////////////////////////////////////////
// iter
/ each
// iter
#[test]
fn
test_iterator
()
{
...
...
@@ -262,34 +260,6 @@ fn test_iterator() {
assert_eq!
(
~
[
A
,
B
,
C
],
elems
)
}
#[test]
fn
test_each
()
{
let
mut
e1
:
EnumSet
<
Foo
>
=
EnumSet
::
empty
();
assert_eq!
(
~
[],
collect
(
e1
))
e1
.add
(
A
);
assert_eq!
(
~
[
A
],
collect
(
e1
))
e1
.add
(
C
);
assert_eq!
(
~
[
A
,
C
],
collect
(
e1
))
e1
.add
(
C
);
assert_eq!
(
~
[
A
,
C
],
collect
(
e1
))
e1
.add
(
B
);
assert_eq!
(
~
[
A
,
B
,
C
],
collect
(
e1
))
}
fn
collect
(
e
:
EnumSet
<
Foo
>
)
->
~
[
Foo
]
{
let
mut
elems
=
~
[];
e
.each
(|
elem
|
{
elems
.push
(
elem
);
true
});
elems
}
///////////////////////////////////////////////////////////////////////////
// operators
...
...
src/libextra/extra.rs
浏览文件 @
8adcba43
...
...
@@ -91,6 +91,7 @@
pub
mod
base64
;
pub
mod
rl
;
pub
mod
workcache
;
pub
mod
enum_set
;
#[path=
"num/bigint.rs"
]
pub
mod
bigint
;
#[path=
"num/rational.rs"
]
...
...
src/librustc/metadata/tyencode.rs
浏览文件 @
8adcba43
...
...
@@ -413,15 +413,14 @@ fn enc_fn_sig(w: @io::Writer, cx: @ctxt, fsig: &ty::FnSig) {
}
fn
enc_bounds
(
w
:
@
io
::
Writer
,
cx
:
@
ctxt
,
bs
:
&
ty
::
ParamBounds
)
{
do
bs
.builtin_bounds.each
|
bound
|
{
for
bound
in
bs
.builtin_bounds
.iter
()
{
match
bound
{
ty
::
BoundSend
=>
w
.write_char
(
'S'
),
ty
::
BoundFreeze
=>
w
.write_char
(
'K'
),
ty
::
BoundStatic
=>
w
.write_char
(
'O'
),
ty
::
BoundSized
=>
w
.write_char
(
'Z'
),
}
true
};
}
for
&
tp
in
bs
.trait_bounds
.iter
()
{
w
.write_char
(
'I'
);
...
...
src/librustc/middle/kind.rs
浏览文件 @
8adcba43
...
...
@@ -338,12 +338,11 @@ pub fn check_builtin_bounds(cx: Context, ty: ty::t, bounds: ty::BuiltinBounds,
{
let
kind
=
ty
::
type_contents
(
cx
.tcx
,
ty
);
let
mut
missing
=
ty
::
EmptyBuiltinBounds
();
do
bounds
.each
|
bound
|
{
for
bound
in
bounds
.iter
()
{
if
!
kind
.meets_bound
(
cx
.tcx
,
bound
)
{
missing
.add
(
bound
);
}
true
};
}
if
!
missing
.is_empty
()
{
any_missing
(
missing
);
}
...
...
src/librustc/middle/ty.rs
浏览文件 @
8adcba43
...
...
@@ -25,7 +25,6 @@
use
util
::
ppaux
::{
trait_store_to_str
,
ty_to_str
,
vstore_to_str
};
use
util
::
ppaux
::{
Repr
,
UserString
};
use
util
::
common
::{
indenter
};
use
util
::
enum_set
::{
EnumSet
,
CLike
};
use
std
::
cast
;
use
std
::
cmp
;
...
...
@@ -48,6 +47,7 @@
use
syntax
::
opt_vec
;
use
syntax
::
abi
::
AbiSet
;
use
syntax
;
use
extra
::
enum_set
::{
EnumSet
,
CLike
};
pub
static
INITIAL_DISCRIMINANT_VALUE
:
uint
=
0
;
...
...
@@ -2287,7 +2287,7 @@ fn trait_contents(store: TraitStore, mutbl: ast::mutability,
// This is like with typarams below, but less "pessimistic" and also
// dependent on the trait store.
let
mut
bt
=
TC_NONE
;
do
(
AllBuiltinBounds
()
-
bounds
)
.each
|
bound
|
{
for
bound
in
(
AllBuiltinBounds
()
-
bounds
)
.iter
()
{
bt
=
bt
+
match
bound
{
BoundStatic
if
bounds
.contains_elem
(
BoundSend
)
=>
TC_NONE
,
// Send bound implies static bound.
...
...
@@ -2296,8 +2296,7 @@ fn trait_contents(store: TraitStore, mutbl: ast::mutability,
BoundFreeze
=>
TC_MUTABLE
,
BoundSized
=>
TC_NONE
,
// don't care if interior is sized
};
true
};
}
st
+
mt
+
bt
}
...
...
@@ -2308,7 +2307,7 @@ fn type_param_def_to_contents(cx: ctxt,
let
_
i
=
indenter
();
let
mut
tc
=
TC_ALL
;
do
type_param_def
.bounds.builtin_bounds.each
|
bound
|
{
for
bound
in
type_param_def
.bounds.builtin_bounds
.iter
()
{
debug!
(
"tc = %s, bound = %?"
,
tc
.to_str
(),
bound
);
tc
=
tc
-
match
bound
{
BoundStatic
=>
TypeContents
::
nonstatic
(
cx
),
...
...
@@ -2317,8 +2316,7 @@ fn type_param_def_to_contents(cx: ctxt,
// The dynamic-size bit can be removed at pointer-level, etc.
BoundSized
=>
TypeContents
::
dynamically_sized
(
cx
),
};
true
};
}
debug!
(
"result = %s"
,
tc
.to_str
());
return
tc
;
...
...
src/librustc/rustc.rs
浏览文件 @
8adcba43
...
...
@@ -96,7 +96,6 @@ pub mod back {
pub
mod
util
{
pub
mod
common
;
pub
mod
ppaux
;
pub
mod
enum_set
;
}
pub
mod
lib
{
...
...
src/librustc/util/ppaux.rs
浏览文件 @
8adcba43
...
...
@@ -589,15 +589,14 @@ fn repr(&self, tcx: ctxt) -> ~str {
impl
Repr
for
ty
::
ParamBounds
{
fn
repr
(
&
self
,
tcx
:
ctxt
)
->
~
str
{
let
mut
res
=
~
[];
do
self
.builtin_bounds.each
|
b
|
{
for
b
in
self
.builtin_bounds
.iter
()
{
res
.push
(
match
b
{
ty
::
BoundStatic
=>
~
"'static"
,
ty
::
BoundSend
=>
~
"Send"
,
ty
::
BoundFreeze
=>
~
"Freeze"
,
ty
::
BoundSized
=>
~
"Sized"
,
});
true
};
}
for
t
in
self
.trait_bounds
.iter
()
{
res
.push
(
t
.repr
(
tcx
));
}
...
...
@@ -833,10 +832,9 @@ impl UserString for ty::BuiltinBounds {
fn
user_string
(
&
self
,
tcx
:
ctxt
)
->
~
str
{
if
self
.is_empty
()
{
~
"<no-bounds>"
}
else
{
let
mut
result
=
~
[];
do
self
.each
|
bb
|
{
for
bb
in
self
.iter
()
{
result
.push
(
bb
.user_string
(
tcx
));
true
};
}
result
.connect
(
"+"
)
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录