Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
097b6d62
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,发现更多精彩内容 >>
提交
097b6d62
编写于
8月 20, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
item_like_imports: Allow glob imports with a given visibility
to reexport some (but not all) names with less visibility.
上级
c56a5afd
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
27 addition
and
5 deletion
+27
-5
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+6
-1
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+21
-4
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
097b6d62
...
...
@@ -26,6 +26,8 @@
use
rustc
::
hir
::
def_id
::{
CRATE_DEF_INDEX
,
DefId
};
use
rustc
::
ty
::{
self
,
VariantKind
};
use
std
::
cell
::
Cell
;
use
syntax
::
ast
::
Name
;
use
syntax
::
attr
;
use
syntax
::
parse
::
token
;
...
...
@@ -176,7 +178,10 @@ fn build_reduced_graph_for_item(&mut self, item: &Item) {
}
}
ViewPathGlob
(
_
)
=>
{
let
subclass
=
GlobImport
{
is_prelude
:
is_prelude
};
let
subclass
=
GlobImport
{
is_prelude
:
is_prelude
,
max_vis
:
Cell
::
new
(
ty
::
Visibility
::
PrivateExternal
),
};
let
span
=
view_path
.span
;
self
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
097b6d62
...
...
@@ -52,7 +52,10 @@ pub enum ImportDirectiveSubclass<'a> {
value_result
:
Cell
<
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>>
,
type_result
:
Cell
<
Result
<&
'a
NameBinding
<
'a
>
,
Determinacy
>>
,
},
GlobImport
{
is_prelude
:
bool
},
GlobImport
{
is_prelude
:
bool
,
max_vis
:
Cell
<
ty
::
Visibility
>
,
// The visibility of the greatest reexport.
},
}
impl
<
'a
>
ImportDirectiveSubclass
<
'a
>
{
...
...
@@ -276,7 +279,7 @@ pub fn add_import_directive(&mut self,
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport
{
is_prelude
:
true
}
=>
{}
GlobImport
{
is_prelude
:
true
,
..
}
=>
{}
GlobImport
{
..
}
=>
self
.current_module.globs
.borrow_mut
()
.push
(
directive
),
}
}
...
...
@@ -292,6 +295,12 @@ fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDirectiv
binding
.pseudo_vis
()
};
if
let
GlobImport
{
ref
max_vis
,
..
}
=
directive
.subclass
{
if
vis
==
directive
.vis
.get
()
||
vis
.is_at_least
(
max_vis
.get
(),
self
)
{
max_vis
.set
(
vis
)
}
}
NameBinding
{
kind
:
NameBindingKind
::
Import
{
binding
:
binding
,
...
...
@@ -562,7 +571,15 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResu
let
msg
=
"Cannot glob-import a module into itself."
.into
();
return
Failed
(
Some
((
directive
.span
,
msg
)));
}
GlobImport
{
..
}
=>
return
Success
(()),
GlobImport
{
is_prelude
,
ref
max_vis
}
=>
{
if
!
is_prelude
&&
max_vis
.get
()
!=
ty
::
Visibility
::
PrivateExternal
&&
// Allow empty globs.
!
max_vis
.get
()
.is_at_least
(
directive
.vis
.get
(),
self
)
{
let
msg
=
"A non-empty glob must import something with the glob's visibility"
;
self
.session
.span_err
(
directive
.span
,
msg
);
}
return
Success
(());
}
};
for
&
(
ns
,
result
)
in
&
[(
ValueNS
,
value_result
),
(
TypeNS
,
type_result
)]
{
...
...
@@ -677,7 +694,7 @@ fn resolve_glob_import(&mut self, directive: &'b ImportDirective<'b>) {
return
;
}
else
if
module
.def_id
()
==
directive
.parent
.def_id
()
{
return
;
}
else
if
let
GlobImport
{
is_prelude
:
true
}
=
directive
.subclass
{
}
else
if
let
GlobImport
{
is_prelude
:
true
,
..
}
=
directive
.subclass
{
self
.prelude
=
Some
(
module
);
return
;
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录