Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
1bbf7a43
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,发现更多精彩内容 >>
提交
1bbf7a43
编写于
11月 07, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Add field `expansion: Mark` to `NameBinding`.
上级
83aac43f
变更
4
隐藏空白更改
内联
并排
Showing
4 changed file
with
68 addition
and
43 deletion
+68
-43
src/librustc_resolve/build_reduced_graph.rs
src/librustc_resolve/build_reduced_graph.rs
+58
-42
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+2
-0
src/librustc_resolve/macros.rs
src/librustc_resolve/macros.rs
+1
-0
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+7
-1
未找到文件。
src/librustc_resolve/build_reduced_graph.rs
浏览文件 @
1bbf7a43
...
...
@@ -45,15 +45,25 @@
use
syntax_pos
::{
Span
,
DUMMY_SP
};
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Module
<
'a
>
,
Span
,
ty
::
Visibility
)
{
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Module
<
'a
>
,
ty
::
Visibility
,
Span
,
Mark
)
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
NameBinding
{
kind
:
NameBindingKind
::
Module
(
self
.0
),
span
:
self
.1
,
vis
:
self
.2
}
NameBinding
{
kind
:
NameBindingKind
::
Module
(
self
.0
),
vis
:
self
.1
,
span
:
self
.2
,
expansion
:
self
.3
,
}
}
}
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Def
,
Span
,
ty
::
Visibility
)
{
impl
<
'a
>
ToNameBinding
<
'a
>
for
(
Def
,
ty
::
Visibility
,
Span
,
Mark
)
{
fn
to_name_binding
(
self
)
->
NameBinding
<
'a
>
{
NameBinding
{
kind
:
NameBindingKind
::
Def
(
self
.0
),
span
:
self
.1
,
vis
:
self
.2
}
NameBinding
{
kind
:
NameBindingKind
::
Def
(
self
.0
),
vis
:
self
.1
,
span
:
self
.2
,
expansion
:
self
.3
,
}
}
}
...
...
@@ -148,8 +158,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
}
let
subclass
=
ImportDirectiveSubclass
::
single
(
binding
.name
,
source
.name
);
let
span
=
view_path
.span
;
self
.add_import_directive
(
module_path
,
subclass
,
span
,
item
.id
,
vis
);
self
.add_import_directive
(
module_path
,
subclass
,
view_path
.span
,
item
.id
,
vis
,
expansion
,
);
}
ViewPathList
(
_
,
ref
source_items
)
=>
{
// Make sure there's at most one `mod` import in the list.
...
...
@@ -196,8 +207,10 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
}
};
let
subclass
=
ImportDirectiveSubclass
::
single
(
rename
,
name
);
let
(
span
,
id
)
=
(
source_item
.span
,
source_item
.node.id
);
self
.add_import_directive
(
module_path
,
subclass
,
span
,
id
,
vis
);
let
id
=
source_item
.node.id
;
self
.add_import_directive
(
module_path
,
subclass
,
source_item
.span
,
id
,
vis
,
expansion
,
);
}
}
ViewPathGlob
(
_
)
=>
{
...
...
@@ -205,8 +218,9 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
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
);
self
.add_import_directive
(
module_path
,
subclass
,
view_path
.span
,
item
.id
,
vis
,
expansion
,
);
}
}
}
...
...
@@ -217,7 +231,7 @@ 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
,
sp
,
ty
::
Visibility
::
Public
)
.to_name_binding
();
let
binding
=
(
module
,
ty
::
Visibility
::
Public
,
sp
,
expansion
)
.to_name_binding
();
let
binding
=
self
.arenas
.alloc_name_binding
(
binding
);
let
directive
=
self
.arenas
.alloc_import_directive
(
ImportDirective
{
id
:
item
.id
,
...
...
@@ -227,6 +241,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
span
:
item
.span
,
module_path
:
Vec
::
new
(),
vis
:
Cell
::
new
(
vis
),
expansion
:
expansion
,
});
let
imported_binding
=
self
.import
(
binding
,
directive
);
self
.define
(
parent
,
name
,
TypeNS
,
imported_binding
);
...
...
@@ -245,7 +260,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
normal_ancestor_id
:
Some
(
item
.id
),
..
ModuleS
::
new
(
Some
(
parent
),
ModuleKind
::
Def
(
def
,
name
))
});
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
vis
,
sp
,
expansion
));
self
.module_map
.insert
(
item
.id
,
module
);
// Descend into the module.
...
...
@@ -258,30 +273,30 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
ItemKind
::
Static
(
_
,
m
,
_
)
=>
{
let
mutbl
=
m
==
Mutability
::
Mutable
;
let
def
=
Def
::
Static
(
self
.definitions
.local_def_id
(
item
.id
),
mutbl
);
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
sp
,
expansion
));
}
ItemKind
::
Const
(
..
)
=>
{
let
def
=
Def
::
Const
(
self
.definitions
.local_def_id
(
item
.id
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
sp
,
expansion
));
}
ItemKind
::
Fn
(
..
)
=>
{
let
def
=
Def
::
Fn
(
self
.definitions
.local_def_id
(
item
.id
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
sp
,
expansion
));
}
// These items live in the type namespace.
ItemKind
::
Ty
(
..
)
=>
{
let
def
=
Def
::
TyAlias
(
self
.definitions
.local_def_id
(
item
.id
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
sp
,
expansion
));
}
ItemKind
::
Enum
(
ref
enum_definition
,
_
)
=>
{
let
def
=
Def
::
Enum
(
self
.definitions
.local_def_id
(
item
.id
));
let
module
=
self
.new_module
(
parent
,
ModuleKind
::
Def
(
def
,
name
),
true
);
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
vis
,
sp
,
expansion
));
for
variant
in
&
(
*
enum_definition
)
.variants
{
self
.build_reduced_graph_for_variant
(
variant
,
module
,
vis
);
self
.build_reduced_graph_for_variant
(
variant
,
module
,
vis
,
expansion
);
}
}
...
...
@@ -289,14 +304,14 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
ItemKind
::
Struct
(
ref
struct_def
,
_
)
=>
{
// Define a name in the type namespace.
let
def
=
Def
::
Struct
(
self
.definitions
.local_def_id
(
item
.id
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
sp
,
expansion
));
// If this is a tuple or unit struct, define a name
// in the value namespace as well.
if
!
struct_def
.is_struct
()
{
let
ctor_def
=
Def
::
StructCtor
(
self
.definitions
.local_def_id
(
struct_def
.id
()),
CtorKind
::
from_ast
(
struct_def
));
self
.define
(
parent
,
name
,
ValueNS
,
(
ctor_def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
ctor_def
,
vis
,
sp
,
expansion
));
}
// Record field names for error reporting.
...
...
@@ -310,7 +325,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
ItemKind
::
Union
(
ref
vdata
,
_
)
=>
{
let
def
=
Def
::
Union
(
self
.definitions
.local_def_id
(
item
.id
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
sp
,
expansion
));
// Record field names for error reporting.
let
field_names
=
vdata
.fields
()
.iter
()
.filter_map
(|
field
|
{
...
...
@@ -329,7 +344,7 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
// Add all the items within to a new module.
let
module
=
self
.new_module
(
parent
,
ModuleKind
::
Def
(
Def
::
Trait
(
def_id
),
name
),
true
);
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
sp
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
vis
,
sp
,
expansion
));
self
.current_module
=
module
;
}
ItemKind
::
Mac
(
_
)
=>
panic!
(
"unexpanded macro in resolve!"
),
...
...
@@ -338,27 +353,28 @@ fn build_reduced_graph_for_item(&mut self, item: &Item, expansion: Mark) {
// Constructs the reduced graph for one variant. Variants exist in the
// type and value namespaces.
fn
build_reduced_graph_for_variant
(
&
mut
self
,
variant
:
&
Variant
,
parent
:
Module
<
'b
>
,
vis
:
ty
::
Visibility
)
{
fn
build_reduced_graph_for_variant
(
&
mut
self
,
variant
:
&
Variant
,
parent
:
Module
<
'b
>
,
vis
:
ty
::
Visibility
,
expansion
:
Mark
,
)
{
let
name
=
variant
.node.name.name
;
let
def_id
=
self
.definitions
.local_def_id
(
variant
.node.data
.id
());
// Define a name in the type namespace.
let
def
=
Def
::
Variant
(
def_id
);
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
v
ariant
.span
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
v
is
,
variant
.span
,
expansion
));
// Define a constructor name in the value namespace.
// Braced variants, unlike structs, generate unusable names in
// value namespace, they are reserved for possible future use.
let
ctor_kind
=
CtorKind
::
from_ast
(
&
variant
.node.data
);
let
ctor_def
=
Def
::
VariantCtor
(
def_id
,
ctor_kind
);
self
.define
(
parent
,
name
,
ValueNS
,
(
ctor_def
,
v
ariant
.span
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
ctor_def
,
v
is
,
variant
.span
,
expansion
));
}
/// Constructs the reduced graph for one foreign item.
fn
build_reduced_graph_for_foreign_item
(
&
mut
self
,
foreign_item
:
&
ForeignItem
)
{
fn
build_reduced_graph_for_foreign_item
(
&
mut
self
,
foreign_item
:
&
ForeignItem
,
expansion
:
Mark
,
)
{
let
parent
=
self
.current_module
;
let
name
=
foreign_item
.ident.name
;
...
...
@@ -371,7 +387,7 @@ fn build_reduced_graph_for_foreign_item(&mut self, foreign_item: &ForeignItem) {
}
};
let
vis
=
self
.resolve_visibility
(
&
foreign_item
.vis
);
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
foreign_item
.span
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
foreign_item
.span
,
expansion
));
}
fn
build_reduced_graph_for_block
(
&
mut
self
,
block
:
&
Block
)
{
...
...
@@ -404,24 +420,24 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>,
match
def
{
Def
::
Mod
(
..
)
|
Def
::
Enum
(
..
)
=>
{
let
module
=
self
.new_module
(
parent
,
ModuleKind
::
Def
(
def
,
name
),
false
);
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Variant
(
..
)
=>
{
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
VariantCtor
(
..
)
=>
{
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Fn
(
..
)
|
Def
::
Static
(
..
)
|
Def
::
Const
(
..
)
|
Def
::
AssociatedConst
(
..
)
|
Def
::
Method
(
..
)
=>
{
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Trait
(
..
)
=>
{
let
module
=
self
.new_module
(
parent
,
ModuleKind
::
Def
(
def
,
name
),
false
);
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
module
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
// If this is a trait, add all the trait item names to the trait info.
let
trait_item_def_ids
=
self
.session.cstore
.associated_item_def_ids
(
def_id
);
...
...
@@ -433,27 +449,27 @@ fn build_reduced_graph_for_external_crate_def(&mut self, parent: Module<'b>,
}
}
Def
::
TyAlias
(
..
)
|
Def
::
AssociatedTy
(
..
)
=>
{
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Struct
(
..
)
=>
{
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
// Record field names for error reporting.
let
field_names
=
self
.session.cstore
.struct_field_names
(
def_id
);
self
.insert_field_names
(
def_id
,
field_names
);
}
Def
::
StructCtor
(
..
)
=>
{
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
ValueNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Union
(
..
)
=>
{
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
TypeNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
// Record field names for error reporting.
let
field_names
=
self
.session.cstore
.struct_field_names
(
def_id
);
self
.insert_field_names
(
def_id
,
field_names
);
}
Def
::
Macro
(
..
)
=>
{
self
.define
(
parent
,
name
,
MacroNS
,
(
def
,
DUMMY_SP
,
vis
));
self
.define
(
parent
,
name
,
MacroNS
,
(
def
,
vis
,
DUMMY_SP
,
Mark
::
root
()
));
}
Def
::
Local
(
..
)
|
Def
::
PrimTy
(
..
)
|
...
...
@@ -695,7 +711,7 @@ fn visit_stmt(&mut self, stmt: &ast::Stmt) {
}
fn
visit_foreign_item
(
&
mut
self
,
foreign_item
:
&
ForeignItem
)
{
self
.resolver
.build_reduced_graph_for_foreign_item
(
foreign_item
);
self
.resolver
.build_reduced_graph_for_foreign_item
(
foreign_item
,
self
.expansion
);
visit
::
walk_foreign_item
(
self
,
foreign_item
);
}
...
...
@@ -732,7 +748,7 @@ fn visit_trait_item(&mut self, item: &TraitItem) {
self
.resolver.trait_item_map
.insert
((
item
.ident.name
,
def_id
),
is_static_method
);
let
vis
=
ty
::
Visibility
::
Public
;
self
.resolver
.define
(
parent
,
item
.ident.name
,
ns
,
(
def
,
item
.span
,
vis
));
self
.resolver
.define
(
parent
,
item
.ident.name
,
ns
,
(
def
,
vis
,
item
.span
,
self
.expansion
));
self
.resolver.current_module
=
parent
.parent
.unwrap
();
// nearest normal ancestor
visit
::
walk_trait_item
(
self
,
item
);
...
...
src/librustc_resolve/lib.rs
浏览文件 @
1bbf7a43
...
...
@@ -881,6 +881,7 @@ fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result {
#[derive(Clone,
Debug)]
pub
struct
NameBinding
<
'a
>
{
kind
:
NameBindingKind
<
'a
>
,
expansion
:
Mark
,
span
:
Span
,
vis
:
ty
::
Visibility
,
}
...
...
@@ -1304,6 +1305,7 @@ pub fn new(session: &'a Session,
arenas
:
arenas
,
dummy_binding
:
arenas
.alloc_name_binding
(
NameBinding
{
kind
:
NameBindingKind
::
Def
(
Def
::
Err
),
expansion
:
Mark
::
root
(),
span
:
DUMMY_SP
,
vis
:
ty
::
Visibility
::
Public
,
}),
...
...
src/librustc_resolve/macros.rs
浏览文件 @
1bbf7a43
...
...
@@ -184,6 +184,7 @@ fn add_ext(&mut self, ident: ast::Ident, ext: Rc<SyntaxExtension>) {
kind
:
NameBindingKind
::
Def
(
Def
::
Macro
(
def_id
)),
span
:
DUMMY_SP
,
vis
:
ty
::
Visibility
::
PrivateExternal
,
expansion
:
Mark
::
root
(),
});
self
.builtin_macros
.insert
(
ident
.name
,
binding
);
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
1bbf7a43
...
...
@@ -26,6 +26,7 @@
use
syntax
::
ast
::{
Ident
,
NodeId
,
Name
};
use
syntax
::
ext
::
base
::
Determinacy
::{
self
,
Determined
,
Undetermined
};
use
syntax
::
ext
::
hygiene
::
Mark
;
use
syntax
::
util
::
lev_distance
::
find_best_match_for_name
;
use
syntax_pos
::
Span
;
...
...
@@ -70,6 +71,7 @@ pub struct ImportDirective<'a> {
pub
subclass
:
ImportDirectiveSubclass
<
'a
>
,
pub
span
:
Span
,
pub
vis
:
Cell
<
ty
::
Visibility
>
,
pub
expansion
:
Mark
,
}
impl
<
'a
>
ImportDirective
<
'a
>
{
...
...
@@ -257,7 +259,8 @@ pub fn add_import_directive(&mut self,
subclass
:
ImportDirectiveSubclass
<
'a
>
,
span
:
Span
,
id
:
NodeId
,
vis
:
ty
::
Visibility
)
{
vis
:
ty
::
Visibility
,
expansion
:
Mark
)
{
let
current_module
=
self
.current_module
;
let
directive
=
self
.arenas
.alloc_import_directive
(
ImportDirective
{
parent
:
current_module
,
...
...
@@ -267,6 +270,7 @@ pub fn add_import_directive(&mut self,
span
:
span
,
id
:
id
,
vis
:
Cell
::
new
(
vis
),
expansion
:
expansion
,
});
self
.indeterminate_imports
.push
(
directive
);
...
...
@@ -310,6 +314,7 @@ pub fn import(&mut self, binding: &'a NameBinding<'a>, directive: &'a ImportDire
},
span
:
directive
.span
,
vis
:
vis
,
expansion
:
directive
.expansion
,
}
}
...
...
@@ -336,6 +341,7 @@ pub fn try_define<T>(&mut self, module: Module<'a>, name: Name, ns: Namespace, b
binding
.vis
},
span
:
old_binding
.span
,
expansion
:
Mark
::
root
(),
}));
}
else
if
!
old_binding
.vis
.is_at_least
(
binding
.vis
,
this
)
{
// We are glob-importing the same item but with greater visibility.
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录