Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2c9922aa
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,发现更多精彩内容 >>
提交
2c9922aa
编写于
8月 07, 2013
作者:
M
Michael Woerister
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Enable privacy check for enum methods.
上级
4da1cfe9
变更
5
隐藏空白更改
内联
并排
Showing
5 changed file
with
59 addition
and
26 deletion
+59
-26
src/librustc/middle/privacy.rs
src/librustc/middle/privacy.rs
+1
-0
src/libsyntax/ext/base.rs
src/libsyntax/ext/base.rs
+10
-10
src/libsyntax/opt_vec.rs
src/libsyntax/opt_vec.rs
+12
-12
src/test/auxiliary/xc_private_method_lib.rs
src/test/auxiliary/xc_private_method_lib.rs
+27
-3
src/test/compile-fail/xc-private-method.rs
src/test/compile-fail/xc-private-method.rs
+9
-1
未找到文件。
src/librustc/middle/privacy.rs
浏览文件 @
2c9922aa
...
...
@@ -403,6 +403,7 @@ pub fn check_crate<'mm>(tcx: ty::ctxt,
// Ditto
match
ty
::
get
(
ty
::
type_autoderef
(
tcx
,
ty
::
expr_ty
(
tcx
,
base
)))
.sty
{
ty_enum
(
id
,
_
)
|
ty_struct
(
id
,
_
)
if
id
.crate
!=
LOCAL_CRATE
||
!
privileged_items
.iter
()
.any
(|
x
|
x
==
&
(
id
.node
))
=>
{
...
...
src/libsyntax/ext/base.rs
浏览文件 @
2c9922aa
...
...
@@ -417,12 +417,12 @@ pub enum MapChain<K,V> {
// get the map from an env frame
impl
<
K
:
Eq
+
Hash
+
IterBytes
+
'static
,
V
:
'static
>
MapChain
<
K
,
V
>
{
// Constructor. I don't think we need a zero-arg one.
fn
new
(
init
:
~
HashMap
<
K
,
@
V
>
)
->
@
mut
MapChain
<
K
,
V
>
{
pub
fn
new
(
init
:
~
HashMap
<
K
,
@
V
>
)
->
@
mut
MapChain
<
K
,
V
>
{
@
mut
BaseMapChain
(
init
)
}
// add a new frame to the environment (functionally)
fn
push_frame
(
@
mut
self
)
->
@
mut
MapChain
<
K
,
V
>
{
pub
fn
push_frame
(
@
mut
self
)
->
@
mut
MapChain
<
K
,
V
>
{
@
mut
ConsMapChain
(
~
HashMap
::
new
()
,
self
)
}
...
...
@@ -432,7 +432,7 @@ fn push_frame (@mut self) -> @mut MapChain<K,V> {
// ugh: can't get this to compile with mut because of the
// lack of flow sensitivity.
fn
get_map
<
'a
>
(
&
'a
self
)
->
&
'a
HashMap
<
K
,
@
V
>
{
pub
fn
get_map
<
'a
>
(
&
'a
self
)
->
&
'a
HashMap
<
K
,
@
V
>
{
match
*
self
{
BaseMapChain
(
~
ref
map
)
=>
map
,
ConsMapChain
(
~
ref
map
,
_
)
=>
map
...
...
@@ -442,7 +442,7 @@ fn get_map<'a>(&'a self) -> &'a HashMap<K,@V> {
// traits just don't work anywhere...?
//impl Map<Name,SyntaxExtension> for MapChain {
fn
contains_key
(
&
self
,
key
:
&
K
)
->
bool
{
pub
fn
contains_key
(
&
self
,
key
:
&
K
)
->
bool
{
match
*
self
{
BaseMapChain
(
ref
map
)
=>
map
.contains_key
(
key
),
ConsMapChain
(
ref
map
,
ref
rest
)
=>
...
...
@@ -453,17 +453,17 @@ fn contains_key (&self, key: &K) -> bool {
// should each_key and each_value operate on shadowed
// names? I think not.
// delaying implementing this....
fn
each_key
(
&
self
,
_
f
:
&
fn
(
&
K
)
->
bool
)
{
pub
fn
each_key
(
&
self
,
_
f
:
&
fn
(
&
K
)
->
bool
)
{
fail
!
(
"unimplemented 2013-02-15T10:01"
);
}
fn
each_value
(
&
self
,
_
f
:
&
fn
(
&
V
)
->
bool
)
{
pub
fn
each_value
(
&
self
,
_
f
:
&
fn
(
&
V
)
->
bool
)
{
fail
!
(
"unimplemented 2013-02-15T10:02"
);
}
// Returns a copy of the value that the name maps to.
// Goes down the chain 'til it finds one (or bottom out).
fn
find
(
&
self
,
key
:
&
K
)
->
Option
<@
V
>
{
pub
fn
find
(
&
self
,
key
:
&
K
)
->
Option
<@
V
>
{
match
self
.get_map
()
.find
(
key
)
{
Some
(
ref
v
)
=>
Some
(
**
v
),
None
=>
match
*
self
{
...
...
@@ -473,7 +473,7 @@ fn find (&self, key: &K) -> Option<@V> {
}
}
fn
find_in_topmost_frame
(
&
self
,
key
:
&
K
)
->
Option
<@
V
>
{
pub
fn
find_in_topmost_frame
(
&
self
,
key
:
&
K
)
->
Option
<@
V
>
{
let
map
=
match
*
self
{
BaseMapChain
(
ref
map
)
=>
map
,
ConsMapChain
(
ref
map
,
_
)
=>
map
...
...
@@ -483,7 +483,7 @@ fn find_in_topmost_frame(&self, key: &K) -> Option<@V> {
}
// insert the binding into the top-level map
fn
insert
(
&
mut
self
,
key
:
K
,
ext
:
@
V
)
->
bool
{
pub
fn
insert
(
&
mut
self
,
key
:
K
,
ext
:
@
V
)
->
bool
{
// can't abstract over get_map because of flow sensitivity...
match
*
self
{
BaseMapChain
(
~
ref
mut
map
)
=>
map
.insert
(
key
,
ext
),
...
...
@@ -495,7 +495,7 @@ fn insert (&mut self, key: K, ext: @V) -> bool {
// ... there are definitely some opportunities for abstraction
// here that I'm ignoring. (e.g., manufacturing a predicate on
// the maps in the chain, and using an abstract "find".
fn
insert_into_frame
(
&
mut
self
,
key
:
K
,
ext
:
@
V
,
n
:
K
,
pred
:
&
fn
(
&@
V
)
->
bool
)
{
pub
fn
insert_into_frame
(
&
mut
self
,
key
:
K
,
ext
:
@
V
,
n
:
K
,
pred
:
&
fn
(
&@
V
)
->
bool
)
{
match
*
self
{
BaseMapChain
(
~
ref
mut
map
)
=>
{
if
satisfies_pred
(
map
,
&
n
,
pred
)
{
...
...
src/libsyntax/opt_vec.rs
浏览文件 @
2c9922aa
...
...
@@ -36,7 +36,7 @@ pub fn from<T>(t: ~[T]) -> OptVec<T> {
}
impl
<
T
>
OptVec
<
T
>
{
fn
push
(
&
mut
self
,
t
:
T
)
{
pub
fn
push
(
&
mut
self
,
t
:
T
)
{
match
*
self
{
Vec
(
ref
mut
v
)
=>
{
v
.push
(
t
);
...
...
@@ -50,32 +50,32 @@ fn push(&mut self, t: T) {
*
self
=
Vec
(
~
[
t
]);
}
fn
map
<
U
>
(
&
self
,
op
:
&
fn
(
&
T
)
->
U
)
->
OptVec
<
U
>
{
pub
fn
map
<
U
>
(
&
self
,
op
:
&
fn
(
&
T
)
->
U
)
->
OptVec
<
U
>
{
match
*
self
{
Empty
=>
Empty
,
Vec
(
ref
v
)
=>
Vec
(
v
.map
(
op
))
}
}
fn
map_consume
<
U
>
(
self
,
op
:
&
fn
(
T
)
->
U
)
->
OptVec
<
U
>
{
pub
fn
map_consume
<
U
>
(
self
,
op
:
&
fn
(
T
)
->
U
)
->
OptVec
<
U
>
{
match
self
{
Empty
=>
Empty
,
Vec
(
v
)
=>
Vec
(
v
.consume_iter
()
.transform
(
op
)
.collect
())
}
}
fn
get
<
'a
>
(
&
'a
self
,
i
:
uint
)
->
&
'a
T
{
pub
fn
get
<
'a
>
(
&
'a
self
,
i
:
uint
)
->
&
'a
T
{
match
*
self
{
Empty
=>
fail
!
(
"Invalid index %u"
,
i
),
Vec
(
ref
v
)
=>
&
v
[
i
]
}
}
fn
is_empty
(
&
self
)
->
bool
{
pub
fn
is_empty
(
&
self
)
->
bool
{
self
.len
()
==
0
}
fn
len
(
&
self
)
->
uint
{
pub
fn
len
(
&
self
)
->
uint
{
match
*
self
{
Empty
=>
0
,
Vec
(
ref
v
)
=>
v
.len
()
...
...
@@ -83,7 +83,7 @@ fn len(&self) -> uint {
}
#[inline]
fn
iter
<
'r
>
(
&
'r
self
)
->
OptVecIterator
<
'r
,
T
>
{
pub
fn
iter
<
'r
>
(
&
'r
self
)
->
OptVecIterator
<
'r
,
T
>
{
match
*
self
{
Empty
=>
OptVecIterator
{
iter
:
None
},
Vec
(
ref
v
)
=>
OptVecIterator
{
iter
:
Some
(
v
.iter
())}
...
...
@@ -91,11 +91,11 @@ fn iter<'r>(&'r self) -> OptVecIterator<'r, T> {
}
#[inline]
fn
map_to_vec
<
B
>
(
&
self
,
op
:
&
fn
(
&
T
)
->
B
)
->
~
[
B
]
{
pub
fn
map_to_vec
<
B
>
(
&
self
,
op
:
&
fn
(
&
T
)
->
B
)
->
~
[
B
]
{
self
.iter
()
.transform
(
op
)
.collect
()
}
fn
mapi_to_vec
<
B
>
(
&
self
,
op
:
&
fn
(
uint
,
&
T
)
->
B
)
->
~
[
B
]
{
pub
fn
mapi_to_vec
<
B
>
(
&
self
,
op
:
&
fn
(
uint
,
&
T
)
->
B
)
->
~
[
B
]
{
let
mut
index
=
0
;
self
.map_to_vec
(|
a
|
{
let
i
=
index
;
...
...
@@ -113,7 +113,7 @@ pub fn take_vec<T>(v: OptVec<T>) -> ~[T] {
}
impl
<
T
:
Clone
>
OptVec
<
T
>
{
fn
prepend
(
&
self
,
t
:
T
)
->
OptVec
<
T
>
{
pub
fn
prepend
(
&
self
,
t
:
T
)
->
OptVec
<
T
>
{
let
mut
v0
=
~
[
t
];
match
*
self
{
Empty
=>
{}
...
...
@@ -124,7 +124,7 @@ fn prepend(&self, t: T) -> OptVec<T> {
}
impl
<
A
:
Eq
>
Eq
for
OptVec
<
A
>
{
fn
eq
(
&
self
,
other
:
&
OptVec
<
A
>
)
->
bool
{
pub
fn
eq
(
&
self
,
other
:
&
OptVec
<
A
>
)
->
bool
{
// Note: cannot use #[deriving(Eq)] here because
// (Empty, Vec(~[])) ought to be equal.
match
(
self
,
other
)
{
...
...
@@ -135,7 +135,7 @@ fn eq(&self, other: &OptVec<A>) -> bool {
}
}
fn
ne
(
&
self
,
other
:
&
OptVec
<
A
>
)
->
bool
{
pub
fn
ne
(
&
self
,
other
:
&
OptVec
<
A
>
)
->
bool
{
!
self
.eq
(
other
)
}
}
...
...
src/test/auxiliary/xc_private_method_lib.rs
浏览文件 @
2c9922aa
#[crate_type=
"lib"
]
;
pub
struct
Foo
{
pub
struct
Struct
{
x
:
int
}
impl
Foo
{
fn
new
()
->
Foo
{
Foo
{
x
:
1
}
}
impl
Struct
{
fn
static_meth_struct
()
->
Struct
{
Struct
{
x
:
1
}
}
fn
meth_struct
(
&
self
)
->
int
{
self
.x
}
}
pub
enum
Enum
{
Variant1
(
int
),
Variant2
(
int
)
}
impl
Enum
{
fn
static_meth_enum
()
->
Enum
{
Variant2
(
10
)
}
fn
meth_enum
(
&
self
)
->
int
{
match
*
self
{
Variant1
(
x
)
|
Variant2
(
x
)
=>
x
}
}
}
src/test/compile-fail/xc-private-method.rs
浏览文件 @
2c9922aa
...
...
@@ -4,5 +4,13 @@
extern
mod
xc_private_method_lib
;
fn
main
()
{
let
_
=
xc_private_method_lib
::
Foo
::
new
();
//~ ERROR function `new` is private
// normal method on struct
let
_
=
xc_private_method_lib
::
Struct
{
x
:
10
}
.meth_struct
();
//~ ERROR method `meth_struct` is private
// static method on struct
let
_
=
xc_private_method_lib
::
Struct
::
static_meth_struct
();
//~ ERROR function `static_meth_struct` is private
// normal method on enum
let
_
=
xc_private_method_lib
::
Variant1
(
20
)
.meth_enum
();
//~ ERROR method `meth_enum` is private
// static method on enum
let
_
=
xc_private_method_lib
::
Enum
::
static_meth_enum
();
//~ ERROR function `static_meth_enum` is private
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录