Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
a0c3ce34
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,发现更多精彩内容 >>
提交
a0c3ce34
编写于
4月 10, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
resolve: use the `Restricted` variant of `ty::Visibility` when privacy checking
上级
a4196cd4
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
18 addition
and
30 deletion
+18
-30
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+11
-22
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+7
-8
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
a0c3ce34
...
...
@@ -907,15 +907,6 @@ fn is_trait(&self) -> bool {
_
=>
false
,
}
}
fn
is_ancestor_of
(
&
self
,
module
:
Module
<
'a
>
)
->
bool
{
if
self
.def_id
()
==
module
.def_id
()
{
return
true
}
match
module
.parent_link
{
ParentLink
::
BlockParentLink
(
parent
,
_
)
|
ParentLink
::
ModuleParentLink
(
parent
,
_
)
=>
self
.is_ancestor_of
(
parent
),
_
=>
false
,
}
}
}
impl
<
'a
>
fmt
::
Debug
for
ModuleS
<
'a
>
{
...
...
@@ -1330,7 +1321,7 @@ fn search_parent_externals(needle: Name, module: Module) -> Option<Module> {
// Check to see whether there are type bindings, and, if
// so, whether there is a module within.
if
let
Some
(
module_def
)
=
binding
.module
()
{
self
.check_privacy
(
search_module
,
name
,
binding
,
span
);
self
.check_privacy
(
name
,
binding
,
span
);
search_module
=
module_def
;
}
else
{
let
msg
=
format!
(
"Not a module `{}`"
,
name
);
...
...
@@ -1461,7 +1452,7 @@ fn resolve_ident_in_lexical_scope(&mut self,
}
/// Returns the nearest normal module parent of the given module.
fn
get_nearest_normal_module_parent
(
&
mut
self
,
module_
:
Module
<
'a
>
)
->
Option
<
Module
<
'a
>>
{
fn
get_nearest_normal_module_parent
(
&
self
,
module_
:
Module
<
'a
>
)
->
Option
<
Module
<
'a
>>
{
let
mut
module_
=
module_
;
loop
{
match
module_
.parent_link
{
...
...
@@ -1480,7 +1471,7 @@ fn get_nearest_normal_module_parent(&mut self, module_: Module<'a>) -> Option<Mo
/// Returns the nearest normal module parent of the given module, or the
/// module itself if it is a normal module.
fn
get_nearest_normal_module_parent_or_self
(
&
mut
self
,
module_
:
Module
<
'a
>
)
->
Module
<
'a
>
{
fn
get_nearest_normal_module_parent_or_self
(
&
self
,
module_
:
Module
<
'a
>
)
->
Module
<
'a
>
{
if
module_
.is_normal
()
{
return
module_
;
}
...
...
@@ -2768,7 +2759,7 @@ fn resolve_module_relative_path(&mut self,
let
name
=
segments
.last
()
.unwrap
()
.identifier.name
;
let
result
=
self
.resolve_name_in_module
(
containing_module
,
name
,
namespace
,
false
,
true
);
result
.success
()
.map
(|
binding
|
{
self
.check_privacy
(
containing_module
,
name
,
binding
,
span
);
self
.check_privacy
(
name
,
binding
,
span
);
binding
.def
()
.unwrap
()
})
.ok_or
(
false
)
}
...
...
@@ -2818,7 +2809,7 @@ fn resolve_crate_relative_path(&mut self,
let
name
=
segments
.last
()
.unwrap
()
.identifier.name
;
let
result
=
self
.resolve_name_in_module
(
containing_module
,
name
,
namespace
,
false
,
true
);
result
.success
()
.map
(|
binding
|
{
self
.check_privacy
(
containing_module
,
name
,
binding
,
span
);
self
.check_privacy
(
name
,
binding
,
span
);
binding
.def
()
.unwrap
()
})
.ok_or
(
false
)
}
...
...
@@ -3412,16 +3403,14 @@ fn resolve_visibility(&mut self, vis: &hir::Visibility) -> ty::Visibility {
vis
}
fn
is_visible
(
&
self
,
binding
:
&
'a
NameBinding
<
'a
>
,
parent
:
Module
<
'a
>
)
->
bool
{
binding
.is_public
()
||
parent
.is_ancestor_of
(
self
.current_module
)
fn
is_accessible
(
&
self
,
vis
:
ty
::
Visibility
)
->
bool
{
let
current_module
=
self
.get_nearest_normal_module_parent_or_self
(
self
.current_module
);
let
node_id
=
self
.ast_map
.as_local_node_id
(
current_module
.def_id
()
.unwrap
())
.unwrap
();
vis
.is_accessible_from
(
node_id
,
&
self
.ast_map
)
}
fn
check_privacy
(
&
mut
self
,
module
:
Module
<
'a
>
,
name
:
Name
,
binding
:
&
'a
NameBinding
<
'a
>
,
span
:
Span
)
{
if
!
self
.is_visible
(
binding
,
module
)
{
fn
check_privacy
(
&
mut
self
,
name
:
Name
,
binding
:
&
'a
NameBinding
<
'a
>
,
span
:
Span
)
{
if
!
self
.is_accessible
(
binding
.vis
)
{
self
.privacy_errors
.push
(
PrivacyError
(
span
,
name
,
binding
));
}
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
a0c3ce34
...
...
@@ -521,7 +521,7 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
span_err!
(
self
.resolver.session
,
directive
.span
,
E0253
,
"{}"
,
&
msg
);
}
let
privacy_error
=
if
!
self
.resolver
.is_
visible
(
binding
,
target_module
)
{
let
privacy_error
=
if
!
self
.resolver
.is_
accessible
(
binding
.vis
)
{
Some
(
Box
::
new
(
PrivacyError
(
directive
.span
,
source
,
binding
)))
}
else
{
None
...
...
@@ -567,10 +567,10 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
_
=>
(),
}
let
ast_map
=
self
.resolver.ast_map
;
match
(
&
value_result
,
&
type_result
)
{
(
&
Success
(
name_binding
),
_
)
if
!
name_binding
.is_import
()
&&
directive
.vis
==
ty
::
Visibility
::
Public
&&
!
name_binding
.is_public
()
=>
{
(
&
Success
(
binding
),
_
)
if
!
binding
.vis
.is_at_least
(
directive
.vis
,
ast_map
)
&&
self
.resolver
.is_accessible
(
binding
.vis
)
=>
{
let
msg
=
format!
(
"`{}` is private, and cannot be reexported"
,
source
);
let
note_msg
=
format!
(
"consider marking `{}` as `pub` in the imported module"
,
source
);
...
...
@@ -579,10 +579,9 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
.emit
();
}
(
_
,
&
Success
(
name_binding
))
if
!
name_binding
.is_import
()
&&
directive
.vis
==
ty
::
Visibility
::
Public
&&
!
name_binding
.is_public
()
=>
{
if
name_binding
.is_extern_crate
()
{
(
_
,
&
Success
(
binding
))
if
!
binding
.vis
.is_at_least
(
directive
.vis
,
ast_map
)
&&
self
.resolver
.is_accessible
(
binding
.vis
)
=>
{
if
binding
.is_extern_crate
()
{
let
msg
=
format!
(
"extern crate `{}` is private, and cannot be reexported
\
(error E0364), consider declaring with `pub`"
,
source
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录