Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
int
Rust
提交
bb09ae28
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,发现更多精彩内容 >>
提交
bb09ae28
编写于
3月 12, 2016
作者:
J
Jeffrey Seyfried
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Refactor away `resolve_name_in_lexical_scope` and `resolve_identifier_in_local_ribs`.
上级
73417853
变更
1
隐藏空白更改
内联
并排
Showing
1 changed file
with
42 addition
and
81 deletion
+42
-81
src/librustc_resolve/lib.rs
src/librustc_resolve/lib.rs
+42
-81
未找到文件。
src/librustc_resolve/lib.rs
浏览文件 @
bb09ae28
...
@@ -789,6 +789,26 @@ enum LexicalScopeBinding<'a> {
...
@@ -789,6 +789,26 @@ enum LexicalScopeBinding<'a> {
LocalDef
(
LocalDef
),
LocalDef
(
LocalDef
),
}
}
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
()),
}
}
fn
def
(
self
)
->
Def
{
self
.local_def
()
.def
}
fn
module
(
self
)
->
Option
<
Module
<
'a
>>
{
match
self
{
LexicalScopeBinding
::
Item
(
binding
)
=>
binding
.module
(),
_
=>
None
,
}
}
}
/// The link from a module up to its nearest parent node.
/// The link from a module up to its nearest parent node.
#[derive(Clone,Debug)]
#[derive(Clone,Debug)]
enum
ParentLink
<
'a
>
{
enum
ParentLink
<
'a
>
{
...
@@ -1404,20 +1424,13 @@ fn resolve_module_path(&mut self,
...
@@ -1404,20 +1424,13 @@ fn resolve_module_path(&mut self,
// This is not a crate-relative path. We resolve the
// This is not a crate-relative path. We resolve the
// first component of the path in the current lexical
// first component of the path in the current lexical
// scope and then proceed to resolve below that.
// scope and then proceed to resolve below that.
match
self
.resolve_item_in_lexical_scope
(
module_path
[
0
],
let
ident
=
hir
::
Ident
::
from_name
(
module_path
[
0
]);
TypeNS
,
match
self
.resolve_ident_in_lexical_scope
(
ident
,
TypeNS
,
true
)
true
)
{
.and_then
(
LexicalScopeBinding
::
module
)
{
Failed
(
err
)
=>
return
Failed
(
err
),
None
=>
return
Failed
(
None
),
Indeterminate
=>
{
Some
(
containing_module
)
=>
{
debug!
(
"(resolving module path for import) indeterminate; bailing"
);
search_module
=
containing_module
;
return
Indeterminate
;
start_index
=
1
;
}
Success
(
binding
)
=>
match
binding
.module
()
{
Some
(
containing_module
)
=>
{
search_module
=
containing_module
;
start_index
=
1
;
}
None
=>
return
Failed
(
None
),
}
}
}
}
}
}
...
@@ -1485,18 +1498,6 @@ fn resolve_ident_in_lexical_scope(&mut self,
...
@@ -1485,18 +1498,6 @@ fn resolve_ident_in_lexical_scope(&mut self,
None
None
}
}
fn
resolve_item_in_lexical_scope
(
&
mut
self
,
name
:
Name
,
namespace
:
Namespace
,
record_used
:
bool
)
->
ResolveResult
<&
'a
NameBinding
<
'a
>>
{
let
ident
=
hir
::
Ident
::
from_name
(
name
);
match
self
.resolve_ident_in_lexical_scope
(
ident
,
namespace
,
record_used
)
{
Some
(
LexicalScopeBinding
::
Item
(
binding
))
=>
Success
(
binding
),
_
=>
Failed
(
None
),
}
}
/// Returns the nearest normal module parent of the given module.
/// Returns the nearest normal module parent of the given module.
fn
get_nearest_normal_module_parent
(
&
mut
self
,
module_
:
Module
<
'a
>
)
->
Option
<
Module
<
'a
>>
{
fn
get_nearest_normal_module_parent
(
&
mut
self
,
module_
:
Module
<
'a
>
)
->
Option
<
Module
<
'a
>>
{
let
mut
module_
=
module_
;
let
mut
module_
=
module_
;
...
@@ -2288,8 +2289,7 @@ fn resolve_pattern(&mut self,
...
@@ -2288,8 +2289,7 @@ fn resolve_pattern(&mut self,
let
ident
=
path1
.node
;
let
ident
=
path1
.node
;
let
renamed
=
ident
.name
;
let
renamed
=
ident
.name
;
match
self
.resolve_bare_identifier_pattern
(
ident
.unhygienic_name
,
match
self
.resolve_bare_identifier_pattern
(
ident
,
pattern
.span
)
{
pattern
.span
)
{
FoundStructOrEnumVariant
(
def
)
if
const_ok
=>
{
FoundStructOrEnumVariant
(
def
)
if
const_ok
=>
{
debug!
(
"(resolving pattern) resolving `{}` to struct or enum variant"
,
debug!
(
"(resolving pattern) resolving `{}` to struct or enum variant"
,
renamed
);
renamed
);
...
@@ -2540,49 +2540,21 @@ fn resolve_pattern(&mut self,
...
@@ -2540,49 +2540,21 @@ fn resolve_pattern(&mut self,
});
});
}
}
fn
resolve_bare_identifier_pattern
(
&
mut
self
,
fn
resolve_bare_identifier_pattern
(
&
mut
self
,
ident
:
hir
::
Ident
,
span
:
Span
)
name
:
Name
,
span
:
Span
)
->
BareIdentifierPatternResolution
{
->
BareIdentifierPatternResolution
{
match
self
.resolve_item_in_lexical_scope
(
name
,
ValueNS
,
true
)
{
match
self
.resolve_ident_in_lexical_scope
(
ident
,
ValueNS
,
true
)
Success
(
binding
)
=>
{
.map
(
LexicalScopeBinding
::
def
)
{
debug!
(
"(resolve bare identifier pattern) succeeded in finding {} at {:?}"
,
Some
(
def
@
Def
::
Variant
(
..
))
|
Some
(
def
@
Def
::
Struct
(
..
))
=>
{
name
,
FoundStructOrEnumVariant
(
def
)
binding
);
match
binding
.def
()
{
None
=>
{
panic!
(
"resolved name in the value namespace to a set of name bindings
\
with no def?!"
);
}
// For the two success cases, this lookup can be
// considered as not having a private component because
// the lookup happened only within the current module.
Some
(
def
@
Def
::
Variant
(
..
))
|
Some
(
def
@
Def
::
Struct
(
..
))
=>
{
return
FoundStructOrEnumVariant
(
def
);
}
Some
(
def
@
Def
::
Const
(
..
))
|
Some
(
def
@
Def
::
AssociatedConst
(
..
))
=>
{
return
FoundConst
(
def
,
name
);
}
Some
(
Def
::
Static
(
..
))
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
StaticVariableReference
);
return
BareIdentifierPatternUnresolved
;
}
_
=>
return
BareIdentifierPatternUnresolved
}
}
}
Some
(
def
@
Def
::
Const
(
..
))
|
Some
(
def
@
Def
::
AssociatedConst
(
..
))
=>
{
Indeterminate
=>
return
BareIdentifierPatternUnresolved
,
FoundConst
(
def
,
ident
.unhygienic_name
)
Failed
(
err
)
=>
{
match
err
{
Some
((
span
,
msg
))
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
FailedToResolve
(
&
msg
));
}
None
=>
(),
}
debug!
(
"(resolve bare identifier pattern) failed to find {}"
,
name
);
return
BareIdentifierPatternUnresolved
;
}
}
Some
(
Def
::
Static
(
..
))
=>
{
resolve_error
(
self
,
span
,
ResolutionError
::
StaticVariableReference
);
BareIdentifierPatternUnresolved
}
_
=>
BareIdentifierPatternUnresolved
,
}
}
}
}
...
@@ -2703,7 +2675,8 @@ fn resolve_identifier(&mut self,
...
@@ -2703,7 +2675,8 @@ fn resolve_identifier(&mut self,
return
Some
(
LocalDef
::
from_def
(
Def
::
Err
));
return
Some
(
LocalDef
::
from_def
(
Def
::
Err
));
}
}
self
.resolve_identifier_in_local_ribs
(
identifier
,
namespace
,
record_used
)
self
.resolve_ident_in_lexical_scope
(
identifier
,
namespace
,
record_used
)
.map
(
LexicalScopeBinding
::
local_def
)
}
}
// Resolve a local definition, potentially adjusting for closures.
// Resolve a local definition, potentially adjusting for closures.
...
@@ -2887,18 +2860,6 @@ fn resolve_crate_relative_path(&mut self,
...
@@ -2887,18 +2860,6 @@ fn resolve_crate_relative_path(&mut self,
})
})
}
}
fn
resolve_identifier_in_local_ribs
(
&
mut
self
,
ident
:
hir
::
Ident
,
namespace
:
Namespace
,
record_used
:
bool
)
->
Option
<
LocalDef
>
{
Some
(
match
self
.resolve_ident_in_lexical_scope
(
ident
,
namespace
,
record_used
)
{
Some
(
LexicalScopeBinding
::
LocalDef
(
local_def
))
=>
local_def
,
Some
(
LexicalScopeBinding
::
Item
(
binding
))
=>
LocalDef
::
from_def
(
binding
.def
()
.unwrap
()),
None
=>
return
None
,
})
}
fn
with_no_errors
<
T
,
F
>
(
&
mut
self
,
f
:
F
)
->
T
fn
with_no_errors
<
T
,
F
>
(
&
mut
self
,
f
:
F
)
->
T
where
F
:
FnOnce
(
&
mut
Resolver
)
->
T
where
F
:
FnOnce
(
&
mut
Resolver
)
->
T
{
{
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录