Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
5f479155
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,发现更多精彩内容 >>
提交
5f479155
编写于
4月 17, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `is_prelude` to only apply to glob imports
上级
aa588871
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
16 addition
and
30 deletion
+16
-30
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+7
-18
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+9
-12
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
5f479155
...
...
@@ -177,13 +177,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
}
let
subclass
=
ImportDirectiveSubclass
::
single
(
binding
,
source_name
);
let
span
=
view_path
.span
;
parent
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
self
.unresolved_imports
+=
1
;
parent
.add_import_directive
(
module_path
,
subclass
,
view_path
.span
,
item
.id
,
vis
,
is_prelude
);
}
ViewPathList
(
_
,
ref
source_items
)
=>
{
// Make sure there's at most one `mod` import in the list.
...
...
@@ -228,23 +224,16 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, parent_ref: &mut Module<
}
};
let
subclass
=
ImportDirectiveSubclass
::
single
(
rename
,
name
);
let
(
span
,
id
)
=
(
source_item
.span
,
source_item
.node
.id
());
parent
.add_import_directive
(
module_path
,
subclass
,
span
,
id
,
vis
);
self
.unresolved_imports
+=
1
;
parent
.add_import_directive
(
module_path
,
subclass
,
source_item
.span
,
source_item
.node
.id
(),
vis
,
is_prelude
);
}
}
ViewPathGlob
(
_
)
=>
{
let
subclass
=
GlobImport
{
is_prelude
:
is_prelude
};
let
span
=
view_path
.span
;
parent
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
self
.unresolved_imports
+=
1
;
parent
.add_import_directive
(
module_path
,
GlobImport
,
view_path
.span
,
item
.id
,
vis
,
is_prelude
);
}
}
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
5f479155
...
...
@@ -41,7 +41,7 @@ pub enum ImportDirectiveSubclass {
type_determined
:
Cell
<
bool
>
,
value_determined
:
Cell
<
bool
>
,
},
GlobImport
,
GlobImport
{
is_prelude
:
bool
}
,
}
impl
ImportDirectiveSubclass
{
...
...
@@ -64,7 +64,6 @@ pub struct ImportDirective<'a> {
subclass
:
ImportDirectiveSubclass
,
span
:
Span
,
vis
:
ty
::
Visibility
,
// see note in ImportResolutionPerNamespace about how to use this
is_prelude
:
bool
,
}
impl
<
'a
>
ImportDirective
<
'a
>
{
...
...
@@ -84,7 +83,7 @@ fn import(&'a self, binding: &'a NameBinding<'a>, privacy_error: Option<Box<Priv
}
pub
fn
is_glob
(
&
self
)
->
bool
{
match
self
.subclass
{
ImportDirectiveSubclass
::
GlobImport
=>
true
,
_
=>
false
}
match
self
.subclass
{
ImportDirectiveSubclass
::
GlobImport
{
..
}
=>
true
,
_
=>
false
}
}
}
...
...
@@ -191,7 +190,7 @@ fn try_result(&self, ns: Namespace, allow_private_imports: bool)
};
let
name
=
match
directive
.subclass
{
SingleImport
{
source
,
..
}
=>
source
,
GlobImport
=>
unreachable!
(),
GlobImport
{
..
}
=>
unreachable!
(),
};
match
target_module
.resolve_name
(
name
,
ns
,
false
)
{
Failed
(
_
)
=>
{}
...
...
@@ -282,8 +281,7 @@ pub fn add_import_directive(&self,
subclass
:
ImportDirectiveSubclass
,
span
:
Span
,
id
:
NodeId
,
vis
:
ty
::
Visibility
,
is_prelude
:
bool
)
{
vis
:
ty
::
Visibility
)
{
let
directive
=
self
.arenas
.alloc_import_directive
(
ImportDirective
{
module_path
:
module_path
,
target_module
:
Cell
::
new
(
None
),
...
...
@@ -291,7 +289,6 @@ pub fn add_import_directive(&self,
span
:
span
,
id
:
id
,
vis
:
vis
,
is_prelude
:
is_prelude
,
});
self
.unresolved_imports
.borrow_mut
()
.push
(
directive
);
...
...
@@ -304,8 +301,8 @@ pub fn add_import_directive(&self,
}
// We don't add prelude imports to the globs since they only affect lexical scopes,
// which are not relevant to import resolution.
GlobImport
if
directive
.is_prelude
=>
{}
GlobImport
=>
self
.globs
.borrow_mut
()
.push
(
directive
),
GlobImport
{
is_prelude
:
true
}
=>
{}
GlobImport
{
..
}
=>
self
.globs
.borrow_mut
()
.push
(
directive
),
}
}
...
...
@@ -496,7 +493,7 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResul
let
(
source
,
target
,
value_determined
,
type_determined
)
=
match
directive
.subclass
{
SingleImport
{
source
,
target
,
ref
value_determined
,
ref
type_determined
}
=>
(
source
,
target
,
value_determined
,
type_determined
),
GlobImport
=>
return
self
.resolve_glob_import
(
target_module
,
directive
),
GlobImport
{
..
}
=>
return
self
.resolve_glob_import
(
target_module
,
directive
),
};
// We need to resolve both namespaces for this to succeed.
...
...
@@ -644,7 +641,7 @@ fn resolve_glob_import(&mut self, target_module: Module<'b>, directive: &'b Impo
}
self
.resolver
.populate_module_if_necessary
(
target_module
);
if
directive
.is_prelude
{
if
let
GlobImport
{
is_prelude
:
true
}
=
directive
.subclass
{
*
module_
.prelude
.borrow_mut
()
=
Some
(
target_module
);
return
Success
(());
}
...
...
@@ -747,7 +744,7 @@ fn import_path_to_string(names: &[Name], subclass: &ImportDirectiveSubclass) ->
fn
import_directive_subclass_to_string
(
subclass
:
&
ImportDirectiveSubclass
)
->
String
{
match
*
subclass
{
SingleImport
{
source
,
..
}
=>
source
.to_string
(),
GlobImport
=>
"*"
.to_string
(),
GlobImport
{
..
}
=>
"*"
.to_string
(),
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录