Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
39e6ae2d
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,发现更多精彩内容 >>
提交
39e6ae2d
编写于
12月 14, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Clean up `get_traits_containing_item`.
上级
8d9ba291
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
50 deletion
+42
-50
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+42
-50
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
39e6ae2d
...
...
@@ -2863,72 +2863,64 @@ fn record_candidate_traits_for_expr_if_necessary(&mut self, expr: &Expr) {
fn
get_traits_containing_item
(
&
mut
self
,
name
:
Name
)
->
Vec
<
TraitCandidate
>
{
debug!
(
"(getting traits containing item) looking for '{}'"
,
name
);
fn
add_trait_info
(
found_traits
:
&
mut
Vec
<
TraitCandidate
>
,
trait_def_id
:
DefId
,
import_id
:
Option
<
NodeId
>
,
name
:
Name
)
{
debug!
(
"(adding trait info) found trait {:?} for method '{}'"
,
trait_def_id
,
name
);
found_traits
.push
(
TraitCandidate
{
def_id
:
trait_def_id
,
import_id
:
import_id
,
});
}
let
mut
found_traits
=
Vec
::
new
();
// Look for the current trait.
if
let
Some
((
trait_def_id
,
_
))
=
self
.current_trait_ref
{
if
self
.trait_item_map
.contains_key
(
&
(
name
,
trait_def_id
))
{
add_trait_info
(
&
mut
found_traits
,
trait_def_id
,
None
,
name
);
found_traits
.push
(
TraitCandidate
{
def_id
:
trait_def_id
,
import_id
:
None
}
);
}
}
let
mut
search_module
=
self
.current_module
;
loop
{
// Look for trait children.
let
mut
search_in_module
=
|
this
:
&
mut
Self
,
module
:
Module
<
'a
>
|
{
let
mut
traits
=
module
.traits
.borrow_mut
();
if
traits
.is_none
()
{
let
mut
collected_traits
=
Vec
::
new
();
module
.for_each_child
(|
name
,
ns
,
binding
|
{
if
ns
!=
TypeNS
{
return
}
if
let
Def
::
Trait
(
_
)
=
binding
.def
()
{
collected_traits
.push
((
name
,
binding
));
}
});
*
traits
=
Some
(
collected_traits
.into_boxed_slice
());
}
for
&
(
trait_name
,
binding
)
in
traits
.as_ref
()
.unwrap
()
.iter
()
{
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
{
let
id
=
directive
.id
;
this
.maybe_unused_trait_imports
.insert
(
id
);
this
.add_to_glob_map
(
id
,
trait_name
);
import_id
=
Some
(
id
);
}
add_trait_info
(
&
mut
found_traits
,
trait_def_id
,
import_id
,
name
);
}
}
};
search_in_module
(
self
,
search_module
);
self
.get_traits_in_module_containing_item
(
name
,
search_module
,
&
mut
found_traits
);
match
search_module
.kind
{
ModuleKind
::
Block
(
..
)
=>
search_module
=
search_module
.parent
.unwrap
(),
_
=>
break
,
}
}
if
let
ModuleKind
::
Block
(
..
)
=
search_module
.kind
{
search_module
=
search_module
.parent
.unwrap
();
}
else
{
if
!
search_module
.no_implicit_prelude
{
self
.prelude
.map
(|
prelude
|
search_in_module
(
self
,
prelude
));
}
break
;
if
let
Some
(
prelude
)
=
self
.prelude
{
if
!
search_module
.no_implicit_prelude
{
self
.get_traits_in_module_containing_item
(
name
,
prelude
,
&
mut
found_traits
);
}
}
found_traits
}
fn
get_traits_in_module_containing_item
(
&
mut
self
,
name
:
Name
,
module
:
Module
,
found_traits
:
&
mut
Vec
<
TraitCandidate
>
)
{
let
mut
traits
=
module
.traits
.borrow_mut
();
if
traits
.is_none
()
{
let
mut
collected_traits
=
Vec
::
new
();
module
.for_each_child
(|
name
,
ns
,
binding
|
{
if
ns
!=
TypeNS
{
return
}
if
let
Def
::
Trait
(
_
)
=
binding
.def
()
{
collected_traits
.push
((
name
,
binding
));
}
});
*
traits
=
Some
(
collected_traits
.into_boxed_slice
());
}
for
&
(
trait_name
,
binding
)
in
traits
.as_ref
()
.unwrap
()
.iter
()
{
let
trait_def_id
=
binding
.def
()
.def_id
();
if
self
.trait_item_map
.contains_key
(
&
(
name
,
trait_def_id
))
{
let
import_id
=
match
binding
.kind
{
NameBindingKind
::
Import
{
directive
,
..
}
=>
{
self
.maybe_unused_trait_imports
.insert
(
directive
.id
);
self
.add_to_glob_map
(
directive
.id
,
trait_name
);
Some
(
directive
.id
)
}
_
=>
None
,
};
found_traits
.push
(
TraitCandidate
{
def_id
:
trait_def_id
,
import_id
:
import_id
});
}
}
}
/// When name resolution fails, this method can be used to look up candidate
/// entities with the expected name. It allows filtering them using the
/// supplied predicate (which should be used to only accept the types of
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录