Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
565942b1
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,发现更多精彩内容 >>
提交
565942b1
编写于
5月 16, 2013
作者:
P
Patrick Walton
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
librustc: Fix privacy checking for cross-crate variants
上级
211d038a
变更
7
隐藏空白更改
内联
并排
Showing
7 changed file
with
81 addition
and
34 deletion
+81
-34
src/librustc/metadata/csearch.rs
src/librustc/metadata/csearch.rs
+14
-1
src/librustc/metadata/decoder.rs
src/librustc/metadata/decoder.rs
+22
-9
src/librustc/metadata/encoder.rs
src/librustc/metadata/encoder.rs
+1
-0
src/librustc/middle/resolve.rs
src/librustc/middle/resolve.rs
+29
-23
src/librustc/middle/typeck/coherence.rs
src/librustc/middle/typeck/coherence.rs
+1
-1
src/test/auxiliary/private_variant_xc.rs
src/test/auxiliary/private_variant_xc.rs
+5
-0
src/test/compile-fail/private-variant-xc.rs
src/test/compile-fail/private-variant-xc.rs
+9
-0
未找到文件。
src/librustc/metadata/csearch.rs
浏览文件 @
565942b1
...
...
@@ -52,9 +52,22 @@ pub fn each_lang_item(cstore: @mut cstore::CStore,
}
/// Iterates over all the paths in the given crate.
#[cfg(stage0)]
pub
fn
each_path
(
cstore
:
@
mut
cstore
::
CStore
,
cnum
:
ast
::
crate_num
,
f
:
&
fn
(
&
str
,
decoder
::
def_like
)
->
bool
)
->
bool
{
f
:
&
fn
(
&
str
,
decoder
::
def_like
,
ast
::
visibility
)
->
bool
)
{
let
crate_data
=
cstore
::
get_crate_data
(
cstore
,
cnum
);
let
get_crate_data
:
decoder
::
GetCrateDataCb
=
|
cnum
|
{
cstore
::
get_crate_data
(
cstore
,
cnum
)
};
decoder
::
each_path
(
cstore
.intr
,
crate_data
,
get_crate_data
,
f
)
}
/// Iterates over all the paths in the given crate.
#[cfg(not(stage0))]
pub
fn
each_path
(
cstore
:
@
mut
cstore
::
CStore
,
cnum
:
ast
::
crate_num
,
f
:
&
fn
(
&
str
,
decoder
::
def_like
,
ast
::
visibility
)
->
bool
)
->
bool
{
let
crate_data
=
cstore
::
get_crate_data
(
cstore
,
cnum
);
let
get_crate_data
:
decoder
::
GetCrateDataCb
=
|
cnum
|
{
cstore
::
get_crate_data
(
cstore
,
cnum
)
...
...
src/librustc/metadata/decoder.rs
浏览文件 @
565942b1
...
...
@@ -319,8 +319,7 @@ fn item_name(intr: @ident_interner, item: ebml::Doc) -> ast::ident {
}
fn
item_to_def_like
(
item
:
ebml
::
Doc
,
did
:
ast
::
def_id
,
cnum
:
ast
::
crate_num
)
->
def_like
{
->
def_like
{
let
fam
=
item_family
(
item
);
match
fam
{
Const
=>
dl_def
(
ast
::
def_const
(
did
)),
...
...
@@ -474,9 +473,11 @@ pub fn each_lang_item(cdata: cmd, f: &fn(ast::node_id, uint) -> bool) -> bool {
}
/// Iterates over all the paths in the given crate.
pub
fn
_
each_path
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
pub
fn
_
each_path
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
get_crate_data
:
GetCrateDataCb
,
f
:
&
fn
(
&
str
,
def_like
)
->
bool
)
->
bool
{
f
:
&
fn
(
&
str
,
def_like
,
ast
::
visibility
)
->
bool
)
->
bool
{
let
root
=
reader
::
Doc
(
cdata
.data
);
let
items
=
reader
::
get_doc
(
root
,
tag_items
);
let
items_data
=
reader
::
get_doc
(
items
,
tag_items_data
);
...
...
@@ -497,8 +498,10 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
debug!
(
"(each_path) yielding explicit item: %s"
,
path
);
let
def_like
=
item_to_def_like
(
item_doc
,
def_id
,
cdata
.cnum
);
let
vis
=
item_visibility
(
item_doc
);
// Hand the information off to the iteratee.
if
!
f
(
path
,
def_like
)
{
if
!
f
(
path
,
def_like
,
vis
)
{
broken
=
true
;
// FIXME #4572: This is awful.
}
}
...
...
@@ -548,7 +551,7 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
debug!
(
"(each_path) yielding reexported
\
item: %s"
,
reexport_path
);
if
(
!
f
(
reexport_path
,
def_like
))
{
if
(
!
f
(
reexport_path
,
def_like
,
ast
::
public
))
{
broken
=
true
;
// FIXME #4572: This is awful.
}
}
...
...
@@ -561,9 +564,19 @@ pub fn _each_path(intr: @ident_interner, cdata: cmd,
return
broken
;
}
pub
fn
each_path
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
#[cfg(stage0)]
pub
fn
each_path
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
get_crate_data
:
GetCrateDataCb
,
f
:
&
fn
(
&
str
,
def_like
,
ast
::
visibility
)
->
bool
)
{
_
each_path
(
intr
,
cdata
,
get_crate_data
,
f
);
}
#[cfg(not(stage0))]
pub
fn
each_path
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
get_crate_data
:
GetCrateDataCb
,
f
:
&
fn
(
&
str
,
def_like
)
->
bool
)
->
bool
{
f
:
&
fn
(
&
str
,
def_like
,
ast
::
visibility
)
->
bool
)
->
bool
{
_
each_path
(
intr
,
cdata
,
get_crate_data
,
f
)
}
...
...
@@ -1127,7 +1140,7 @@ pub fn get_crate_vers(data: @~[u8]) -> @~str {
fn
iter_crate_items
(
intr
:
@
ident_interner
,
cdata
:
cmd
,
get_crate_data
:
GetCrateDataCb
,
proc
:
&
fn
(
path
:
&
str
,
ast
::
def_id
))
{
for
each_path
(
intr
,
cdata
,
get_crate_data
)
|
path_string
,
def_like
|
{
for
each_path
(
intr
,
cdata
,
get_crate_data
)
|
path_string
,
def_like
,
_
|
{
match
def_like
{
dl_impl
(
*
)
|
dl_field
=>
{}
dl_def
(
def
)
=>
{
...
...
src/librustc/metadata/encoder.rs
浏览文件 @
565942b1
...
...
@@ -316,6 +316,7 @@ fn encode_enum_variant_info(ecx: @EncodeContext,
encode_family
(
ebml_w
,
'v'
);
encode_name
(
ecx
,
ebml_w
,
variant
.node.name
);
encode_parent_item
(
ebml_w
,
local_def
(
id
));
encode_visibility
(
ebml_w
,
variant
.node.vis
);
encode_type
(
ecx
,
ebml_w
,
node_id_to_type
(
ecx
.tcx
,
variant
.node.id
));
match
variant
.node.kind
{
...
...
src/librustc/middle/resolve.rs
浏览文件 @
565942b1
...
...
@@ -539,7 +539,8 @@ fn set_module_kind(@mut self,
self
.type_def
=
Some
(
TypeNsDef
{
privacy
:
privacy
,
module_def
:
Some
(
module
),
type_def
:
None
type_def
:
None
,
type_span
:
None
,
})
}
Some
(
type_def
)
=>
{
...
...
@@ -549,7 +550,8 @@ fn set_module_kind(@mut self,
self
.type_def
=
Some
(
TypeNsDef
{
privacy
:
privacy
,
module_def
:
Some
(
module
),
type_def
:
type_def
.type_def
type_def
:
type_def
.type_def
,
type_span
:
None
,
})
}
Some
(
module_def
)
=>
module_def
.kind
=
kind
,
...
...
@@ -1392,10 +1394,8 @@ fn build_reduced_graph_for_variant(@mut self,
}
}
/**
* Constructs the reduced graph for one 'view item'. View items consist
* of imports and use directives.
*/
/// Constructs the reduced graph for one 'view item'. View items consist
/// of imports and use directives.
fn
build_reduced_graph_for_view_item
(
@
mut
self
,
view_item
:
@
view_item
,
parent
:
ReducedGraphParent
,
...
...
@@ -1551,11 +1551,13 @@ fn build_reduced_graph_for_block(@mut self,
fn
handle_external_def
(
@
mut
self
,
def
:
def
,
visibility
:
ast
::
visibility
,
modules
:
&
mut
HashMap
<
def_id
,
@
mut
Module
>
,
child_name_bindings
:
@
mut
NameBindings
,
final_ident
:
&
str
,
ident
:
ident
,
new_parent
:
ReducedGraphParent
)
{
let
privacy
=
visibility_to_privacy
(
visibility
);
match
def
{
def_mod
(
def_id
)
|
def_foreign_mod
(
def_id
)
=>
{
match
child_name_bindings
.type_def
{
...
...
@@ -1573,7 +1575,7 @@ fn handle_external_def(@mut self,
// FIXME (#5074): this should be a match on find
if
!
modules
.contains_key
(
&
def_id
)
{
child_name_bindings
.define_module
(
Public
,
child_name_bindings
.define_module
(
privacy
,
parent_link
,
Some
(
def_id
),
NormalModuleKind
,
...
...
@@ -1582,9 +1584,9 @@ fn handle_external_def(@mut self,
child_name_bindings
.get_module
());
}
else
{
let
existing_module
=
*
modules
.get
(
&
def_id
);
// Create an import resolution to
//
avoid creating cycles in the
// module graph.
//
Create an import resolution to avoid creating cycles in
//
the
module graph.
let
resolution
=
@
mut
ImportResolution
(
Public
,
0
);
resolution
.outstanding_references
=
0
;
...
...
@@ -1610,11 +1612,19 @@ fn handle_external_def(@mut self,
}
}
}
def_fn
(
*
)
|
def_static_method
(
*
)
|
def_const
(
*
)
|
def_variant
(
*
)
=>
{
debug!
(
"(building reduced graph for external crate) building
\
variant %s"
,
final_ident
);
// We assume the parent is visible, or else we wouldn't have seen
// it.
let
privacy
=
variant_visibility_to_privacy
(
visibility
,
true
);
child_name_bindings
.define_value
(
privacy
,
def
,
dummy_sp
());
}
def_fn
(
*
)
|
def_static_method
(
*
)
|
def_const
(
*
)
=>
{
debug!
(
"(building reduced graph for external
\
crate) building value %s"
,
final_ident
);
child_name_bindings
.define_value
(
Public
,
def
,
dummy_sp
());
child_name_bindings
.define_value
(
privacy
,
def
,
dummy_sp
());
}
def_trait
(
def_id
)
=>
{
debug!
(
"(building reduced graph for external
\
...
...
@@ -1651,11 +1661,11 @@ trait method '%s'",
}
}
child_name_bindings
.define_type
(
Public
,
def
,
dummy_sp
());
child_name_bindings
.define_type
(
privacy
,
def
,
dummy_sp
());
// Define a module if necessary.
let
parent_link
=
self
.get_parent_link
(
new_parent
,
ident
);
child_name_bindings
.set_module_kind
(
Public
,
child_name_bindings
.set_module_kind
(
privacy
,
parent_link
,
Some
(
def_id
),
TraitModuleKind
,
...
...
@@ -1665,13 +1675,13 @@ trait method '%s'",
debug!
(
"(building reduced graph for external
\
crate) building type %s"
,
final_ident
);
child_name_bindings
.define_type
(
Public
,
def
,
dummy_sp
());
child_name_bindings
.define_type
(
privacy
,
def
,
dummy_sp
());
}
def_struct
(
def_id
)
=>
{
debug!
(
"(building reduced graph for external
\
crate) building type %s"
,
final_ident
);
child_name_bindings
.define_type
(
Public
,
def
,
dummy_sp
());
child_name_bindings
.define_type
(
privacy
,
def
,
dummy_sp
());
self
.structs
.insert
(
def_id
);
}
def_self
(
*
)
|
def_arg
(
*
)
|
def_local
(
*
)
|
...
...
@@ -1692,7 +1702,7 @@ fn build_reduced_graph_for_external_crate(@mut self, root: @mut Module) {
// Create all the items reachable by paths.
for
each_path
(
self
.session.cstore
,
root
.def_id
.get
()
.crate
)
|
path_string
,
def_like
|
{
|
path_string
,
def_like
,
visibility
|
{
debug!
(
"(building reduced graph for external crate) found path
\
entry: %s (%?)"
,
...
...
@@ -1760,6 +1770,7 @@ fn build_reduced_graph_for_external_crate(@mut self, root: @mut Module) {
dummy_sp
());
self
.handle_external_def
(
def
,
visibility
,
&
mut
modules
,
child_name_bindings
,
*
self
.session
.str_of
(
...
...
@@ -2995,14 +3006,9 @@ fn resolve_name_in_module(@mut self,
// If this is a search of all imports, we should be done with glob
// resolution at this point.
<<<<<<<
HEAD
if
name_search_type
==
SearchItemsAndAllImports
{
assert_eq!
(
module_
.glob_count
,
0
);
=======
if
name_search_type
==
PathPublicOrPrivateSearch
||
name_search_type
==
PathPublicOnlySearch
{
assert
!
(
module_
.glob_count
==
0
);
>>>>>>>
librustc
:
Disallow
`
use
`
from
reaching
into
impls
or
traits
.
assert_eq!
(
module_
.glob_count
,
0
);
}
// Check the list of resolved imports.
...
...
src/librustc/middle/typeck/coherence.rs
浏览文件 @
565942b1
...
...
@@ -975,7 +975,7 @@ fn add_external_crates(&self) {
def_id
{
crate
:
crate_number
,
node
:
0
});
for
each_path
(
crate_store
,
crate_number
)
|
_
p
,
def_like
|
{
for
each_path
(
crate_store
,
crate_number
)
|
_
,
def_like
,
_
|
{
match
def_like
{
dl_def
(
def_mod
(
def_id
))
=>
{
self
.add_impls_for_module
(
&
mut
impls_seen
,
...
...
src/test/auxiliary/private_variant_xc.rs
0 → 100644
浏览文件 @
565942b1
pub
enum
Foo
{
pub
Bar
,
priv
Baz
,
}
src/test/compile-fail/private-variant-xc.rs
0 → 100644
浏览文件 @
565942b1
// aux-build:private_variant_xc.rs
extern
mod
private_variant_xc
;
pub
fn
main
()
{
let
_
=
private_variant_xc
::
Bar
;
let
_
=
private_variant_xc
::
Baz
;
//~ ERROR unresolved name
}
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录