Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
87ae68c1
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,发现更多精彩内容 >>
提交
87ae68c1
编写于
8月 20, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor `binding.def()` to return a `Def` instead of an `Option<Def>`.
上级
691d10c3
变更
2
隐藏空白更改
内联
并排
Showing
2 changed file
with
20 addition
and
22 deletion
+20
-22
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+17
-17
src/librustc_resolve/resolve_imports.rs
src/librustc_resolve/resolve_imports.rs
+3
-5
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
87ae68c1
...
...
@@ -459,7 +459,7 @@ fn resolve_struct_error<'b, 'a: 'b, 'c>(resolver: &'b Resolver<'a>,
err
}
ResolutionError
::
BindingShadowsSomethingUnacceptable
(
what_binding
,
name
,
binding
)
=>
{
let
shadows_what
=
PathResolution
::
new
(
binding
.def
()
.unwrap
()
)
.kind_name
();
let
shadows_what
=
PathResolution
::
new
(
binding
.def
())
.kind_name
();
let
mut
err
=
struct_span_err!
(
resolver
.session
,
span
,
E0530
,
...
...
@@ -739,7 +739,7 @@ impl<'a> LexicalScopeBinding<'a> {
fn
local_def
(
self
)
->
LocalDef
{
match
self
{
LexicalScopeBinding
::
LocalDef
(
local_def
)
=>
local_def
,
LexicalScopeBinding
::
Item
(
binding
)
=>
LocalDef
::
from_def
(
binding
.def
()
.unwrap
()
),
LexicalScopeBinding
::
Item
(
binding
)
=>
LocalDef
::
from_def
(
binding
.def
()),
}
}
...
...
@@ -877,10 +877,10 @@ fn module(&self) -> Option<Module<'a>> {
}
}
fn
def
(
&
self
)
->
Option
<
Def
>
{
fn
def
(
&
self
)
->
Def
{
match
self
.kind
{
NameBindingKind
::
Def
(
def
)
=>
Some
(
def
)
,
NameBindingKind
::
Module
(
module
)
=>
module
.def
,
NameBindingKind
::
Def
(
def
)
=>
def
,
NameBindingKind
::
Module
(
module
)
=>
module
.def
.unwrap
()
,
NameBindingKind
::
Import
{
binding
,
..
}
=>
binding
.def
(),
}
}
...
...
@@ -916,7 +916,7 @@ fn is_glob_import(&self) -> bool {
}
fn
is_importable
(
&
self
)
->
bool
{
match
self
.def
()
.unwrap
()
{
match
self
.def
()
{
Def
::
AssociatedConst
(
..
)
|
Def
::
Method
(
..
)
|
Def
::
AssociatedTy
(
..
)
=>
false
,
_
=>
true
,
}
...
...
@@ -1097,7 +1097,7 @@ impl<'a> hir::lowering::Resolver for Resolver<'a> {
fn
resolve_generated_global_path
(
&
mut
self
,
path
:
&
hir
::
Path
,
is_value
:
bool
)
->
Def
{
let
namespace
=
if
is_value
{
ValueNS
}
else
{
TypeNS
};
match
self
.resolve_crate_relative_path
(
path
.span
,
&
path
.segments
,
namespace
)
{
Ok
(
binding
)
=>
binding
.def
()
.unwrap
()
,
Ok
(
binding
)
=>
binding
.def
(),
Err
(
true
)
=>
Def
::
Err
,
Err
(
false
)
=>
{
let
path_name
=
&
format!
(
"{}"
,
path
);
...
...
@@ -1693,7 +1693,7 @@ fn resolve_item(&mut self, item: &Item) {
&
prefix
.segments
,
TypeNS
)
{
Ok
(
binding
)
=>
{
let
def
=
binding
.def
()
.unwrap
()
;
let
def
=
binding
.def
();
self
.record_def
(
item
.id
,
PathResolution
::
new
(
def
));
}
Err
(
true
)
=>
self
.record_def
(
item
.id
,
err_path_resolution
()),
...
...
@@ -2309,7 +2309,7 @@ fn resolve_pattern(&mut self,
// entity, then fall back to a fresh binding.
let
binding
=
self
.resolve_ident_in_lexical_scope
(
ident
.node
,
ValueNS
,
None
)
.and_then
(
LexicalScopeBinding
::
item
);
let
resolution
=
binding
.
and_then
(
NameBinding
::
def
)
.and_then
(|
def
|
{
let
resolution
=
binding
.
map
(
NameBinding
::
def
)
.and_then
(|
def
|
{
let
always_binding
=
!
pat_src
.is_refutable
()
||
opt_pat
.is_some
()
||
bmode
!=
BindingMode
::
ByValue
(
Mutability
::
Immutable
);
match
def
{
...
...
@@ -2443,7 +2443,7 @@ fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace
if
path
.global
{
let
binding
=
self
.resolve_crate_relative_path
(
span
,
segments
,
namespace
);
return
binding
.map
(|
binding
|
mk_res
(
binding
.def
()
.unwrap
()
));
return
binding
.map
(|
binding
|
mk_res
(
binding
.def
()));
}
// Try to find a path to an item in a module.
...
...
@@ -2481,7 +2481,7 @@ fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace
let
unqualified_def
=
resolve_identifier_with_fallback
(
self
,
None
);
let
qualified_binding
=
self
.resolve_module_relative_path
(
span
,
segments
,
namespace
);
match
(
qualified_binding
,
unqualified_def
)
{
(
Ok
(
binding
),
Some
(
ref
ud
))
if
binding
.def
()
.unwrap
()
==
ud
.def
=>
{
(
Ok
(
binding
),
Some
(
ref
ud
))
if
binding
.def
()
==
ud
.def
=>
{
self
.session
.add_lint
(
lint
::
builtin
::
UNUSED_QUALIFICATIONS
,
id
,
...
...
@@ -2491,7 +2491,7 @@ fn resolve_path(&mut self, id: NodeId, path: &Path, path_depth: usize, namespace
_
=>
{}
}
qualified_binding
.map
(|
binding
|
mk_res
(
binding
.def
()
.unwrap
()
))
qualified_binding
.map
(|
binding
|
mk_res
(
binding
.def
()))
}
// Resolve a single identifier
...
...
@@ -3114,7 +3114,7 @@ fn add_trait_info(found_traits: &mut Vec<TraitCandidate>,
let
mut
collected_traits
=
Vec
::
new
();
module
.for_each_child
(|
name
,
ns
,
binding
|
{
if
ns
!=
TypeNS
{
return
}
if
let
Some
(
Def
::
Trait
(
_
)
)
=
binding
.def
()
{
if
let
Def
::
Trait
(
_
)
=
binding
.def
()
{
collected_traits
.push
((
name
,
binding
));
}
});
...
...
@@ -3122,7 +3122,7 @@ fn add_trait_info(found_traits: &mut Vec<TraitCandidate>,
}
for
&
(
trait_name
,
binding
)
in
traits
.as_ref
()
.unwrap
()
.iter
()
{
let
trait_def_id
=
binding
.def
()
.
unwrap
()
.
def_id
();
let
trait_def_id
=
binding
.def
()
.def_id
();
if
this
.trait_item_map
.contains_key
(
&
(
name
,
trait_def_id
))
{
let
mut
import_id
=
None
;
if
let
NameBindingKind
::
Import
{
directive
,
..
}
=
binding
.kind
{
...
...
@@ -3181,8 +3181,8 @@ fn lookup_candidates<FilterFn>(&mut self,
if
name_binding
.is_import
()
{
return
;
}
// collect results based on the filter function
if
let
Some
(
def
)
=
name_binding
.def
()
{
if
name
==
lookup_name
&&
ns
==
namespace
&&
filter_fn
(
def
)
{
if
name
==
lookup_name
&&
ns
==
namespace
{
if
filter_fn
(
name_binding
.def
()
)
{
// create the path
let
ident
=
ast
::
Ident
::
with_empty_ctxt
(
name
);
let
params
=
PathParameters
::
none
();
...
...
@@ -3302,7 +3302,7 @@ fn report_privacy_errors(&self) {
let
msg
=
format!
(
"extern crate `{}` is private"
,
name
);
self
.session
.add_lint
(
lint
::
builtin
::
INACCESSIBLE_EXTERN_CRATE
,
node_id
,
span
,
msg
);
}
else
{
let
def
=
binding
.def
()
.unwrap
()
;
let
def
=
binding
.def
();
self
.session
.span_err
(
span
,
&
format!
(
"{} `{}` is private"
,
def
.kind_name
(),
name
));
}
}
...
...
src/librustc_resolve/resolve_imports.rs
浏览文件 @
87ae68c1
...
...
@@ -639,9 +639,9 @@ fn finalize_import(&mut self, directive: &'b ImportDirective<'b>) -> ResolveResu
// Record what this import resolves to for later uses in documentation,
// this may resolve to either a value or a type, but for documentation
// purposes it's good enough to just favor one over the other.
let
def
=
match
type_result
.ok
()
.
and_then
(
NameBinding
::
def
)
{
let
def
=
match
type_result
.ok
()
.
map
(
NameBinding
::
def
)
{
Some
(
def
)
=>
def
,
None
=>
value_result
.ok
()
.
and_then
(
NameBinding
::
def
)
.unwrap
(),
None
=>
value_result
.ok
()
.
map
(
NameBinding
::
def
)
.unwrap
(),
};
let
path_resolution
=
PathResolution
::
new
(
def
);
self
.def_map
.insert
(
directive
.id
,
path_resolution
);
...
...
@@ -714,9 +714,7 @@ fn finalize_resolutions_in(&mut self, module: Module<'b>) {
if
binding
.vis
==
ty
::
Visibility
::
Public
&&
(
binding
.is_import
()
||
binding
.is_extern_crate
())
{
if
let
Some
(
def
)
=
binding
.def
()
{
reexports
.push
(
Export
{
name
:
name
,
def_id
:
def
.def_id
()
});
}
reexports
.push
(
Export
{
name
:
name
,
def_id
:
binding
.def
()
.def_id
()
});
}
if
let
NameBindingKind
::
Import
{
binding
:
orig_binding
,
directive
,
..
}
=
binding
.kind
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录