Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
2ccaeed5
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,发现更多精彩内容 >>
提交
2ccaeed5
编写于
4月 26, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor away `FallbackChecks` and remove dead code
上级
c9d8e149
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
6 addition
and
63 deletion
+6
-63
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+6
-63
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
2ccaeed5
...
...
@@ -42,7 +42,6 @@
use
self
::
AssocItemResolveResult
::
*
;
use
self
::
BareIdentifierPatternResolution
::
*
;
use
self
::
ParentLink
::
*
;
use
self
::
FallbackChecks
::
*
;
use
rustc
::
dep_graph
::
DepNode
;
use
rustc
::
hir
::
map
as
hir_map
;
...
...
@@ -81,7 +80,7 @@
use
rustc
::
hir
::{
PathSegment
,
PathParameters
};
use
rustc
::
hir
::
HirVec
;
use
rustc
::
hir
::{
TraitRef
,
Ty
,
TyBool
,
TyChar
,
TyFloat
,
TyInt
};
use
rustc
::
hir
::{
TyRptr
,
TyStr
,
TyUint
,
TyPath
,
TyPtr
};
use
rustc
::
hir
::{
TyRptr
,
TyStr
,
TyUint
,
TyPath
};
use
std
::
collections
::{
HashMap
,
HashSet
};
use
std
::
cell
::{
Cell
,
RefCell
};
...
...
@@ -676,9 +675,7 @@ fn success(self) -> Option<T> {
enum
FallbackSuggestion
{
NoSuggestion
,
Field
,
Method
,
TraitItem
,
StaticMethod
(
String
),
TraitMethod
(
String
),
}
...
...
@@ -1124,12 +1121,6 @@ fn alloc_name_resolution(&'a self) -> &'a RefCell<NameResolution<'a>> {
}
}
#[derive(PartialEq)]
enum
FallbackChecks
{
Everything
,
OnlyTraitAndStatics
,
}
impl
<
'a
,
'tcx
>
Resolver
<
'a
,
'tcx
>
{
fn
new
(
session
:
&
'a
Session
,
ast_map
:
&
'a
hir_map
::
Map
<
'tcx
>
,
...
...
@@ -2821,13 +2812,10 @@ fn with_no_errors<T, F>(&mut self, f: F) -> T
}
fn
find_fallback_in_self_type
(
&
mut
self
,
name
:
Name
)
->
FallbackSuggestion
{
fn
extract_path_and_node_id
(
t
:
&
Ty
,
allow
:
FallbackChecks
)
->
Option
<
(
Path
,
NodeId
,
FallbackChecks
)
>
{
fn
extract_node_id
(
t
:
&
Ty
)
->
Option
<
NodeId
>
{
match
t
.node
{
TyPath
(
None
,
ref
path
)
=>
Some
((
path
.clone
(),
t
.id
,
allow
)),
TyPtr
(
ref
mut_ty
)
=>
extract_path_and_node_id
(
&
mut_ty
.ty
,
OnlyTraitAndStatics
),
TyRptr
(
_
,
ref
mut_ty
)
=>
extract_path_and_node_id
(
&
mut_ty
.ty
,
allow
),
TyPath
(
None
,
_
)
=>
Some
(
t
.id
),
TyRptr
(
_
,
ref
mut_ty
)
=>
extract_node_id
(
&
mut_ty
.ty
),
// This doesn't handle the remaining `Ty` variants as they are not
// that commonly the self_type, it might be interesting to provide
// support for those in future.
...
...
@@ -2835,23 +2823,6 @@ fn extract_path_and_node_id(t: &Ty,
}
}
fn
get_module
<
'a
,
'tcx
>
(
this
:
&
mut
Resolver
<
'a
,
'tcx
>
,
span
:
Span
,
name_path
:
&
[
ast
::
Name
])
->
Option
<
Module
<
'a
>>
{
let
last_name
=
name_path
.last
()
.unwrap
();
if
name_path
.len
()
==
1
{
match
this
.primitive_type_table.primitive_types
.get
(
last_name
)
{
Some
(
_
)
=>
None
,
None
=>
this
.current_module
.resolve_name_in_lexical_scope
(
*
last_name
,
TypeNS
)
.and_then
(
NameBinding
::
module
)
}
}
else
{
this
.resolve_module_path
(
&
name_path
,
UseLexicalScope
,
span
)
.success
()
}
}
fn
is_static_method
(
this
:
&
Resolver
,
did
:
DefId
)
->
bool
{
if
let
Some
(
node_id
)
=
this
.ast_map
.as_local_node_id
(
did
)
{
let
sig
=
match
this
.ast_map
.get
(
node_id
)
{
...
...
@@ -2871,15 +2842,7 @@ fn is_static_method(this: &Resolver, did: DefId) -> bool {
}
}
let
(
path
,
node_id
,
allowed
)
=
match
self
.current_self_type
{
Some
(
ref
ty
)
=>
match
extract_path_and_node_id
(
ty
,
Everything
)
{
Some
(
x
)
=>
x
,
None
=>
return
NoSuggestion
,
},
None
=>
return
NoSuggestion
,
};
if
allowed
==
Everything
{
if
let
Some
(
node_id
)
=
self
.current_self_type
.as_ref
()
.and_then
(
extract_node_id
)
{
// Look for a field with the same name in the current self_type.
match
self
.def_map
.borrow
()
.get
(
&
node_id
)
.map
(|
d
|
d
.full_def
())
{
Some
(
Def
::
Enum
(
did
))
|
...
...
@@ -2897,24 +2860,6 @@ fn is_static_method(this: &Resolver, did: DefId) -> bool {
}
}
let
name_path
=
path
.segments
.iter
()
.map
(|
seg
|
seg
.identifier.name
)
.collect
::
<
Vec
<
_
>>
();
// Look for a method in the current self type's impl module.
if
let
Some
(
module
)
=
get_module
(
self
,
path
.span
,
&
name_path
)
{
if
let
Some
(
binding
)
=
module
.resolve_name_in_lexical_scope
(
name
,
ValueNS
)
{
if
let
Some
(
Def
::
Method
(
did
))
=
binding
.def
()
{
if
is_static_method
(
self
,
did
)
{
return
StaticMethod
(
path_names_to_string
(
&
path
,
0
));
}
if
self
.current_trait_ref
.is_some
()
{
return
TraitItem
;
}
else
if
allowed
==
Everything
{
return
Method
;
}
}
}
}
// Look for a method in the current trait.
if
let
Some
((
trait_did
,
ref
trait_ref
))
=
self
.current_trait_ref
{
if
let
Some
(
&
did
)
=
self
.trait_item_map
.get
(
&
(
name
,
trait_did
))
{
...
...
@@ -3073,10 +3018,8 @@ fn resolve_expr(&mut self, expr: &Expr) {
}
}
Field
=>
format!
(
"`self.{}`"
,
path_name
),
Method
|
TraitItem
=>
format!
(
"to call `self.{}`"
,
path_name
),
TraitMethod
(
path_str
)
|
StaticMethod
(
path_str
)
=>
TraitMethod
(
path_str
)
=>
format!
(
"to call `{}::{}`"
,
path_str
,
path_name
),
};
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录