Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
aa19274b
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,发现更多精彩内容 >>
提交
aa19274b
编写于
11月 29, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
De-genericize `try_define`.
上级
59de7f8f
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
30 addition
and
28 deletion
+30
-28
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+12
-11
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+3
-3
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+15
-14
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
aa19274b
...
...
@@ -16,7 +16,8 @@
use
macros
::{
InvocationData
,
LegacyScope
};
use
resolve_imports
::
ImportDirective
;
use
resolve_imports
::
ImportDirectiveSubclass
::{
self
,
GlobImport
,
SingleImport
};
use
{
Resolver
,
Module
,
ModuleS
,
ModuleKind
,
NameBinding
,
NameBindingKind
,
ToNameBinding
};
use
{
Module
,
ModuleS
,
ModuleKind
,
NameBinding
,
NameBindingKind
,
ToNameBinding
};
use
{
Resolver
,
ResolverArenas
};
use
Namespace
::{
self
,
TypeNS
,
ValueNS
,
MacroNS
};
use
{
resolve_error
,
resolve_struct_error
,
ResolutionError
};
...
...
@@ -45,24 +46,24 @@
use
syntax_pos
::{
Span
,
DUMMY_SP
};
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Module
<
'a
>
,
ty
::
Visibility
,
Span
,
Mark
)
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
NameBinding
{
fn
to_name_binding
(
self
,
arenas
:
&
'a
ResolverArenas
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
arenas
.alloc_name_binding
(
NameBinding
{
kind
:
NameBindingKind
::
Module
(
self
.0
),
vis
:
self
.1
,
span
:
self
.2
,
expansion
:
self
.3
,
}
}
)
}
}
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Def
,
ty
::
Visibility
,
Span
,
Mark
)
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
NameBinding
{
fn
to_name_binding
(
self
,
arenas
:
&
'a
ResolverArenas
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
arenas
.alloc_name_binding
(
NameBinding
{
kind
:
NameBindingKind
::
Def
(
self
.0
),
vis
:
self
.1
,
span
:
self
.2
,
expansion
:
self
.3
,
}
}
)
}
}
...
...
@@ -79,8 +80,8 @@ impl<'b> Resolver<'b> {
fn
define
<
T
>
(
&
mut
self
,
parent
:
Module
<
'b
>
,
ident
:
Ident
,
ns
:
Namespace
,
def
:
T
)
where
T
:
ToNameBinding
<
'b
>
,
{
let
binding
=
def
.to_name_binding
();
if
let
Err
(
old_binding
)
=
self
.try_define
(
parent
,
ident
,
ns
,
binding
.clone
()
)
{
let
binding
=
def
.to_name_binding
(
self
.arenas
);
if
let
Err
(
old_binding
)
=
self
.try_define
(
parent
,
ident
,
ns
,
binding
)
{
self
.report_conflict
(
parent
,
ident
,
ns
,
old_binding
,
&
binding
);
}
}
...
...
@@ -238,8 +239,8 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
// n.b. we don't need to look at the path option here, because cstore already did
let
crate_id
=
self
.session.cstore
.extern_mod_stmt_cnum
(
item
.id
)
.unwrap
();
let
module
=
self
.get_extern_crate_root
(
crate_id
);
let
binding
=
(
module
,
ty
::
Visibility
::
Public
,
sp
,
expansion
)
.to_name_binding
();
let
binding
=
self
.arenas
.alloc_name_binding
(
binding
);
let
binding
=
(
module
,
ty
::
Visibility
::
Public
,
sp
,
expansion
)
.to_name_binding
(
self
.arenas
);
let
directive
=
self
.arenas
.alloc_import_directive
(
ImportDirective
{
id
:
item
.id
,
parent
:
parent
,
...
...
src/librustc_resolve/lib.rs
浏览文件 @
aa19274b
...
...
@@ -875,11 +875,11 @@ pub struct NameBinding<'a> {
}
pub
trait
ToNameBinding
<
'a
>
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
;
fn
to_name_binding
(
self
,
arenas
:
&
'a
ResolverArenas
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
;
}
impl
<
'a
>
ToNameBinding
<
'a
>
for
NameBinding
<
'a
>
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
impl
<
'a
>
ToNameBinding
<
'a
>
for
&
'a
NameBinding
<
'a
>
{
fn
to_name_binding
(
self
,
_
:
&
'a
ResolverArenas
<
'a
>
)
->
&
'a
NameBinding
<
'a
>
{
self
}
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
aa19274b
...
...
@@ -12,7 +12,7 @@
use
{
AmbiguityError
,
Module
,
PerNS
};
use
Namespace
::{
self
,
TypeNS
,
MacroNS
};
use
{
NameBinding
,
NameBindingKind
,
PathResult
,
PathScope
,
PrivacyError
,
ToNameBinding
};
use
{
NameBinding
,
NameBindingKind
,
PathResult
,
PathScope
,
PrivacyError
};
use
Resolver
;
use
{
names_to_string
,
module_to_string
};
use
{
resolve_error
,
ResolutionError
};
...
...
@@ -273,7 +273,7 @@ pub fn add_import_directive(&mut self,
// Given a binding and an import directive that resolves to it,
// return the corresponding binding defined by the import directive.
pub
fn
import
(
&
mut
self
,
binding
:
&
'a
NameBinding
<
'a
>
,
directive
:
&
'a
ImportDirective
<
'a
>
)
->
NameBinding
<
'a
>
{
->
&
'a
NameBinding
<
'a
>
{
let
vis
=
if
binding
.pseudo_vis
()
.is_at_least
(
directive
.vis
.get
(),
self
)
||
!
directive
.is_glob
()
&&
binding
.is_extern_crate
()
{
// c.f. `PRIVATE_IN_PUBLIC`
directive
.vis
.get
()
...
...
@@ -287,7 +287,7 @@ pub fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDire
}
}
NameBinding
{
self
.arenas
.alloc_name_binding
(
NameBinding
{
kind
:
NameBindingKind
::
Import
{
binding
:
binding
,
directive
:
directive
,
...
...
@@ -296,16 +296,17 @@ pub fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDire
span
:
directive
.span
,
vis
:
vis
,
expansion
:
directive
.expansion
,
}
}
)
}
// Define the name or return the existing binding if there is a collision.
pub
fn
try_define
<
T
>
(
&
mut
self
,
module
:
Module
<
'a
>
,
ident
:
Ident
,
ns
:
Namespace
,
binding
:
T
)
->
Result
<
(),
&
'a
NameBinding
<
'a
>>
where
T
:
ToNameBinding
<
'a
>
{
pub
fn
try_define
(
&
mut
self
,
module
:
Module
<
'a
>
,
ident
:
Ident
,
ns
:
Namespace
,
binding
:
&
'a
NameBinding
<
'a
>
)
->
Result
<
(),
&
'a
NameBinding
<
'a
>>
{
let
ident
=
ident
.unhygienize
();
let
binding
=
self
.arenas
.alloc_name_binding
(
binding
.to_name_binding
());
self
.update_resolution
(
module
,
ident
,
ns
,
|
this
,
resolution
|
{
if
let
Some
(
old_binding
)
=
resolution
.binding
{
if
binding
.is_glob_import
()
{
...
...
@@ -389,7 +390,7 @@ fn import_dummy_binding(&mut self, directive: &'a ImportDirective<'a>) {
let
dummy_binding
=
self
.dummy_binding
;
let
dummy_binding
=
self
.import
(
dummy_binding
,
directive
);
self
.per_ns
(|
this
,
ns
|
{
let
_
=
this
.try_define
(
directive
.parent
,
target
,
ns
,
dummy_binding
.clone
()
);
let
_
=
this
.try_define
(
directive
.parent
,
target
,
ns
,
dummy_binding
);
});
}
}
...
...
@@ -516,10 +517,11 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
return
};
let
parent
=
directive
.parent
;
match
result
[
ns
]
.get
()
{
Err
(
Undetermined
)
=>
indeterminate
=
true
,
Err
(
Determined
)
=>
{
this
.update_resolution
(
directive
.
parent
,
target
,
ns
,
|
_
,
resolution
|
{
this
.update_resolution
(
parent
,
target
,
ns
,
|
_
,
resolution
|
{
resolution
.single_imports
.directive_failed
()
});
}
...
...
@@ -534,10 +536,9 @@ fn resolve_import(&mut self, directive: &'b ImportDirective<'b>) -> bool {
}
Ok
(
binding
)
=>
{
let
imported_binding
=
this
.import
(
binding
,
directive
);
let
conflict
=
this
.try_define
(
directive
.
parent
,
target
,
ns
,
imported_binding
);
let
conflict
=
this
.try_define
(
parent
,
target
,
ns
,
imported_binding
);
if
let
Err
(
old_binding
)
=
conflict
{
let
binding
=
&
this
.import
(
binding
,
directive
);
this
.report_conflict
(
directive
.parent
,
target
,
ns
,
binding
,
old_binding
);
this
.report_conflict
(
parent
,
target
,
ns
,
imported_binding
,
old_binding
);
}
}
}
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录