Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2e24c741
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,发现更多精彩内容 >>
提交
2e24c741
编写于
2月 07, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Expand NameBinding to better represent bindings from imports
上级
22e189ed
变更
3
隐藏空白更改
内联
并排
Showing
3 changed file
with
45 addition
and
21 deletion
+45
-21
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+3
-3
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+26
-12
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+16
-6
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
2e24c741
...
...
@@ -19,7 +19,7 @@
use
resolve_imports
::
ImportResolution
;
use
Module
;
use
Namespace
::{
self
,
TypeNS
,
ValueNS
};
use
{
NameBinding
,
DefOrModule
};
use
{
NameBinding
,
NameBindingKind
};
use
{
names_to_string
,
module_to_string
};
use
ParentLink
::{
ModuleParentLink
,
BlockParentLink
};
use
Resolver
;
...
...
@@ -82,8 +82,8 @@ fn to_name_binding(self) -> NameBinding<'a> {
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Def
,
Span
,
DefModifiers
)
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
let
def
=
DefOrModule
::
Def
(
self
.0
);
NameBinding
{
modifiers
:
self
.2
,
def_or_module
:
def
,
span
:
Some
(
self
.1
)
}
let
kind
=
NameBindingKind
::
Def
(
self
.0
);
NameBinding
{
modifiers
:
self
.2
,
kind
:
kind
,
span
:
Some
(
self
.1
)
}
}
}
...
...
src/librustc_resolve/lib.rs
浏览文件 @
2e24c741
...
...
@@ -951,21 +951,26 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
// We need to track them to prohibit reexports like `pub use PrivEnum::Variant`.
const
PRIVATE_VARIANT
=
1
<<
2
,
const
PRELUDE
=
1
<<
3
,
const
GLOB_IMPORTED
=
1
<<
4
,
}
}
// Records a possibly-private value, type, or module definition.
#[derive(
Clone,
Debug)]
#[derive(Debug)]
pub
struct
NameBinding
<
'a
>
{
modifiers
:
DefModifiers
,
// see note in ImportResolution about how to use this
def_or_module
:
DefOrModule
<
'a
>
,
modifiers
:
DefModifiers
,
kind
:
NameBindingKind
<
'a
>
,
span
:
Option
<
Span
>
,
}
#[derive(
Clone,
Debug)]
enum
DefOrModule
<
'a
>
{
#[derive(Debug)]
enum
NameBindingKind
<
'a
>
{
Def
(
Def
),
Module
(
Module
<
'a
>
),
Import
{
binding
:
&
'a
NameBinding
<
'a
>
,
id
:
NodeId
,
},
}
impl
<
'a
>
NameBinding
<
'a
>
{
...
...
@@ -976,20 +981,22 @@ fn create_from_module(module: Module<'a>, span: Option<Span>) -> Self {
DefModifiers
::
empty
()
}
|
DefModifiers
::
IMPORTABLE
;
NameBinding
{
modifiers
:
modifiers
,
def_or_module
:
DefOrModule
::
Module
(
module
),
span
:
span
}
NameBinding
{
modifiers
:
modifiers
,
kind
:
NameBindingKind
::
Module
(
module
),
span
:
span
}
}
fn
module
(
&
self
)
->
Option
<
Module
<
'a
>>
{
match
self
.def_or_module
{
DefOrModule
::
Module
(
ref
module
)
=>
Some
(
module
),
DefOrModule
::
Def
(
_
)
=>
None
,
match
self
.kind
{
NameBindingKind
::
Module
(
module
)
=>
Some
(
module
),
NameBindingKind
::
Def
(
_
)
=>
None
,
NameBindingKind
::
Import
{
binding
,
..
}
=>
binding
.module
(),
}
}
fn
def
(
&
self
)
->
Option
<
Def
>
{
match
self
.def_or_module
{
DefOrModule
::
Def
(
def
)
=>
Some
(
def
),
DefOrModule
::
Module
(
ref
module
)
=>
module
.def
,
match
self
.kind
{
NameBindingKind
::
Def
(
def
)
=>
Some
(
def
),
NameBindingKind
::
Module
(
module
)
=>
module
.def
,
NameBindingKind
::
Import
{
binding
,
..
}
=>
binding
.def
(),
}
}
...
...
@@ -1009,6 +1016,13 @@ fn def_and_lp(&self) -> (Def, LastPrivate) {
fn
is_extern_crate
(
&
self
)
->
bool
{
self
.module
()
.map
(|
module
|
module
.is_extern_crate
)
.unwrap_or
(
false
)
}
fn
is_import
(
&
self
)
->
bool
{
match
self
.kind
{
NameBindingKind
::
Import
{
..
}
=>
true
,
_
=>
false
,
}
}
}
/// Interns the names of the primitive types.
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
2e24c741
...
...
@@ -11,10 +11,9 @@
use
self
::
ImportDirectiveSubclass
::
*
;
use
DefModifiers
;
use
DefOrModule
;
use
Module
;
use
Namespace
::{
self
,
TypeNS
,
ValueNS
};
use
NameBinding
;
use
{
NameBinding
,
NameBindingKind
}
;
use
ResolveResult
;
use
ResolveResult
::
*
;
use
Resolver
;
...
...
@@ -82,11 +81,22 @@ pub fn new(module_path: Vec<Name>,
// Given the binding to which this directive resolves in a particular namespace,
// this returns the binding for the name this directive defines in that namespace.
fn
import
<
'a
>
(
&
self
,
binding
:
&
'a
NameBinding
<
'a
>
)
->
NameBinding
<
'a
>
{
let
mut
binding
=
binding
.clone
();
let
mut
modifiers
=
match
self
.is_public
{
true
=>
DefModifiers
::
PUBLIC
|
DefModifiers
::
IMPORTABLE
,
false
=>
DefModifiers
::
empty
(),
};
if
let
GlobImport
=
self
.subclass
{
modifiers
=
modifiers
|
DefModifiers
::
GLOB_IMPORTED
;
}
if
self
.shadowable
==
Shadowable
::
Always
{
binding
.modifiers
=
binding
.modifiers
|
DefModifiers
::
PRELUDE
;
modifiers
=
modifiers
|
DefModifiers
::
PRELUDE
;
}
NameBinding
{
kind
:
NameBindingKind
::
Import
{
binding
:
binding
,
id
:
self
.id
},
span
:
Some
(
self
.span
),
modifiers
:
modifiers
,
}
binding
}
}
...
...
@@ -216,7 +226,7 @@ fn import_resolving_error(&self, e: ImportResolvingError<'b>) {
let
dummy_binding
=
self
.resolver
.new_name_binding
(
NameBinding
{
modifiers
:
DefModifiers
::
IMPORTABLE
,
def_or_module
:
DefOrModule
::
Def
(
Def
::
Err
),
kind
:
NameBindingKind
::
Def
(
Def
::
Err
),
span
:
None
,
});
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录